Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Further refactor to use defer for close
  • Loading branch information
myitcv committed May 4, 2018
commit 82f8b60799bfbe60c8170dae3fe3567333c4acc5
31 changes: 19 additions & 12 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,20 +627,27 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
if pkg.PkgObj != "" {
fmt.Fprintf(hw, "## %v\n", pkg.ImportPath)

binHash := sha256.New()
binPath, err := os.Executable()
if err != nil {
return nil, fmt.Errorf("could not locate GopherJS binary: %v", err)
}
binFile, err := os.Open(binPath)
if err != nil {
return nil, fmt.Errorf("could not open %v: %v", binPath, err)
hashBin := func() error {
binHash := sha256.New()
binPath, err := os.Executable()
if err != nil {
return fmt.Errorf("could not locate GopherJS binary: %v", err)
}
binFile, err := os.Open(binPath)
if err != nil {
return fmt.Errorf("could not open %v: %v", binPath, err)
}
defer binFile.Close()
if _, err := io.Copy(binHash, binFile); err != nil {
return fmt.Errorf("failed to hash %v: %v", binPath, err)
}
fmt.Fprintf(hw, "gopherjs bin: %#x\n", binHash.Sum(nil))
return nil
}
defer binFile.Close()
if _, err := io.Copy(binHash, binFile); err != nil {
return nil, fmt.Errorf("failed to hash %v: %v", binPath, err)

if err := hashBin(); err != nil {
return nil, err
}
fmt.Fprintf(hw, "gopherjs bin: %#x\n", binHash.Sum(nil))

orderedBuildTags := append([]string{}, s.options.BuildTags...)
sort.Strings(orderedBuildTags)
Expand Down