From dd9725c177f221a556bedf8c2407236d051601ac Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Thu, 24 Jun 2021 08:41:16 +0000 Subject: [PATCH] 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 --- ui/build/build.go | 5 +++++ ui/build/config.go | 5 +++++ ui/build/soong.go | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ui/build/build.go b/ui/build/build.go index 8f050d9be..1187aa2cf 100644 --- a/ui/build/build.go +++ b/ui/build/build.go @@ -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 } + + 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 { diff --git a/ui/build/config.go b/ui/build/config.go index b9aaaf84e..480672171 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -108,6 +108,9 @@ const ( // Only generate build files (in a subdirectory of the out directory) and exit. 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 // partially uses Bazel. Build metadata may come from Android.bp or BUILD files. mixedBuild @@ -936,6 +939,8 @@ func (c *configImpl) bazelBuildMode() bazelBuildMode { return mixedBuild } else if c.Environment().IsEnvTrue("GENERATE_BAZEL_FILES") { return generateBuildFiles + } else if v, ok := c.Environment().Get("SOONG_DUMP_JSON_MODULE_GRAPH"); ok && v != "" { + return generateJsonModuleGraph } else { return noBazel } diff --git a/ui/build/soong.go b/ui/build/soong.go index 19a47ae7c..a40457fc6 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -333,8 +333,9 @@ func runSoong(ctx Context, config Config) { } func shouldCollectBuildSoongMetrics(config Config) bool { - // Do not collect metrics protobuf if the soong_build binary ran as the bp2build converter. - return config.bazelBuildMode() != generateBuildFiles + // Do not collect metrics protobuf if the soong_build binary ran as the + // bp2build converter or the JSON graph dump. + return config.bazelBuildMode() != generateBuildFiles && config.bazelBuildMode() != generateJsonModuleGraph } func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {