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

This commit is contained in:
Treehugger Robot
2020-06-05 19:32:30 +00:00
committed by Gerrit Code Review
2 changed files with 16 additions and 11 deletions

View File

@@ -54,18 +54,16 @@ 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 {
// It's not safe to use the same TMPDIR as the build, as that can be removed.
tmpDir, err := ioutil.TempDir("", "dumpvars") tmpDir, err := ioutil.TempDir("", "dumpvars")
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
// It's not safe to use the same TMPDIR as the build, as that can be removed. SetupLitePath(ctx, config, tmpDir)
config.Environment().Set("TMPDIR", tmpDir)
SetupLitePath(ctx, config) ret, err = dumpMakeVars(ctx, config, goals, makeVars, false, tmpDir)
ret, err = dumpMakeVars(ctx, config, goals, makeVars, false)
if err != nil { if err != nil {
return ret, err return ret, err
} }
@@ -82,7 +80,7 @@ func DumpMakeVars(ctx Context, config Config, goals, vars []string) (map[string]
return ret, nil return ret, nil
} }
func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_vars bool) (map[string]string, error) { func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_vars bool, tmpDir string) (map[string]string, error) {
ctx.BeginTrace(metrics.RunKati, "dumpvars") ctx.BeginTrace(metrics.RunKati, "dumpvars")
defer ctx.EndTrace() defer ctx.EndTrace()
@@ -98,6 +96,9 @@ func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_
cmd.Environment.Set("WRITE_SOONG_VARIABLES", "true") cmd.Environment.Set("WRITE_SOONG_VARIABLES", "true")
} }
cmd.Environment.Set("DUMP_MANY_VARS", strings.Join(vars, " ")) cmd.Environment.Set("DUMP_MANY_VARS", strings.Join(vars, " "))
if tmpDir != "" {
cmd.Environment.Set("TMPDIR", tmpDir)
}
cmd.Sandbox = dumpvarsSandbox cmd.Sandbox = dumpvarsSandbox
output := bytes.Buffer{} output := bytes.Buffer{}
cmd.Stdout = &output cmd.Stdout = &output
@@ -253,7 +254,7 @@ func runMakeProductConfig(ctx Context, config Config) {
"BUILD_BROKEN_USES_BUILD_STATIC_LIBRARY", "BUILD_BROKEN_USES_BUILD_STATIC_LIBRARY",
}, exportEnvVars...), BannerVars...) }, exportEnvVars...), BannerVars...)
make_vars, err := dumpMakeVars(ctx, config, config.Arguments(), allVars, true) make_vars, err := dumpMakeVars(ctx, config, config.Arguments(), allVars, true, "")
if err != nil { if err != nil {
ctx.Fatalln("Error dumping make vars:", err) ctx.Fatalln("Error dumping make vars:", err)
} }

View File

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