Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cl/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"runtime"
"slices"
"strings"
"sync"
"testing"

"github.com/goplus/gogen/packages"
Expand Down Expand Up @@ -313,6 +314,21 @@ func testRunAndTestFrom(t *testing.T, pkgDir, relPkg, sel string, opts runOption
}
}

// sharedGoCacheDir returns a per-process go-build cache reused by every
// captured run. Isolation from the developer cache is preserved (fresh
// temp dir per test process); sharing across tests avoids re-typechecking
// the whole dependency graph for each of the ~170 golden dirs.
var goCacheOnce sync.Once
var goCacheDir string
var goCacheErr error

func sharedGoCacheDir() (string, error) {
goCacheOnce.Do(func() {
goCacheDir, goCacheErr = os.MkdirTemp("", "llgo-gocache-*")
})
return goCacheDir, goCacheErr
}

func RunAndCapture(relPkg, pkgDir string) ([]byte, error) {
conf := build.NewDefaultConf(build.ModeRun)
return RunAndCaptureWithConf(relPkg, pkgDir, conf)
Expand Down Expand Up @@ -376,11 +392,10 @@ func runWithConf(relPkg, pkgDir string, conf *build.Config) ([]byte, error) {
}

func doWithConf(relPkg, pkgDir string, conf *build.Config, action string) ([]byte, error) {
cacheDir, err := os.MkdirTemp("", "llgo-gocache-*")
cacheDir, err := sharedGoCacheDir()
if err != nil {
return nil, err
}
defer os.RemoveAll(cacheDir)
oldCache := os.Getenv("GOCACHE")
if err := os.Setenv("GOCACHE", cacheDir); err != nil {
return nil, err
Expand Down
Loading