Commit d8cbc2c9 authored by Alex Brainman's avatar Alex Brainman

misc/cgo/testcarchive: do not use same executable name in TestInstall

Fixes #17439

Change-Id: I7caa28519f38692f9ca306f0789cbb975fa1d7c4
Reviewed-on: https://go-review.googlesource.com/31112Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 42f5ee4c
...@@ -35,13 +35,9 @@ var GOOS, GOARCH string ...@@ -35,13 +35,9 @@ var GOOS, GOARCH string
var libgodir string var libgodir string
func init() { func init() {
bin = []string{"./testp"}
GOOS = goEnv("GOOS") GOOS = goEnv("GOOS")
GOARCH = goEnv("GOARCH") GOARCH = goEnv("GOARCH")
execScript := "go_" + GOOS + "_" + GOARCH + "_exec" bin = cmdToRun("./testp")
if executor, err := exec.LookPath(execScript); err == nil {
bin = []string{executor, "./testp"}
}
ccOut := goEnv("CC") ccOut := goEnv("CC")
cc = []string{string(ccOut)} cc = []string{string(ccOut)}
...@@ -126,81 +122,62 @@ func goEnv(key string) string { ...@@ -126,81 +122,62 @@ func goEnv(key string) string {
return strings.TrimSpace(string(out)) return strings.TrimSpace(string(out))
} }
func compilemain(t *testing.T, libgo string) { func cmdToRun(name string) []string {
ccArgs := append(cc, "-o", "testp"+exeSuffix, "main.c") execScript := "go_" + goEnv("GOOS") + "_" + goEnv("GOARCH") + "_exec"
if GOOS == "windows" { executor, err := exec.LookPath(execScript)
ccArgs = append(ccArgs, "main_windows.c", libgo, "-lntdll", "-lws2_32", "-lwinmm") if err != nil {
} else { return []string{name}
ccArgs = append(ccArgs, "main_unix.c", libgo)
}
t.Log(ccArgs)
if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
} }
return []string{executor, name}
} }
func TestInstall(t *testing.T) { func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
defer func() { cmd := exec.Command(buildcmd[0], buildcmd[1:]...)
os.Remove("libgo.a")
os.Remove("libgo.h")
os.Remove("testp")
os.RemoveAll("pkg")
}()
cmd := exec.Command("go", "install", "-buildmode=c-archive", "libgo")
cmd.Env = gopathEnv cmd.Env = gopathEnv
if out, err := cmd.CombinedOutput(); err != nil { if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
defer func() {
os.Remove(libgoa)
os.Remove(libgoh)
}()
compilemain(t, filepath.Join("pkg", libgodir, "libgo.a")) ccArgs := append(cc, "-o", exe, "main.c")
if GOOS == "windows" {
binArgs := append(bin, "arg1", "arg2") ccArgs = append(ccArgs, "main_windows.c", libgoa, "-lntdll", "-lws2_32", "-lwinmm")
if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil { } else {
t.Logf("%s", out) ccArgs = append(ccArgs, "main_unix.c", libgoa)
t.Fatal(err)
} }
t.Log(ccArgs)
os.Remove("libgo.a") if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
os.Remove("libgo.h")
os.Remove("testp")
// Test building libgo other than installing it.
// Header files are now present.
cmd = exec.Command("go", "build", "-buildmode=c-archive", filepath.Join("src", "libgo", "libgo.go"))
cmd.Env = gopathEnv
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
defer os.Remove(exe)
compilemain(t, "libgo.a") binArgs := append(cmdToRun(exe), "arg1", "arg2")
if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil { if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil {
t.Logf("%s", out) t.Logf("%s", out)
t.Fatal(err) t.Fatal(err)
} }
}
os.Remove("libgo.a") func TestInstall(t *testing.T) {
os.Remove("libgo.h") defer os.RemoveAll("pkg")
os.Remove("testp")
cmd = exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo.a", "libgo") testInstall(t, "./testp1"+exeSuffix,
cmd.Env = gopathEnv filepath.Join("pkg", libgodir, "libgo.a"),
if out, err := cmd.CombinedOutput(); err != nil { filepath.Join("pkg", libgodir, "libgo.h"),
t.Logf("%s", out) "go", "install", "-buildmode=c-archive", "libgo")
t.Fatal(err)
}
compilemain(t, "libgo.a") // Test building libgo other than installing it.
// Header files are now present.
testInstall(t, "./testp2"+exeSuffix, "libgo.a", "libgo.h",
"go", "build", "-buildmode=c-archive", filepath.Join("src", "libgo", "libgo.go"))
if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil { testInstall(t, "./testp3"+exeSuffix, "libgo.a", "libgo.h",
t.Logf("%s", out) "go", "build", "-buildmode=c-archive", "-o", "libgo.a", "libgo")
t.Fatal(err)
}
} }
func TestEarlySignalHandler(t *testing.T) { func TestEarlySignalHandler(t *testing.T) {
......
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