Merge "Create a ninja.environment file"
This commit is contained in:
@@ -23,10 +23,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"android/soong/shared"
|
||||||
"android/soong/ui/metrics"
|
"android/soong/ui/metrics"
|
||||||
"android/soong/ui/status"
|
"android/soong/ui/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// File containing the environment state when ninja is executed
|
||||||
|
ninjaEnvFileName = "ninja.environment"
|
||||||
|
)
|
||||||
|
|
||||||
// Constructs and runs the Ninja command line with a restricted set of
|
// Constructs and runs the Ninja command line with a restricted set of
|
||||||
// environment variables. It's important to restrict the environment Ninja runs
|
// environment variables. It's important to restrict the environment Ninja runs
|
||||||
// for hermeticity reasons, and to avoid spurious rebuilds.
|
// for hermeticity reasons, and to avoid spurious rebuilds.
|
||||||
@@ -186,6 +192,21 @@ func runNinjaForBuild(ctx Context, config Config) {
|
|||||||
ctx.Verbosef(" %s", envVar)
|
ctx.Verbosef(" %s", envVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the env vars available during ninja execution to a file
|
||||||
|
ninjaEnvVars := cmd.Environment.AsMap()
|
||||||
|
data, err := shared.EnvFileContents(ninjaEnvVars)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Panicf("Could not parse environment variables for ninja run %s", err)
|
||||||
|
}
|
||||||
|
// Write the file in every single run. This is fine because
|
||||||
|
// 1. It is not a dep of Soong analysis, so will not retrigger Soong analysis.
|
||||||
|
// 2. Is is fairly lightweight (~1Kb)
|
||||||
|
ninjaEnvVarsFile := shared.JoinPath(config.SoongOutDir(), ninjaEnvFileName)
|
||||||
|
err = os.WriteFile(ninjaEnvVarsFile, data, 0666)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Panicf("Could not write ninja environment file %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Poll the Ninja log for updates regularly based on the heartbeat
|
// Poll the Ninja log for updates regularly based on the heartbeat
|
||||||
// frequency. If it isn't updated enough, then we want to surface the
|
// frequency. If it isn't updated enough, then we want to surface the
|
||||||
// possibility that Ninja is stuck, to the user.
|
// possibility that Ninja is stuck, to the user.
|
||||||
|
Reference in New Issue
Block a user