Merge "Fix dumpvars $PATH / $TMPDIR"

This commit is contained in:
Treehugger Robot 2019-10-07 19:29:17 +00:00 committed by Gerrit Code Review
commit bd7c98ce22
2 changed files with 59 additions and 1 deletions

View file

@ -17,6 +17,8 @@ package build
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"android/soong/ui/metrics"
@ -51,7 +53,17 @@ func DumpMakeVars(ctx Context, config Config, goals, vars []string) (map[string]
var ret map[string]string
if len(makeVars) > 0 {
var err error
tmpDir, err := ioutil.TempDir("", "dumpvars")
if err != nil {
return nil, err
}
defer os.RemoveAll(tmpDir)
// It's not safe to use the same TMPDIR as the build, as that can be removed.
config.Environment().Set("TMPDIR", tmpDir)
SetupLitePath(ctx, config)
ret, err = dumpMakeVars(ctx, config, goals, makeVars, false)
if err != nil {
return ret, err

View file

@ -18,6 +18,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
@ -53,6 +54,51 @@ func parsePathDir(dir string) []string {
return ret
}
// A "lite" version of SetupPath used for dumpvars, or other places that need
// minimal overhead (but at the expense of logging).
func SetupLitePath(ctx Context, config Config) {
if config.pathReplaced {
return
}
ctx.BeginTrace(metrics.RunSetupTool, "litepath")
defer ctx.EndTrace()
origPath, _ := config.Environment().Get("PATH")
myPath, _ := config.Environment().Get("TMPDIR")
myPath = filepath.Join(myPath, "path")
ensureEmptyDirectoriesExist(ctx, myPath)
os.Setenv("PATH", origPath)
for name, pathConfig := range paths.Configuration {
if !pathConfig.Symlink {
continue
}
origExec, err := exec.LookPath(name)
if err != nil {
continue
}
origExec, err = filepath.Abs(origExec)
if err != nil {
continue
}
err = os.Symlink(origExec, filepath.Join(myPath, name))
if err != nil {
ctx.Fatalln("Failed to create symlink:", err)
}
}
myPath, _ = filepath.Abs(myPath)
prebuiltsPath, _ := filepath.Abs("prebuilts/build-tools/path/" + runtime.GOOS + "-x86")
myPath = prebuiltsPath + string(os.PathListSeparator) + myPath
config.Environment().Set("PATH", myPath)
config.pathReplaced = true
}
func SetupPath(ctx Context, config Config) {
if config.pathReplaced {
return