diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-02-02 10:42:46 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-02 19:27:33 +0000 |
| commit | 4b43d668c2ae42465af7cbad4bc5fa86d0b6cc15 (patch) | |
| tree | cc68055be7392a361312de837006dc8cbeb56c54 /src/cmd/link | |
| parent | 18772915a1b9ca211a4bb707de59ee0941b4773b (diff) | |
| download | go-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/link')
| -rw-r--r-- | src/cmd/link/link_test.go | 22 |
1 files changed, 11 insertions, 11 deletions
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) |
