-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix gopackagesdriver for Go 1.18 by replicating stdlib and add test f…
…or stdliblist.go (#3157) * 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 * test/stdlib: Depend on _list_json Add a dependency on `GoStdLib._list_json` to the stdlib test. This ensures that we can successfully build the JSON data needed by the gopackagesdriver.
- Loading branch information
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_stdliblist(t *testing.T) { | ||
testDir := t.TempDir() | ||
outJSON := filepath.Join(testDir, "out.json") | ||
|
||
test_args := []string{ | ||
fmt.Sprintf("-out=%s", outJSON), | ||
"-sdk=external/go_sdk", | ||
} | ||
|
||
if err := stdliblist(test_args); err != nil { | ||
t.Errorf("calling stdliblist got err: %v", err) | ||
} | ||
f, err := os.Open(outJSON) | ||
if err != nil { | ||
t.Errorf("cannot open output json: %v", err) | ||
} | ||
defer func() { _ = f.Close() }() | ||
decoder := json.NewDecoder(f) | ||
for decoder.More() { | ||
var result *flatPackage | ||
if err := decoder.Decode(&result); err != nil { | ||
t.Errorf("unable to decode output json: %v\n", err) | ||
} | ||
|
||
if !strings.HasPrefix(result.ID, "@io_bazel_rules_go//stdlib") { | ||
t.Errorf("ID should be prefixed with @io_bazel_rules_go//stdlib :%v", result) | ||
} | ||
if !strings.HasPrefix(result.ExportFile, "__BAZEL_OUTPUT_BASE__") { | ||
t.Errorf("export file should be prefixed with __BAZEL_OUTPUT_BASE__ :%v", result) | ||
} | ||
for _, gofile := range result.GoFiles { | ||
if !strings.HasPrefix(gofile, "__BAZEL_OUTPUT_BASE__/external/go_sdk") { | ||
t.Errorf("all go files should be prefixed with __BAZEL_OUTPUT_BASE__/external/go_sdk :%v", result) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters