summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Spandan Das <spandandas@google.com> 2023-02-16 18:31:43 +0000
committer Spandan Das <spandandas@google.com> 2023-02-28 23:49:22 +0000
commit2db59da973c97ec1bd228bcae0f5ca5dbf00504f (patch)
treefd6d0d03a1014344828f3d8e4c5d74c05efe5f92
parent7ae8afc1155a2eee9172bc96073da72cb01ef650 (diff)
Create a ninja.environment file
This contains the environment variables set by soong_ui during the ninja execution. This file will be unused in single-tree builds, but will be useful for multi-tree. The orchestrator will use this file to set the correct environment for each inner tree build in the combined ninja execution. Test: m nothing compiles Change-Id: I0570e34f51f426448464fb80030d4bea1cd52acb
-rw-r--r--ui/build/ninja.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/ui/build/ninja.go b/ui/build/ninja.go
index dab1a9b58..28f3c3806 100644
--- a/ui/build/ninja.go
+++ b/ui/build/ninja.go
@@ -23,10 +23,16 @@ import (
"strings"
"time"
+ "android/soong/shared"
"android/soong/ui/metrics"
"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
// environment variables. It's important to restrict the environment Ninja runs
// for hermeticity reasons, and to avoid spurious rebuilds.
@@ -186,6 +192,21 @@ func runNinjaForBuild(ctx Context, config Config) {
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
// frequency. If it isn't updated enough, then we want to surface the
// possibility that Ninja is stuck, to the user.