Skip to content

Commit f0ccf72

Browse files
committed
Use better key name for gopherjs binary hash
1 parent a822093 commit f0ccf72

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

build/build.go

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,32 @@ const (
596596
hashDebug = false
597597
)
598598

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+
599625
func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
600626
if archive, ok := s.Archives[pkg.ImportPath]; ok {
601627
return archive, nil
@@ -605,7 +631,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
605631
// determine staleness. Set hashDebug to see this in action. The format is:
606632
//
607633
// ## sync
608-
// gopherjs bin: 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
634+
// gopherjs binary hash: 0x519d22c6ab65a950f5b6278e4d65cb75dbd3a7eb1cf16e976a40b9f1febc0446
609635
// build tags:
610636
// import: internal/race
611637
// hash: 0xb966d7680c1c8ca75026f993c153aff0102dc9551f314e5352043187b5f9c9a6
@@ -627,28 +653,13 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
627653
if pkg.PkgObj != "" {
628654
fmt.Fprintf(hw, "## %v\n", pkg.ImportPath)
629655

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 {
649658
return nil, err
650659
}
651660

661+
fmt.Fprintf(hw, "gopherjs binary hash: %v\n", binHash)
662+
652663
orderedBuildTags := append([]string{}, s.options.BuildTags...)
653664
sort.Strings(orderedBuildTags)
654665

0 commit comments

Comments
 (0)