Skip to content

Commit 3ab9ff1

Browse files
committed
cmd/go: include Go toolchain information in build ID
This causes packages and binaries built by Go 1.5 to look out of date to Go 1.6 and vice versa, so that when you flip between different Go versions but keep the same GOPATH, the right rebuilding happens at each flip. Go 1.4 binaries will also look out of date to Go 1.5, but Go 1.5 binaries will not look out of date to Go 1.4 (since Go 1.4 doesn't have anything like this). People flipping between Go 1.4 and Go 1.5 will still need to use go install -a every time to flip to Go 1.4, but not when they flip back to Go 1.5. Fixes #6534. Fixes #10702. Change-Id: I0ae7f268f822d483059a938a4f22846ff9275b4c Reviewed-on: https://go-review.googlesource.com/10760 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]>
1 parent 43aac4f commit 3ab9ff1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cmd/go/pkg.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,27 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
724724
for _, file := range inputFiles {
725725
fmt.Fprintf(h, "%s\n", file)
726726
}
727+
728+
// Include the content of runtime/zversion.go in the hash
729+
// for package runtime. This will give package runtime a
730+
// different build ID in each Go release.
731+
if p.Standard && p.ImportPath == "runtime" {
732+
data, _ := ioutil.ReadFile(filepath.Join(p.Dir, "zversion.go"))
733+
fmt.Fprintf(h, "zversion %q\n", string(data))
734+
}
735+
736+
// Include the build IDs of any dependencies in the hash.
737+
// This, combined with the runtime/zversion content,
738+
// will cause packages to have different build IDs when
739+
// compiled with different Go releases.
740+
// This helps the go command know to recompile when
741+
// people use the same GOPATH but switch between
742+
// different Go releases. See golang.org/issue/10702.
743+
for _, dep := range p.Deps {
744+
p1 := deps[dep]
745+
fmt.Fprintf(h, "dep %s %s\n", p1.ImportPath, p1.buildID)
746+
}
747+
727748
p.buildID = fmt.Sprintf("%x", h.Sum(nil))
728749

729750
return p

0 commit comments

Comments
 (0)