Commit 482da518 authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Ian Lance Taylor

cmd/go: fix TestCgoContainsSpace

TestCgoContainsSpace builds a small program which mimics $CC.
Usually, $CC attempts to compile a trivial code to detect its own
supported flags (i.e. "-no-pie", which must be passed on some systems),
however the mimic didn't consider these cases.

This CL solve the issue.

Also, use the same name as $CC, it may solve other potential problems.

Fixes #20324

Change-Id: I7a00ac016a5fd0667540f2a715371f8152edc395
Reviewed-on: https://go-review.googlesource.com/43330Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 978af9c2
......@@ -4055,13 +4055,26 @@ func TestCgoFlagContainsSpace(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.tempFile("src/cc/main.go", fmt.Sprintf(`package main
tg.tempFile(fmt.Sprintf("src/%s/main.go", testCC), fmt.Sprintf(`package main
import (
"os"
"os/exec"
)
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 arg {
......@@ -4080,24 +4093,18 @@ func TestCgoFlagContainsSpace(t *testing.T) {
if !success {
panic("args should contains '-Ic flags' or '-Lld flags'")
}
cmd := exec.Command(%q, os.Args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
panic(err)
}
}
`, testCC))
tg.cd(tg.path("src/cc"))
tg.cd(tg.path(fmt.Sprintf("src/%s", testCC)))
tg.run("build")
tg.setenv("CC", tg.path("src/cc/cc"))
tg.tempFile("src/cgo/cgo.go", `package main
tg.setenv("CC", tg.path(fmt.Sprintf("src/%s/%s", testCC, testCC)))
tg.tempFile("src/cgo/main.go", `package main
// #cgo CFLAGS: -I"c flags"
// #cgo LDFLAGS: -L"ld flags"
import "C"
func main() {}
`)
path := tg.path("src/cgo/cgo.go")
tg.run("run", path)
tg.cd(tg.path("src/cgo"))
tg.run("run", "main.go")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment