From a88632793cbd9cce2c1384fcfd7a92c954f0bb05 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Tue, 8 Mar 2022 00:27:30 +0000 Subject: [PATCH] stdliblist: Fix for Go 1.18 by replicating stdlib The stdliblist operation that the gopackagesdriver relies on fails on Go 1.18rc1 with the following error: ``` external/go_sdk/src/crypto/elliptic/p256_asm.go:24:12: pattern p256_asm_table.bin: cannot embed irregular file p256_asm_table.bin ``` We see this failure because Bazel builds a symlink tree of the GOROOT run `go list` with. However, since [CL 380475][1], the Go standard library uses `go:embed` to embed a file in `crypto/elliptic`, but `go:embed` does not support symlinks. [1]: https://go.dev/cl/380475 Fix this by having stdliblist copy the relevant portions of the GOROOT to run `go list` with. This matches [what the stdlib action does][2]. [2]: https://github.com/bazelbuild/rules_go/blob/e9a7054ff11a520e3b8aceb76a3ba44bb8da4c94/go/tools/builders/stdlib.go#L54-L57 Resolves #3080 --- go/tools/builders/stdliblist.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/go/tools/builders/stdliblist.go b/go/tools/builders/stdliblist.go index ec7e3161ae..8d26fa6146 100644 --- a/go/tools/builders/stdliblist.go +++ b/go/tools/builders/stdliblist.go @@ -158,19 +158,22 @@ func stdliblist(args []string) error { return err } + execRoot := abs(".") + if err := replicate(os.Getenv("GOROOT"), execRoot, replicatePaths("src", "pkg/tool", "pkg/include")); err != nil { + return err + } + // Ensure paths are absolute. absPaths := []string{} for _, path := range filepath.SplitList(os.Getenv("PATH")) { absPaths = append(absPaths, abs(path)) } os.Setenv("PATH", strings.Join(absPaths, string(os.PathListSeparator))) - os.Setenv("GOROOT", abs(os.Getenv("GOROOT"))) + os.Setenv("GOROOT", execRoot) // Make sure we have an absolute path to the C compiler. // TODO(#1357): also take absolute paths of includes and other paths in flags. os.Setenv("CC", abs(os.Getenv("CC"))) - execRoot := abs(".") - cachePath := abs(*out + ".gocache") defer os.RemoveAll(cachePath) os.Setenv("GOCACHE", cachePath)