Build mode function should return output file
Each build mode has to provide an output file, which also has a
corresponding dependency file (<output file>.d). Previously, some of
the build mode functions returned that file, others just returned and
relied on the doChosenActivity() method to return the file.
That was confusing as the same file name was referenced from two
separate places. This change makes all the build mode functions return
their output file explicitly and the doChosenActivity()just returns
what it receives. It also moves the writeDepsFile call to adjacent to
the return.
Bug: 257650737
Test: m nothing
Change-Id: I35f96ab404d9ffb1da747a3ecb8fc4e1feb9c026
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 99f0e3b..5a96314 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -348,13 +348,11 @@
// output file of the specific activity.
func doChosenActivity(ctx *android.Context, configuration android.Config, extraNinjaDeps []string, metricsDir string) string {
if configuration.BuildMode == android.SymlinkForest {
- runSymlinkForestCreation(configuration, ctx, extraNinjaDeps, metricsDir)
- return symlinkForestMarker
+ return runSymlinkForestCreation(configuration, ctx, extraNinjaDeps, metricsDir)
} else if configuration.BuildMode == android.Bp2build {
// Run the alternate pipeline of bp2build mutators and singleton to convert
// Blueprint to BUILD files before everything else.
- runBp2Build(configuration, ctx, extraNinjaDeps, metricsDir)
- return bp2buildMarker
+ return runBp2Build(configuration, ctx, extraNinjaDeps, metricsDir)
} else if configuration.BuildMode == android.ApiBp2build {
outputFile := runApiBp2build(configuration, ctx, extraNinjaDeps)
writeMetrics(configuration, ctx.EventHandler, metricsDir)
@@ -419,8 +417,8 @@
// The actual output (build.ninja) was written in the RunBlueprint() call
// above
writeDepFile(cmdlineArgs.OutFile, ctx.EventHandler, ninjaDeps)
+ return cmdlineArgs.OutFile
}
- return cmdlineArgs.OutFile
}
// soong_ui dumps the available environment variables to
@@ -627,7 +625,7 @@
// Ideally, bp2build would write a file that contains instructions to the
// symlink tree creation binary. Then the latter would not need to depend on
// the very heavy-weight machinery of soong_build .
-func runSymlinkForestCreation(configuration android.Config, ctx *android.Context, extraNinjaDeps []string, metricsDir string) {
+func runSymlinkForestCreation(configuration android.Config, ctx *android.Context, extraNinjaDeps []string, metricsDir string) string {
var ninjaDeps []string
ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
@@ -671,12 +669,14 @@
//invocation of codegen. We should simply use a separate .pb file
}
writeBp2BuildMetrics(codegenMetrics, ctx.EventHandler, metricsDir)
+
+ return symlinkForestMarker
}
// Run Soong in the bp2build mode. This creates a standalone context that registers
// an alternate pipeline of mutators and singletons specifically for generating
// Bazel BUILD files instead of Ninja files.
-func runBp2Build(configuration android.Config, ctx *android.Context, extraNinjaDeps []string, metricsDir string) {
+func runBp2Build(configuration android.Config, ctx *android.Context, extraNinjaDeps []string, metricsDir string) string {
var codegenMetrics *bp2build.CodegenMetrics
ctx.EventHandler.Do("bp2build", func() {
@@ -722,6 +722,7 @@
codegenMetrics.Print()
}
writeBp2BuildMetrics(codegenMetrics, ctx.EventHandler, metricsDir)
+ return bp2buildMarker
}
// Write Bp2Build metrics into $LOG_DIR