Skip to content

Commit 3d1cea4

Browse files
committed
builder: Make paths absolute for stdliblist (bazel-contrib#1357)
Make the gopackagesdriver work when using a C/C++ toolchain with sysroots. We need to turn the relative in flag like --sysroot into an absolute. Address the todo by using the code already available in the stdlib.go as part of bazel-contrib#1536.
1 parent 6655d08 commit 3d1cea4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

go/tools/builders/stdlib.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ You may need to use the flags --cpu=x64_windows --compiler=mingw-gcc.`)
8181
os.Setenv("GO111MODULE", "off")
8282

8383
// Make sure we have an absolute path to the C compiler.
84-
// TODO(#1357): also take absolute paths of includes and other paths in flags.
8584
os.Setenv("CC", quotePathIfNeeded(abs(os.Getenv("CC"))))
8685

8786
// Ensure paths are absolute.
@@ -159,7 +158,7 @@ You may need to use the flags --cpu=x64_windows --compiler=mingw-gcc.`)
159158
installArgs = append(installArgs, "-ldflags="+allSlug+strings.Join(ldflags, " "))
160159
installArgs = append(installArgs, "-asmflags="+allSlug+strings.Join(asmflags, " "))
161160

162-
// Modifying CGO flags to use only absolute path
161+
// Modify CGO flags to use only absolute path
163162
// because go is having its own sandbox, all CGO flags must use absolute path
164163
if err := absEnv(cgoEnvVars, cgoAbsEnvFlags); err != nil {
165164
return fmt.Errorf("error modifying cgo environment to absolute path: %v", err)

go/tools/builders/stdliblist.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,18 @@ func stdliblist(args []string) error {
251251

252252
cgoEnabled := os.Getenv("CGO_ENABLED") == "1"
253253
// Make sure we have an absolute path to the C compiler.
254-
// TODO(#1357): also take absolute paths of includes and other paths in flags.
255254
ccEnv, ok := os.LookupEnv("CC")
256255
if cgoEnabled && !ok {
257256
return fmt.Errorf("CC must be set")
258257
}
259258
os.Setenv("CC", quotePathIfNeeded(abs(ccEnv)))
260259

260+
// Modify CGO flags to use only absolute path
261+
// because go is having its own sandbox, all CGO flags must use absolute path
262+
if err := absEnv(cgoEnvVars, cgoAbsEnvFlags); err != nil {
263+
return fmt.Errorf("error modifying cgo environment to absolute path: %v", err)
264+
}
265+
261266
// We want to keep the cache around so that the processed files can be used by other tools.
262267
absCachePath := abs(*cachePath)
263268
os.Setenv("GOCACHE", absCachePath)

0 commit comments

Comments
 (0)