-
-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lazy expand absolute path to avoid including them in the output (#4009)
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** It fixes reproducibility issues reported in #3994 by lazy-expanding paths to absolute paths **Which issues(s) does this PR fix?** Fixes #3994
- Loading branch information
1 parent
29d4e5d
commit 64759ee
Showing
7 changed files
with
179 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ filegroup( | |
"ar.go", | ||
"asm.go", | ||
"builder.go", | ||
"cc.go", | ||
"cgo2.go", | ||
"compilepkg.go", | ||
"constants.go", | ||
|
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,47 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func cc(args []string) error { | ||
cc := os.Getenv("GO_CC") | ||
if cc == "" { | ||
errors.New("GO_CC environment variable not set") | ||
} | ||
ccroot := os.Getenv("GO_CC_ROOT") | ||
if ccroot == "" { | ||
errors.New("GO_CC_ROOT environment variable not set") | ||
} | ||
normalized := []string{cc} | ||
normalized = append(normalized, args...) | ||
transformArgs(normalized, cgoAbsEnvFlags, func(s string) string { | ||
if strings.HasPrefix(s, cgoAbsPlaceholder) { | ||
trimmed := strings.TrimPrefix(s, cgoAbsPlaceholder) | ||
abspath := filepath.Join(ccroot, trimmed) | ||
if _, err := os.Stat(abspath); err == nil { | ||
// Only return the abspath if it exists, otherwise it | ||
// means that either it won't have any effect or the original | ||
// value was not a relpath (e.g. a path with a XCODE placehold from | ||
// macos cc_wrapper) | ||
return abspath | ||
} | ||
return trimmed | ||
} | ||
return s | ||
}) | ||
if runtime.GOOS == "windows" { | ||
cmd := exec.Command(normalized[0], normalized[1:]...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} else { | ||
return syscall.Exec(normalized[0], normalized, os.Environ()) | ||
} | ||
} |
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