Allow multiple ninja implementations
This permits easier testing and comparison between different ninja
implementations.
Bug: 362926979
Bug: 318434287
Test: manual
Change-Id: Ic058338d0a2fd8c988794a0781dcc93c0f4c03e3
diff --git a/ui/build/ninja.go b/ui/build/ninja.go
index 4e3e544..def0783 100644
--- a/ui/build/ninja.go
+++ b/ui/build/ninja.go
@@ -49,14 +49,10 @@
nr := status.NewNinjaReader(ctx, ctx.Status.StartTool(), fifo)
defer nr.Close()
- executable := config.NinjaBin()
- args := []string{
- "-d", "keepdepfile",
- "-d", "keeprsp",
- "-d", "stats",
- "--frontend_file", fifo,
- }
- if config.useN2 {
+ var executable string
+ var args []string
+ switch config.ninjaCommand {
+ case NINJA_N2:
executable = config.N2Bin()
args = []string{
"-d", "trace",
@@ -66,8 +62,31 @@
//"-d", "stats",
"--frontend-file", fifo,
}
+ case NINJA_SISO:
+ executable = config.SisoBin()
+ args = []string{
+ "ninja",
+ "--log_dir", config.SoongOutDir(),
+ // TODO: implement these features, or remove them.
+ //"-d", "trace",
+ //"-d", "keepdepfile",
+ //"-d", "keeprsp",
+ //"-d", "stats",
+ //"--frontend-file", fifo,
+ }
+ default:
+ // NINJA_NINJA is the default.
+ executable = config.NinjaBin()
+ args = []string{
+ "-d", "keepdepfile",
+ "-d", "keeprsp",
+ "-d", "stats",
+ "--frontend_file", fifo,
+ "-o", "usesphonyoutputs=yes",
+ "-w", "dupbuild=err",
+ "-w", "missingdepfile=err",
+ }
}
-
args = append(args, config.NinjaArgs()...)
var parallel int
@@ -83,17 +102,10 @@
args = append(args, "-f", config.CombinedNinjaFile())
- if !config.useN2 {
- args = append(args,
- "-o", "usesphonyoutputs=yes",
- "-w", "dupbuild=err",
- "-w", "missingdepfile=err")
- }
-
if !config.BuildBrokenMissingOutputs() {
// Missing outputs will be treated as errors.
// BUILD_BROKEN_MISSING_OUTPUTS can be used to bypass this check.
- if !config.useN2 {
+ if config.ninjaCommand != NINJA_N2 {
args = append(args,
"-w", "missingoutfile=err",
)
@@ -110,21 +122,18 @@
cmd.Environment.AppendFromKati(config.KatiEnvFile())
}
- switch config.NinjaWeightListSource() {
- case NINJA_LOG:
- if !config.useN2 {
+ // TODO(b/346806126): implement this for the other ninjaCommand values.
+ if config.ninjaCommand == NINJA_NINJA {
+ switch config.NinjaWeightListSource() {
+ case NINJA_LOG:
cmd.Args = append(cmd.Args, "-o", "usesninjalogasweightlist=yes")
- }
- case EVENLY_DISTRIBUTED:
- // pass empty weight list means ninja considers every tasks's weight as 1(default value).
- if !config.useN2 {
+ case EVENLY_DISTRIBUTED:
+ // pass empty weight list means ninja considers every tasks's weight as 1(default value).
cmd.Args = append(cmd.Args, "-o", "usesweightlist=/dev/null")
- }
- case EXTERNAL_FILE:
- fallthrough
- case HINT_FROM_SOONG:
- // The weight list is already copied/generated.
- if !config.useN2 {
+ case EXTERNAL_FILE:
+ fallthrough
+ case HINT_FROM_SOONG:
+ // The weight list is already copied/generated.
ninjaWeightListPath := filepath.Join(config.OutDir(), ninjaWeightListFileName)
cmd.Args = append(cmd.Args, "-o", "usesweightlist="+ninjaWeightListPath)
}
@@ -227,6 +236,8 @@
// We don't want this build broken flag to cause reanalysis, so allow it through to the
// actions.
"BUILD_BROKEN_INCORRECT_PARTITION_IMAGES",
+ // Do not do reanalysis just because we changed ninja commands.
+ "SOONG_NINJA",
"SOONG_USE_N2",
"RUST_BACKTRACE",
"RUST_LOG",
@@ -235,8 +246,11 @@
cmd.Environment.Set("DIST_DIR", config.DistDir())
cmd.Environment.Set("SHELL", "/bin/bash")
- if config.useN2 {
+ switch config.ninjaCommand {
+ case NINJA_N2:
cmd.Environment.Set("RUST_BACKTRACE", "1")
+ default:
+ // Only set RUST_BACKTRACE for n2.
}
// Print the environment variables that Ninja is operating in.