Reapply "Clean environment variables to account for sandbox work directory."

with minor edits.

This reverts commit 9543d19b4b.

Bug: 363037195
Change-Id: I4cb10b312b7f468185bfad12a16f9b4b64e7a58a
This commit is contained in:
Taylor Santiago
2024-09-03 13:30:22 -07:00
parent 13d8e82c5e
commit 8b0bed7187
3 changed files with 96 additions and 25 deletions

View File

@@ -57,6 +57,22 @@ func parsePathDir(dir string) []string {
return ret
}
func updatePathForSandbox(config Config) {
wd, err := os.Getwd()
if err != nil {
return
}
var newPath []string
if path, ok := config.Environment().Get("PATH"); ok && path != "" {
entries := strings.Split(path, string(filepath.ListSeparator))
for _, ent := range entries {
newPath = append(newPath, config.sandboxPath(wd, ent))
}
}
config.Environment().Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
}
// SetupLitePath is the "lite" version of SetupPath used for dumpvars, or other
// places that does not need the full logging capabilities of path_interposer,
// wants the minimal performance overhead, and still get the benefits of $PATH
@@ -121,6 +137,7 @@ func SetupLitePath(ctx Context, config Config, tmpDir string) {
// Set $PATH to be the directories containing the host tool symlinks, and
// the prebuilts directory for the current host OS.
config.Environment().Set("PATH", myPath)
updatePathForSandbox(config)
config.pathReplaced = true
}
@@ -265,5 +282,6 @@ func SetupPath(ctx Context, config Config) {
// Replace the $PATH variable with the path_interposer symlinks, and
// checked-in prebuilts.
config.Environment().Set("PATH", myPath)
updatePathForSandbox(config)
config.pathReplaced = true
}