Commit 1e4a88fa authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/link/internal/ld: make dwarf_test and associated testdata module-agnostic

Updates #30228

Change-Id: I31aac4cb113c0c88a54329181ad27aee3d8acc71
Reviewed-on: https://go-review.googlesource.com/c/162835
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarThan McIntosh <thanm@google.com>
parent b88462ef
...@@ -114,26 +114,14 @@ func gobuild(t *testing.T, dir string, testfile string, gcflags string) *builtFi ...@@ -114,26 +114,14 @@ func gobuild(t *testing.T, dir string, testfile string, gcflags string) *builtFi
return &builtFile{f, dst} return &builtFile{f, dst}
} }
func envWithGoPathSet(gp string) []string { // Similar to gobuild() above, but uses a main package instead of a test.go file.
env := os.Environ()
for i := 0; i < len(env); i++ {
if strings.HasPrefix(env[i], "GOPATH=") {
env[i] = "GOPATH=" + gp
return env
}
}
env = append(env, "GOPATH="+gp)
return env
}
// Similar to gobuild() above, but runs off a separate GOPATH environment
func gobuildTestdata(t *testing.T, tdir string, gopathdir string, packtobuild string, gcflags string) *builtFile { func gobuildTestdata(t *testing.T, tdir string, pkgDir string, gcflags string) *builtFile {
dst := filepath.Join(tdir, "out.exe") dst := filepath.Join(tdir, "out.exe")
// Run a build with an updated GOPATH // Run a build with an updated GOPATH
cmd := exec.Command(testenv.GoToolPath(t), "build", gcflags, "-o", dst, packtobuild) cmd := exec.Command(testenv.GoToolPath(t), "build", gcflags, "-o", dst)
cmd.Env = envWithGoPathSet(gopathdir) cmd.Dir = pkgDir
if b, err := cmd.CombinedOutput(); err != nil { if b, err := cmd.CombinedOutput(); err != nil {
t.Logf("build: %s\n", b) t.Logf("build: %s\n", b)
t.Fatalf("build error: %v", err) t.Fatalf("build error: %v", err)
...@@ -727,7 +715,7 @@ func main() { ...@@ -727,7 +715,7 @@ func main() {
} }
} }
func abstractOriginSanity(t *testing.T, gopathdir string, flags string) { func abstractOriginSanity(t *testing.T, pkgDir string, flags string) {
t.Parallel() t.Parallel()
dir, err := ioutil.TempDir("", "TestAbstractOriginSanity") dir, err := ioutil.TempDir("", "TestAbstractOriginSanity")
...@@ -737,7 +725,7 @@ func abstractOriginSanity(t *testing.T, gopathdir string, flags string) { ...@@ -737,7 +725,7 @@ func abstractOriginSanity(t *testing.T, gopathdir string, flags string) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
// Build with inlining, to exercise DWARF inlining support. // Build with inlining, to exercise DWARF inlining support.
f := gobuildTestdata(t, dir, gopathdir, "main", flags) f := gobuildTestdata(t, dir, filepath.Join(pkgDir, "main"), flags)
d, err := f.DWARF() d, err := f.DWARF()
if err != nil { if err != nil {
......
package main package main
import "a" import "cmd/link/internal/ld/testdata/issue25459/a"
var Glob int var Glob int
......
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
b "b.dir" b "cmd/link/internal/ld/testdata/issue26237/b.dir"
) )
var skyx int var skyx int
......
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