Fix dumpvars $PATH / $TMPDIR

Instead of just using the host $PATH during dumpvars, use our path
configuration from the regular build. But instead of creating a ton of
symlinks to the interposer, just use a small directory of symlinks. This
only takes ~3ms (vs ~300ms), at the expense of error logging. Since we
do just about the same product configuration at the start of the build,
we can just rely on the logging there.

This fixes warnings printed by the Mac build, since we using the host
`date` instead of the toybox version:

usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

TMPDIR was being shared with the main build, but we're allowed to run in
parallel. If a build is started while we're running, our TMPDIR may be
cleared. Instead, create our own temporary directory, which doesn't need
to be a stable value (as we never do caching here).

Fixes: 141893400
Test: (on mac) source build/envsetup.sh; lunch
Change-Id: I0ff536e71dc5649cae26daa0087eb80861704021
This commit is contained in:
Dan Willemsen 2019-10-03 16:45:58 -07:00
parent 96ce6ab143
commit 4e2456bc09
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