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