@@ -30,6 +30,25 @@ import (
30
30
"golang.org/x/tools/go/buildutil"
31
31
)
32
32
33
+ const (
34
+ hashDebug = true
35
+ )
36
+
37
+ var (
38
+ compilerBinaryHash string
39
+ )
40
+
41
+ func init () {
42
+ // We do this here because it will only fail in truly bad situations, i.e.
43
+ // machine running out of resources. We also panic if there is a problem
44
+ // because it's unlikely anything else will be useful/work
45
+ h , err := hashCompilerBinary ()
46
+ if err != nil {
47
+ panic (err )
48
+ }
49
+ compilerBinaryHash = h
50
+ }
51
+
33
52
type ImportCError struct {
34
53
pkgPath string
35
54
}
@@ -592,17 +611,9 @@ func (s *Session) buildImportPathWithSrcDir(path string, srcDir string) (*Packag
592
611
return pkg , archive , nil
593
612
}
594
613
595
- const (
596
- hashDebug = false
597
- )
598
-
599
- var (
600
- gopherJsBinaryHash string
601
- )
602
-
603
- func hashGopherJsBinary () (string , error ) {
604
- if gopherJsBinaryHash != "" {
605
- return gopherJsBinaryHash , nil
614
+ func hashCompilerBinary () (string , error ) {
615
+ if compilerBinaryHash != "" {
616
+ return compilerBinaryHash , nil
606
617
}
607
618
608
619
binHash := sha256 .New ()
@@ -618,8 +629,8 @@ func hashGopherJsBinary() (string, error) {
618
629
if _ , err := io .Copy (binHash , binFile ); err != nil {
619
630
return "" , fmt .Errorf ("failed to hash %v: %v" , binPath , err )
620
631
}
621
- gopherJsBinaryHash = fmt .Sprintf ("%#x" , binHash .Sum (nil ))
622
- return gopherJsBinaryHash , nil
632
+ compilerBinaryHash = fmt .Sprintf ("%#x" , binHash .Sum (nil ))
633
+ return compilerBinaryHash , nil
623
634
}
624
635
625
636
func (s * Session ) BuildPackage (pkg * PackageData ) (* compiler.Archive , error ) {
@@ -630,14 +641,14 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
630
641
// For non-main and test packages we build up a hash that will help
631
642
// determine staleness. Set hashDebug to see this in action. The format is:
632
643
//
633
- // ## sync
634
- // gopherjs binary hash: 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
635
- // build tags:
636
- // import: internal/race
644
+ // ## <package>
645
+ // compiler binary hash: 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
646
+ // build tags: <list of build tags>
647
+ // import: <import path>
637
648
// hash: 0xb966d7680c1c8ca75026f993c153aff0102dc9551f314e5352043187b5f9c9a6
638
649
// ...
639
650
//
640
- // file: /home/myitcv/gos/src/sync/cond.go
651
+ // file: <file path>
641
652
// <file contents>
642
653
// N bytes
643
654
// ...
@@ -652,13 +663,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
652
663
653
664
if pkg .PkgObj != "" {
654
665
fmt .Fprintf (hw , "## %v\n " , pkg .ImportPath )
655
-
656
- binHash , err := hashGopherJsBinary ()
657
- if err != nil {
658
- return nil , err
659
- }
660
-
661
- fmt .Fprintf (hw , "gopherjs binary hash: %v\n " , binHash )
666
+ fmt .Fprintf (hw , "compiler binary hash: %v\n " , compilerBinaryHash )
662
667
663
668
orderedBuildTags := append ([]string {}, s .options .BuildTags ... )
664
669
sort .Strings (orderedBuildTags )
0 commit comments