Skip to content

Commit 92c9f3a

Browse files
cmd/go: include C/C++/Fortran compiler version in build ID
This will force a rebuild if the C/C++/Fortran compiler changes. No test because a real test requires installing two different compilers. Fixes #40042 Change-Id: I83cc88ade90d665a6fce06435068f39c811e43af Reviewed-on: https://go-review.googlesource.com/c/go/+/314276 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent becb9a2 commit 92c9f3a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/cmd/go/internal/work/buildid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (b *Builder) toolID(name string) string {
204204
// In order to get reproducible builds for released compilers, we
205205
// detect a released compiler by the absence of "experimental" in the
206206
// --version output, and in that case we just use the version string.
207-
func (b *Builder) gccgoToolID(name, language string) (string, error) {
207+
func (b *Builder) gccToolID(name, language string) (string, error) {
208208
key := name + "." + language
209209
b.id.Lock()
210210
id := b.toolIDCache[key]

src/cmd/go/internal/work/exec.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,27 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
249249
if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
250250
fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
251251
cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
252-
fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(), cppflags, cflags, ldflags)
252+
253+
ccExe := b.ccExe()
254+
fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags)
255+
if ccID, err := b.gccToolID(ccExe[0], "c"); err == nil {
256+
fmt.Fprintf(h, "CC ID=%q\n", ccID)
257+
}
253258
if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
254-
fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(), cxxflags)
259+
cxxExe := b.cxxExe()
260+
fmt.Fprintf(h, "CXX=%q %q\n", cxxExe, cxxflags)
261+
if cxxID, err := b.gccToolID(cxxExe[0], "c++"); err == nil {
262+
fmt.Fprintf(h, "CXX ID=%q\n", cxxID)
263+
}
255264
}
256265
if len(p.FFiles) > 0 {
257-
fmt.Fprintf(h, "FC=%q %q\n", b.fcExe(), fflags)
266+
fcExe := b.fcExe()
267+
fmt.Fprintf(h, "FC=%q %q\n", fcExe, fflags)
268+
if fcID, err := b.gccToolID(fcExe[0], "f95"); err == nil {
269+
fmt.Fprintf(h, "FC ID=%q\n", fcID)
270+
}
258271
}
259-
// TODO(rsc): Should we include the SWIG version or Fortran/GCC/G++/Objective-C compiler versions?
272+
// TODO(rsc): Should we include the SWIG version?
260273
}
261274
if p.Internal.CoverMode != "" {
262275
fmt.Fprintf(h, "cover %q %q\n", p.Internal.CoverMode, b.toolID("cover"))
@@ -316,15 +329,15 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
316329
}
317330

318331
case "gccgo":
319-
id, err := b.gccgoToolID(BuildToolchain.compiler(), "go")
332+
id, err := b.gccToolID(BuildToolchain.compiler(), "go")
320333
if err != nil {
321334
base.Fatalf("%v", err)
322335
}
323336
fmt.Fprintf(h, "compile %s %q %q\n", id, forcedGccgoflags, p.Internal.Gccgoflags)
324337
fmt.Fprintf(h, "pkgpath %s\n", gccgoPkgpath(p))
325338
fmt.Fprintf(h, "ar %q\n", BuildToolchain.(gccgoToolchain).ar())
326339
if len(p.SFiles) > 0 {
327-
id, _ = b.gccgoToolID(BuildToolchain.compiler(), "assembler-with-cpp")
340+
id, _ = b.gccToolID(BuildToolchain.compiler(), "assembler-with-cpp")
328341
// Ignore error; different assembler versions
329342
// are unlikely to make any difference anyhow.
330343
fmt.Fprintf(h, "asm %q\n", id)
@@ -1274,7 +1287,7 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
12741287
// Or external linker settings and flags?
12751288

12761289
case "gccgo":
1277-
id, err := b.gccgoToolID(BuildToolchain.linker(), "go")
1290+
id, err := b.gccToolID(BuildToolchain.linker(), "go")
12781291
if err != nil {
12791292
base.Fatalf("%v", err)
12801293
}

0 commit comments

Comments
 (0)