Print the JSON module graph correctly.
Before, we piggybacked on the implementation of regular soong_build and
wrote a fake build.ninja file to satisfy Ninja.
Now, instead, the JSON module graph is a a separate action in the Ninja
output file. This has the pleasant side effect that one can flip back
and forth between generating the JSON file and regular Soong without
loss of incrementality.
Side cleanup: write .d files in a slightly cleaner way.
Test: Presubmits.
Change-Id: Ia853383567b9dd31c53f3bdf56cfc8d517b498ec
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 06210b9..058f819 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -117,6 +117,7 @@
bootstrapGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.ninja")
bp2buildGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.bp2build.ninja")
+ moduleGraphGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.modulegraph.ninja")
// The glob .ninja files are subninja'd. However, they are generated during
// the build itself so we write an empty file so that the subninja doesn't
@@ -181,9 +182,27 @@
Outputs: []string{config.Bp2BuildMarkerFile()},
Args: bp2buildArgs,
}
+
+ moduleGraphArgs := []string{
+ "--module_graph_file", config.ModuleGraphFile(),
+ "--globListDir", "globs.modulegraph",
+ "--globFile", moduleGraphGlobFile,
+ }
+
+ moduleGraphArgs = append(moduleGraphArgs, commonArgs...)
+ moduleGraphArgs = append(moduleGraphArgs, environmentArgs(config, ".modulegraph")...)
+ moduleGraphArgs = append(moduleGraphArgs, "Android.bp")
+
+ moduleGraphInvocation := bootstrap.PrimaryBuilderInvocation{
+ Inputs: []string{"Android.bp"},
+ Outputs: []string{config.ModuleGraphFile()},
+ Args: moduleGraphArgs,
+ }
+
args.PrimaryBuilderInvocations = []bootstrap.PrimaryBuilderInvocation{
bp2buildInvocation,
mainSoongBuildInvocation,
+ moduleGraphInvocation,
}
blueprintCtx := blueprint.NewContext()
@@ -307,6 +326,8 @@
if config.bazelBuildMode() == generateBuildFiles {
target = config.Bp2BuildMarkerFile()
+ } else if config.bazelBuildMode() == generateJsonModuleGraph {
+ target = config.ModuleGraphFile()
} else {
// This build generates <builddir>/build.ninja, which is used later by build/soong/ui/build/build.go#Build().
target = config.MainNinjaFile()