Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xytan0056 committed May 16, 2022
1 parent 68b94d1 commit 8b0dde2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 7 additions & 6 deletions go/tools/builders/stdliblist.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ func flatPackageForStd(cloneBase string, pkg *goListPackage) *flatPackage {
// If we run "go list" with that GOROOT, this action will fail because those
// go:embed directives will refuse to include the symlinks in the sandbox.
//
// To work around this, cloneGoRoot creates a copy of external/go_sdk into a new
// cloneBase directory while retaining its path relative to the root directory.
// To work around this, cloneGoRoot creates a copy of a subset of external/go_sdk
// that is sufficient to call "go list" into a new cloneBase directory while
// retaining its path relative to the root directory, e.g. "go list" needs to
// call "compile", which needs "pkg/tool".
// So "$OUTPUT_BASE/external/go_sdk" becomes
// {cloneBase}/external/go_sdk", which will be set at GOROOT later.
// This ensures that file paths in the generated JSON are still valid.
// {cloneBase}/external/go_sdk", which will be set at GOROOT later. This ensures
// that file paths in the generated JSON are still valid.
//
// cloneGoRoot returns the new GOROOT we should run
// under.
// cloneGoRoot returns the new GOROOT we should run under.
func cloneGoRoot(execRoot, relativeGoroot, cloneBase string) (newGoRoot string, err error) {
goroot := filepath.Join(execRoot, relativeGoroot)
newGoRoot = filepath.Join(cloneBase, relativeGoroot)
Expand Down
11 changes: 8 additions & 3 deletions go/tools/builders/stdliblist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -14,7 +14,7 @@ import (

func Test_stdliblist(t *testing.T) {
testDir := t.TempDir()
f, _ := ioutil.TempFile(testDir, "*")
outJSON := filepath.Join(testDir, "out.json")

// test files are at run file directory, but this test is run at
// {runfile directory}/bazel.TestWorkspace()
Expand All @@ -27,7 +27,7 @@ func Test_stdliblist(t *testing.T) {
t.Error("failed to find runfiles path")
}
test_args := []string{
fmt.Sprintf("-out=%s", f.Name()),
fmt.Sprintf("-out=%s", outJSON),
fmt.Sprintf("-sdk=%s", "go_sdk"),
fmt.Sprintf("-wd=%s", filepath.Dir(filepath.Clean(runFilesPath))),
}
Expand All @@ -36,6 +36,11 @@ func Test_stdliblist(t *testing.T) {
if 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() }()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
var result flatPackage
Expand Down

0 comments on commit 8b0dde2

Please sign in to comment.