From 747c2a09119facc969faaffcd257f5e1e5bc64ad Mon Sep 17 00:00:00 2001 From: linmaolin Date: Fri, 27 Dec 2024 17:43:58 +0800 Subject: [PATCH] go/packages: add GOROOT env to avoid TestTarget failure in OpenBSD When running tests in OpenBSD if 'go' is built with -trimpath, the TestTarget will always fail. Because when invoked without proper environments, 'go' itself fails to find the GOROOT path. Fixes golang/go#70891 --- go/packages/packages_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 7f6181c27fe..be2278be22f 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -3361,9 +3361,12 @@ func main() { `) gopath := filepath.Join(dir, "gopath") + // See https://golang.org/issue/70891. + // OpenBSD hasn't a /proc filesystem. When running with a -trimpath + // built go, it will always fail without a GOROOT. pkgs, err := packages.Load(&packages.Config{ Mode: packages.NeedName | packages.NeedTarget, - Env: []string{"GOPATH=" + gopath, "GO111MODULE=off"}, + Env: []string{"GOPATH=" + gopath, "GO111MODULE=off", "GOROOT=" + os.Getenv("GOROOT")}, }, filepath.Join(gopath, "src", "...")) if err != nil { t.Fatal(err)