Merge "Fix dumpvars $PATH / $TMPDIR"
This commit is contained in:
@@ -17,6 +17,8 @@ package build
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"android/soong/ui/metrics"
|
"android/soong/ui/metrics"
|
||||||
@@ -51,7 +53,17 @@ func DumpMakeVars(ctx Context, config Config, goals, vars []string) (map[string]
|
|||||||
|
|
||||||
var ret map[string]string
|
var ret map[string]string
|
||||||
if len(makeVars) > 0 {
|
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)
|
ret, err = dumpMakeVars(ctx, config, goals, makeVars, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -53,6 +54,51 @@ func parsePathDir(dir string) []string {
|
|||||||
return ret
|
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) {
|
func SetupPath(ctx Context, config Config) {
|
||||||
if config.pathReplaced {
|
if config.pathReplaced {
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user