From c6f3e98eb568a364eb77445a50e4dfbe95ba5058 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 9 Jun 2017 11:44:31 -0400 Subject: [PATCH] cmd/go: rewrite TestCgoFlagContainsSpace not to use a fake CC Using a fake CC fails today if runtime/cgo is stale, because the build will try to rebuild runtime/cgo using the fake CC, and the fake CC is not a working C compiler. Worse, in the future, when the go command is sensitive to details like the fact that different CCs produce different outputs, putting in the fake CC will make runtime/cgo look stale even if it was formerly up-to-date. Fix both problems by not overriding CC and instead looking at the command being run to make sure the flags are quoted as expected. Change-Id: I4417e35cfab33a07546cc90748ddb6119d8fdb2d Reviewed-on: https://go-review.googlesource.com/56272 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/go/go_test.go | 59 ++++++------------------------------------- 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 56b9b07889..b836da9f57 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -4141,65 +4141,22 @@ func TestCgoFlagContainsSpace(t *testing.T) { if !canCgo { t.Skip("skipping because cgo not enabled") } - tg := testgo(t) defer tg.cleanup() - ccName := filepath.Base(testCC) - - tg.tempFile(fmt.Sprintf("src/%s/main.go", ccName), fmt.Sprintf(`package main - import ( - "os" - "os/exec" - "strings" - ) - - func main() { - cmd := exec.Command(%q, os.Args[1:]...) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() - if err != nil { - panic(err) - } - - if os.Args[len(os.Args)-1] == "trivial.c" { - return - } - - var success bool - for _, arg := range os.Args { - switch { - case strings.Contains(arg, "c flags"): - if success { - panic("duplicate CFLAGS") - } - success = true - case strings.Contains(arg, "ld flags"): - if success { - panic("duplicate LDFLAGS") - } - success = true - } - } - if !success { - panic("args should contains '-Ic flags' or '-Lld flags'") - } - } - `, testCC)) - tg.cd(tg.path(fmt.Sprintf("src/%s", ccName))) - tg.run("build") - tg.setenv("CC", tg.path(fmt.Sprintf("src/%s/%s", ccName, ccName))) - - tg.tempFile("src/cgo/main.go", `package main + tg.makeTempdir() + tg.cd(tg.path(".")) + tg.tempFile("main.go", `package main // #cgo CFLAGS: -I"c flags" // #cgo LDFLAGS: -L"ld flags" import "C" func main() {} `) - tg.cd(tg.path("src/cgo")) - tg.run("run", "main.go") + tg.run("run", "-x", "main.go") + tg.grepStderr(`"-I[^"]+c flags"`, "did not find quoted c flags") + tg.grepStderrNot(`"-I[^"]+c flags".*"-I[^"]+c flags"`, "found too many quoted c flags") + tg.grepStderr(`"-L[^"]+ld flags"`, "did not find quoted ld flags") + tg.grepStderrNot(`"-L[^"]+c flags".*"-L[^"]+c flags"`, "found too many quoted ld flags") } // Issue #20435. -- 2.48.1