Pass the TMPDIR directly to the command when dumping makefile variables.

External applications such as metrics uploader depends on the TMPDIR.
DumpMakeVars is changing the TMPDIR environment variable value. Once
the work is done, TMPDIR directory is deleted. Additional flow of
the tool or external applications can panic since TMPDIR directory
does not exist. Since this is an isolated case, pass the TMPDIR
directory to the command of dumping the makefile variables.

Bug: b/140638454
Test: * Ran lunch command with ANDROID_ENABLE_METRICS_UPLOAD set
        and metrics_uploader did not crash.
      * m nothing
Change-Id: Ib78a3f8cfb5da48f65bd9bce1511e9abdf3d9cca
This commit is contained in:
Patrice Arruda
2020-06-04 19:34:41 +00:00
parent ad14580f99
commit ae2694b30d
2 changed files with 16 additions and 11 deletions

View File

@@ -55,8 +55,9 @@ func parsePathDir(dir string) []string {
}
// 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) {
// minimal overhead (but at the expense of logging). If tmpDir is empty, the
// default TMPDIR is used from config.
func SetupLitePath(ctx Context, config Config, tmpDir string) {
if config.pathReplaced {
return
}
@@ -65,8 +66,11 @@ func SetupLitePath(ctx Context, config Config) {
defer ctx.EndTrace()
origPath, _ := config.Environment().Get("PATH")
myPath, _ := config.Environment().Get("TMPDIR")
myPath = filepath.Join(myPath, "path")
if tmpDir == "" {
tmpDir, _ = config.Environment().Get("TMPDIR")
}
myPath := filepath.Join(tmpDir, "path")
ensureEmptyDirectoriesExist(ctx, myPath)
os.Setenv("PATH", origPath)