Allow n2 as a replacement for ninja in builds
If `SOONG_USE_N2=true` is set in the environment, then n2 is used in
place of ninja. Some ninja features are not available in n2 at this
time, but this enables bringup efforts to happen in parallel.
Bug: 352368206
Test: manual
Change-Id: I8455cb24eb640a4651782ee76e48a7d3a9932b93
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 77fee0a..e18cc25 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -638,6 +638,22 @@
"--frontend_file", fifo,
"-f", filepath.Join(config.SoongOutDir(), "bootstrap.ninja"),
}
+ if config.useN2 {
+ ninjaArgs = []string{
+ // TODO: implement these features, or remove them.
+ //"-d", "keepdepfile",
+ //"-d", "stats",
+ //"-o", "usesphonyoutputs=yes",
+ //"-o", "preremoveoutputs=yes",
+ //"-w", "dupbuild=err",
+ //"-w", "outputdir=err",
+ //"-w", "missingoutfile=err",
+ "-v",
+ "-j", strconv.Itoa(config.Parallel()),
+ "--frontend-file", fifo,
+ "-f", filepath.Join(config.SoongOutDir(), "bootstrap.ninja"),
+ }
+ }
if extra, ok := config.Environment().Get("SOONG_UI_NINJA_ARGS"); ok {
ctx.Printf(`CAUTION: arguments in $SOONG_UI_NINJA_ARGS=%q, e.g. "-n", can make soong_build FAIL or INCORRECT`, extra)
@@ -645,8 +661,13 @@
}
ninjaArgs = append(ninjaArgs, targets...)
+ ninjaCmd := config.PrebuiltBuildTool("ninja")
+ if config.useN2 {
+ ninjaCmd = config.PrebuiltBuildTool("n2")
+ }
+
cmd := Command(ctx, config, "soong bootstrap",
- config.PrebuiltBuildTool("ninja"), ninjaArgs...)
+ ninjaCmd, ninjaArgs...)
var ninjaEnv Environment