cmd/link/internal/ld: simplify gobuildTestdata

Drop the second argument, which is is always a one-time temporary
directory, thus it can be created right here.

Change-Id: I73e5be2ccd4bddec249c7cb2a8ff9242d99f7e20
Reviewed-on: https://go-review.googlesource.com/c/go/+/610037
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Kir Kolyshkin 2024-09-03 19:32:40 -07:00 committed by Gopher Robot
parent fbe74d8ddb
commit dfae83c9db

View file

@ -131,8 +131,8 @@ func gobuild(t *testing.T, dir string, testfile string, gcflags string) *builtFi
// Similar to gobuild() above, but uses a main package instead of a test.go file. // Similar to gobuild() above, but uses a main package instead of a test.go file.
func gobuildTestdata(t *testing.T, tdir string, pkgDir string, gcflags string) *builtFile { func gobuildTestdata(t *testing.T, pkgDir string, gcflags string) *builtFile {
dst := filepath.Join(tdir, "out.exe") dst := filepath.Join(t.TempDir(), "out.exe")
// Run a build with an updated GOPATH // Run a build with an updated GOPATH
cmd := testenv.Command(t, testenv.GoToolPath(t), "build", gcflags, "-o", dst) cmd := testenv.Command(t, testenv.GoToolPath(t), "build", gcflags, "-o", dst)
@ -762,10 +762,8 @@ func main() {
func abstractOriginSanity(t *testing.T, pkgDir string, flags string) { func abstractOriginSanity(t *testing.T, pkgDir string, flags string) {
t.Parallel() t.Parallel()
dir := t.TempDir()
// Build with inlining, to exercise DWARF inlining support. // Build with inlining, to exercise DWARF inlining support.
f := gobuildTestdata(t, dir, filepath.Join(pkgDir, "main"), flags) f := gobuildTestdata(t, filepath.Join(pkgDir, "main"), flags)
defer f.Close() defer f.Close()
d, err := f.DWARF() d, err := f.DWARF()
@ -1231,14 +1229,12 @@ func TestMachoIssue32233(t *testing.T) {
t.Skip("skipping; test only interesting on darwin") t.Skip("skipping; test only interesting on darwin")
} }
tmpdir := t.TempDir()
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatalf("where am I? %v", err) t.Fatalf("where am I? %v", err)
} }
pdir := filepath.Join(wd, "testdata", "issue32233", "main") pdir := filepath.Join(wd, "testdata", "issue32233", "main")
f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) f := gobuildTestdata(t, pdir, DefaultOpt)
f.Close() f.Close()
} }
@ -1313,13 +1309,12 @@ func TestIssue38192(t *testing.T) {
// Build a test program that contains a translation unit whose // Build a test program that contains a translation unit whose
// text (from am assembly source) contains only a single instruction. // text (from am assembly source) contains only a single instruction.
tmpdir := t.TempDir()
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatalf("where am I? %v", err) t.Fatalf("where am I? %v", err)
} }
pdir := filepath.Join(wd, "testdata", "issue38192") pdir := filepath.Join(wd, "testdata", "issue38192")
f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) f := gobuildTestdata(t, pdir, DefaultOpt)
defer f.Close() defer f.Close()
// Open the resulting binary and examine the DWARF it contains. // Open the resulting binary and examine the DWARF it contains.
@ -1431,14 +1426,12 @@ func TestIssue39757(t *testing.T) {
// compiler/runtime in ways that aren't happening now, so this // compiler/runtime in ways that aren't happening now, so this
// might be something to check for if it does start failing. // might be something to check for if it does start failing.
tmpdir := t.TempDir()
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatalf("where am I? %v", err) t.Fatalf("where am I? %v", err)
} }
pdir := filepath.Join(wd, "testdata", "issue39757") pdir := filepath.Join(wd, "testdata", "issue39757")
f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) f := gobuildTestdata(t, pdir, DefaultOpt)
defer f.Close() defer f.Close()
syms, err := f.Symbols() syms, err := f.Symbols()
@ -1529,17 +1522,12 @@ func TestIssue42484(t *testing.T) {
t.Parallel() t.Parallel()
tmpdir, err := os.MkdirTemp("", "TestIssue42484")
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
defer os.RemoveAll(tmpdir)
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatalf("where am I? %v", err) t.Fatalf("where am I? %v", err)
} }
pdir := filepath.Join(wd, "testdata", "issue42484") pdir := filepath.Join(wd, "testdata", "issue42484")
f := gobuildTestdata(t, tmpdir, pdir, NoOpt) f := gobuildTestdata(t, pdir, NoOpt)
var lastAddr uint64 var lastAddr uint64
var lastFile string var lastFile string