@@ -596,6 +596,32 @@ const (
596
596
hashDebug = false
597
597
)
598
598
599
+ var (
600
+ gopherJsBinaryHash string
601
+ )
602
+
603
+ func hashGopherJsBinary () (string , error ) {
604
+ if gopherJsBinaryHash != "" {
605
+ return gopherJsBinaryHash , nil
606
+ }
607
+
608
+ binHash := sha256 .New ()
609
+ binPath , err := os .Executable ()
610
+ if err != nil {
611
+ return "" , fmt .Errorf ("could not locate GopherJS binary: %v" , err )
612
+ }
613
+ binFile , err := os .Open (binPath )
614
+ if err != nil {
615
+ return "" , fmt .Errorf ("could not open %v: %v" , binPath , err )
616
+ }
617
+ defer binFile .Close ()
618
+ if _ , err := io .Copy (binHash , binFile ); err != nil {
619
+ return "" , fmt .Errorf ("failed to hash %v: %v" , binPath , err )
620
+ }
621
+ gopherJsBinaryHash = fmt .Sprintf ("%#x" , binHash .Sum (nil ))
622
+ return gopherJsBinaryHash , nil
623
+ }
624
+
599
625
func (s * Session ) BuildPackage (pkg * PackageData ) (* compiler.Archive , error ) {
600
626
if archive , ok := s .Archives [pkg .ImportPath ]; ok {
601
627
return archive , nil
@@ -605,7 +631,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
605
631
// determine staleness. Set hashDebug to see this in action. The format is:
606
632
//
607
633
// ## sync
608
- // gopherjs bin : 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
634
+ // gopherjs binary hash : 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
609
635
// build tags:
610
636
// import: internal/race
611
637
// hash: 0xb966d7680c1c8ca75026f993c153aff0102dc9551f314e5352043187b5f9c9a6
@@ -627,28 +653,13 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
627
653
if pkg .PkgObj != "" {
628
654
fmt .Fprintf (hw , "## %v\n " , pkg .ImportPath )
629
655
630
- hashBin := func () error {
631
- binHash := sha256 .New ()
632
- binPath , err := os .Executable ()
633
- if err != nil {
634
- return fmt .Errorf ("could not locate GopherJS binary: %v" , err )
635
- }
636
- binFile , err := os .Open (binPath )
637
- if err != nil {
638
- return fmt .Errorf ("could not open %v: %v" , binPath , err )
639
- }
640
- defer binFile .Close ()
641
- if _ , err := io .Copy (binHash , binFile ); err != nil {
642
- return fmt .Errorf ("failed to hash %v: %v" , binPath , err )
643
- }
644
- fmt .Fprintf (hw , "gopherjs bin: %#x\n " , binHash .Sum (nil ))
645
- return nil
646
- }
647
-
648
- if err := hashBin (); err != nil {
656
+ binHash , err := hashGopherJsBinary ()
657
+ if err != nil {
649
658
return nil , err
650
659
}
651
660
661
+ fmt .Fprintf (hw , "gopherjs binary hash: %v\n " , binHash )
662
+
652
663
orderedBuildTags := append ([]string {}, s .options .BuildTags ... )
653
664
sort .Strings (orderedBuildTags )
654
665
0 commit comments