aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2023-02-02 10:42:46 -0500
committerGopher Robot <gobot@golang.org>2023-02-02 19:27:33 +0000
commit4b43d668c2ae42465af7cbad4bc5fa86d0b6cc15 (patch)
treecc68055be7392a361312de837006dc8cbeb56c54 /src/cmd
parent18772915a1b9ca211a4bb707de59ee0941b4773b (diff)
downloadgo-4b43d668c2ae42465af7cbad4bc5fa86d0b6cc15.tar.xz
internal/testenv: avoid rebuilding all of std in WriteImportcfg
Instead, have the caller pass in an explicit list of the packages (if any) they need. After #47257, a builder running a test does not necessarily have the entire standard library already cached, especially when running tests in sharded mode. testenv.WriteImportcfg used to write an importcfg for the entire standard library — which required rebuilding the entire standard library — even though most tests need only a tiny subset. This reduces the time to test internal/abi with a cold build cache on my workstation from ~16s to ~0.05s. It somewhat increases the time for 'go test go/internal/gcimporter' with a cold cache, from ~43s to ~54s, presumably due to decreased parallelism in rebuilding the standard library and increased overhead in re-resolving the import map. However, 'go test -short' running time remains stable (~5.5s before and after). Fixes #58248. Change-Id: I9be6b61ae6e28b75b53af85207c281bb93b9346f Reviewed-on: https://go-review.googlesource.com/c/go/+/464736 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/internal/archive/archive_test.go2
-rw-r--r--src/cmd/link/link_test.go22
-rw-r--r--src/cmd/objdump/objdump_test.go2
-rw-r--r--src/cmd/pack/pack_test.go4
4 files changed, 15 insertions, 15 deletions
diff --git a/src/cmd/internal/archive/archive_test.go b/src/cmd/internal/archive/archive_test.go
index 0e2c7bca75..10a3d6ebeb 100644
--- a/src/cmd/internal/archive/archive_test.go
+++ b/src/cmd/internal/archive/archive_test.go
@@ -113,7 +113,7 @@ func buildGoobj(t *testing.T) goobjPaths {
go2src := filepath.Join("testdata", "go2.go")
importcfgfile := filepath.Join(buildDir, "importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
+ testenv.WriteImportcfg(t, importcfgfile, nil, go1src, go2src)
out, err := testenv.Command(t, gotool, "tool", "compile", "-importcfg="+importcfgfile, "-p=p", "-o", go1obj, go1src).CombinedOutput()
if err != nil {
diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go
index 4dca2e20d6..b4ef9ada17 100644
--- a/src/cmd/link/link_test.go
+++ b/src/cmd/link/link_test.go
@@ -49,15 +49,16 @@ func main() {}
`
tmpdir := t.TempDir()
+ main := filepath.Join(tmpdir, "main.go")
- importcfgfile := filepath.Join(tmpdir, "importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
-
- err := os.WriteFile(filepath.Join(tmpdir, "main.go"), []byte(source), 0666)
+ err := os.WriteFile(main, []byte(source), 0666)
if err != nil {
t.Fatalf("failed to write main.go: %v\n", err)
}
+ importcfgfile := filepath.Join(tmpdir, "importcfg")
+ testenv.WriteImportcfg(t, importcfgfile, nil, main)
+
cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "main.go")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
@@ -101,11 +102,10 @@ func TestIssue28429(t *testing.T) {
}
}
- importcfgfile := filepath.Join(tmpdir, "importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
-
// Compile a main package.
write("main.go", "package main; func main() {}")
+ importcfgfile := filepath.Join(tmpdir, "importcfg")
+ testenv.WriteImportcfg(t, importcfgfile, nil, filepath.Join(tmpdir, "main.go"))
runGo("tool", "compile", "-importcfg="+importcfgfile, "-p=main", "main.go")
runGo("tool", "pack", "c", "main.a", "main.o")
@@ -243,7 +243,7 @@ void foo() {
cflags := strings.Fields(runGo("env", "GOGCCFLAGS"))
importcfgfile := filepath.Join(tmpdir, "importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
+ testenv.WriteImportcfg(t, importcfgfile, nil, "runtime")
// Compile, assemble and pack the Go and C code.
runGo("tool", "asm", "-p=main", "-gensymabis", "-o", "symabis", "x.s")
@@ -787,10 +787,10 @@ func TestIndexMismatch(t *testing.T) {
mObj := filepath.Join(tmpdir, "main.o")
exe := filepath.Join(tmpdir, "main.exe")
- importcfgFile := filepath.Join(tmpdir, "stdlib.importcfg")
- testenv.WriteImportcfg(t, importcfgFile, nil)
+ importcfgFile := filepath.Join(tmpdir, "runtime.importcfg")
+ testenv.WriteImportcfg(t, importcfgFile, nil, "runtime")
importcfgWithAFile := filepath.Join(tmpdir, "witha.importcfg")
- testenv.WriteImportcfg(t, importcfgWithAFile, map[string]string{"a": aObj})
+ testenv.WriteImportcfg(t, importcfgWithAFile, map[string]string{"a": aObj}, "runtime")
// Build a program with main package importing package a.
cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-importcfg="+importcfgFile, "-p=a", "-o", aObj, aSrc)
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go
index 69b4cf4e21..226e74d81e 100644
--- a/src/cmd/objdump/objdump_test.go
+++ b/src/cmd/objdump/objdump_test.go
@@ -299,7 +299,7 @@ func TestDisasmGoobj(t *testing.T) {
tmp := t.TempDir()
importcfgfile := filepath.Join(tmp, "hello.importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
+ testenv.WriteImportcfg(t, importcfgfile, nil, "testdata/fmthello.go")
hello := filepath.Join(tmp, "hello.o")
args := []string{"tool", "compile", "-p=main", "-importcfg=" + importcfgfile, "-o", hello}
diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go
index be75738093..5534a10b37 100644
--- a/src/cmd/pack/pack_test.go
+++ b/src/cmd/pack/pack_test.go
@@ -210,7 +210,7 @@ func TestHello(t *testing.T) {
}
importcfgfile := filepath.Join(dir, "hello.importcfg")
- testenv.WriteImportcfg(t, importcfgfile, nil)
+ testenv.WriteImportcfg(t, importcfgfile, nil, hello)
goBin := testenv.GoToolPath(t)
run(goBin, "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "hello.go")
@@ -284,7 +284,7 @@ func TestLargeDefs(t *testing.T) {
goBin := testenv.GoToolPath(t)
run(goBin, "tool", "compile", "-importcfg="+importcfgfile, "-p=large", "large.go")
run(packPath(t), "grc", "large.a", "large.o")
- testenv.WriteImportcfg(t, importcfgfile, map[string]string{"large": filepath.Join(dir, "large.o")})
+ testenv.WriteImportcfg(t, importcfgfile, map[string]string{"large": filepath.Join(dir, "large.o")}, "runtime")
run(goBin, "tool", "compile", "-importcfg="+importcfgfile, "-p=main", "main.go")
run(goBin, "tool", "link", "-importcfg="+importcfgfile, "-L", ".", "-o", "a.out", "main.o")
out := run("./a.out")