Skip to content

Commit 29fdab5

Browse files
JamyDevlinzhp
authored andcommitted
Fix stdlib file outputs pointing to processwrapper (#3608)
1 parent d71926d commit 29fdab5

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

go/private/actions/stdlib.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ def _should_use_sdk_stdlib(go):
6565

6666
def _build_stdlib_list_json(go):
6767
out = go.declare_file(go, "stdlib.pkg.json")
68+
cache_dir = go.declare_directory(go, "gocache")
6869
args = go.builder_args(go, "stdliblist")
6970
args.add("-sdk", go.sdk.root_file.dirname)
7071
args.add("-out", out)
72+
args.add("-cache", cache_dir.path)
7173

7274
inputs = go.sdk_files
7375
if not go.mode.pure:
7476
inputs += go.crosstool
7577

7678
go.actions.run(
7779
inputs = inputs,
78-
outputs = [out],
80+
outputs = [out, cache_dir],
7981
mnemonic = "GoStdlibList",
8082
executable = go.toolchain._builder,
8183
arguments = [args],

go/tools/builders/stdliblist.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ func absoluteSourcesPaths(cloneBase, pkgDir string, srcs []string) []string {
139139
// extension (which are from the cache). This is a work around for
140140
// https://golang.org/issue/28749: cmd/go puts assembly, C, and C++ files in
141141
// CompiledGoFiles.
142-
func filterGoFiles(srcs []string) []string {
142+
func filterGoFiles(srcs []string, pathReplaceFn func(p string) string) []string {
143143
ret := make([]string, 0, len(srcs))
144144
for _, f := range srcs {
145145
if ext := filepath.Ext(f); ext == ".go" || ext == "" {
146-
ret = append(ret, f)
146+
ret = append(ret, pathReplaceFn(f))
147147
}
148148
}
149149

150150
return ret
151151
}
152152

153-
func flatPackageForStd(cloneBase string, pkg *goListPackage) *flatPackage {
153+
func flatPackageForStd(cloneBase string, pkg *goListPackage, pathReplaceFn func(p string) string) *flatPackage {
154154
goFiles := absoluteSourcesPaths(cloneBase, pkg.Dir, pkg.GoFiles)
155155
compiledGoFiles := absoluteSourcesPaths(cloneBase, pkg.Dir, pkg.CompiledGoFiles)
156156

@@ -162,7 +162,7 @@ func flatPackageForStd(cloneBase string, pkg *goListPackage) *flatPackage {
162162
Imports: map[string]string{},
163163
Standard: pkg.Standard,
164164
GoFiles: goFiles,
165-
CompiledGoFiles: filterGoFiles(compiledGoFiles),
165+
CompiledGoFiles: filterGoFiles(compiledGoFiles, pathReplaceFn),
166166
}
167167

168168
// imports
@@ -194,6 +194,7 @@ func stdliblist(args []string) error {
194194
flags := flag.NewFlagSet("stdliblist", flag.ExitOnError)
195195
goenv := envFlags(flags)
196196
out := flags.String("out", "", "Path to output go list json")
197+
cachePath := flags.String("cache", "", "Path to use for GOCACHE")
197198
if err := flags.Parse(args); err != nil {
198199
return err
199200
}
@@ -250,10 +251,10 @@ func stdliblist(args []string) error {
250251
os.Setenv("CC", quotePathIfNeeded(abs(ccEnv)))
251252

252253
// We want to keep the cache around so that the processed files can be used by other tools.
253-
cachePath := abs(*out + ".gocache")
254-
os.Setenv("GOCACHE", cachePath)
255-
os.Setenv("GOMODCACHE", cachePath)
256-
os.Setenv("GOPATH", cachePath)
254+
absCachePath := abs(*cachePath)
255+
os.Setenv("GOCACHE", absCachePath)
256+
os.Setenv("GOMODCACHE", absCachePath)
257+
os.Setenv("GOPATH", absCachePath)
257258

258259
listArgs := goenv.goCmd("list")
259260
if len(build.Default.BuildTags) > 0 {
@@ -279,12 +280,19 @@ func stdliblist(args []string) error {
279280

280281
encoder := json.NewEncoder(jsonFile)
281282
decoder := json.NewDecoder(jsonData)
283+
pathReplaceFn := func (s string) string {
284+
if strings.HasPrefix(s, absCachePath) {
285+
return strings.Replace(s, absCachePath, filepath.Join("__BAZEL_EXECROOT__", *cachePath), 1)
286+
}
287+
288+
return s
289+
}
282290
for decoder.More() {
283291
var pkg *goListPackage
284292
if err := decoder.Decode(&pkg); err != nil {
285293
return err
286294
}
287-
if err := encoder.Encode(flatPackageForStd(cloneBase, pkg)); err != nil {
295+
if err := encoder.Encode(flatPackageForStd(cloneBase, pkg, pathReplaceFn)); err != nil {
288296
return err
289297
}
290298
}

0 commit comments

Comments
 (0)