Fix SOONG_DUMP_JSON_MODULE_GRAPH on a fresh checkout.

This CL adds generateJsonModuleGraph bazelBuildMode and ensures that it
returns Soong early, before Kati and Soong metrics collection begin
(which causes errors, since they're looking for files that Soong in json
dump mode did not write).

Test: TH
Test: rm -rf out && SOONG_DUMP_JSON_MODULE_GRAPH=/tmp/soong.json m nothing

Change-Id: I264eadb3b3b0cd6b6e7a65adc7b39bb1c01ca136
This commit is contained in:
Jingwen Chen
2021-06-24 08:41:16 +00:00
parent a8de9fb2ae
commit dd9725c177
3 changed files with 13 additions and 2 deletions

View File

@@ -274,6 +274,11 @@ func Build(ctx Context, config Config) {
// Return early, if we're using Soong as solely the generator of BUILD files. // Return early, if we're using Soong as solely the generator of BUILD files.
return return
} }
if config.bazelBuildMode() == generateJsonModuleGraph {
// Return early, if we're using Soong as solely the generator of the JSON module graph
return
}
} }
if what&RunKati != 0 { if what&RunKati != 0 {

View File

@@ -108,6 +108,9 @@ const (
// Only generate build files (in a subdirectory of the out directory) and exit. // Only generate build files (in a subdirectory of the out directory) and exit.
generateBuildFiles generateBuildFiles
// Only generate the Soong json module graph for use with jq, and exit.
generateJsonModuleGraph
// Generate synthetic build files and incorporate these files into a build which // Generate synthetic build files and incorporate these files into a build which
// partially uses Bazel. Build metadata may come from Android.bp or BUILD files. // partially uses Bazel. Build metadata may come from Android.bp or BUILD files.
mixedBuild mixedBuild
@@ -936,6 +939,8 @@ func (c *configImpl) bazelBuildMode() bazelBuildMode {
return mixedBuild return mixedBuild
} else if c.Environment().IsEnvTrue("GENERATE_BAZEL_FILES") { } else if c.Environment().IsEnvTrue("GENERATE_BAZEL_FILES") {
return generateBuildFiles return generateBuildFiles
} else if v, ok := c.Environment().Get("SOONG_DUMP_JSON_MODULE_GRAPH"); ok && v != "" {
return generateJsonModuleGraph
} else { } else {
return noBazel return noBazel
} }

View File

@@ -333,8 +333,9 @@ func runSoong(ctx Context, config Config) {
} }
func shouldCollectBuildSoongMetrics(config Config) bool { func shouldCollectBuildSoongMetrics(config Config) bool {
// Do not collect metrics protobuf if the soong_build binary ran as the bp2build converter. // Do not collect metrics protobuf if the soong_build binary ran as the
return config.bazelBuildMode() != generateBuildFiles // bp2build converter or the JSON graph dump.
return config.bazelBuildMode() != generateBuildFiles && config.bazelBuildMode() != generateJsonModuleGraph
} }
func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics { func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {