Skip to content

Commit 9e26569

Browse files
cmd/go: don't add C compiler ID to hash for standard library
No test because a real test requires installing two different compilers. For #40042 For #47251 Change-Id: Iefddd67830d242a119378b7ce20be481904806e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/335409 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]> Reviewed-by: Jay Conrod <[email protected]>
1 parent d568e6e commit 9e26569

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/cmd/go/go_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,3 +2848,35 @@ func TestExecInDeletedDir(t *testing.T) {
28482848
// `go version` should not fail
28492849
tg.run("version")
28502850
}
2851+
2852+
// A missing C compiler should not force the net package to be stale.
2853+
// Issue 47215.
2854+
func TestMissingCC(t *testing.T) {
2855+
if !canCgo {
2856+
t.Skip("test is only meaningful on systems with cgo")
2857+
}
2858+
cc := os.Getenv("CC")
2859+
if cc == "" {
2860+
cc = "gcc"
2861+
}
2862+
if filepath.IsAbs(cc) {
2863+
t.Skipf(`"CC" (%s) is an absolute path`, cc)
2864+
}
2865+
_, err := exec.LookPath(cc)
2866+
if err != nil {
2867+
t.Skipf(`"CC" (%s) not on PATH`, cc)
2868+
}
2869+
2870+
tg := testgo(t)
2871+
defer tg.cleanup()
2872+
netStale, _ := tg.isStale("net")
2873+
if netStale {
2874+
t.Skip(`skipping test because "net" package is currently stale`)
2875+
}
2876+
2877+
tg.setenv("PATH", "") // No C compiler on PATH.
2878+
netStale, _ = tg.isStale("net")
2879+
if netStale {
2880+
t.Error(`clearing "PATH" causes "net" to be stale`)
2881+
}
2882+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,15 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
252252

253253
ccExe := b.ccExe()
254254
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)
255+
// Include the C compiler tool ID so that if the C
256+
// compiler changes we rebuild the package.
257+
// But don't do that for standard library packages like net,
258+
// so that the prebuilt .a files from a Go binary install
259+
// don't need to be rebuilt with the local compiler.
260+
if !p.Standard {
261+
if ccID, err := b.gccToolID(ccExe[0], "c"); err == nil {
262+
fmt.Fprintf(h, "CC ID=%q\n", ccID)
263+
}
257264
}
258265
if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
259266
cxxExe := b.cxxExe()

0 commit comments

Comments
 (0)