Subsume INTEGRATED_BP2BUILD into other env modes
This refactors bazel-build mode determination logic in soong_ui so it's
clearer which of three possible modes are being used in a given
invocation (NO_BAZEL, GENERATE_BUILD_FILES, or MIXED_BUILDS).
Test: bootstrap tests
Change-Id: I41d2baebf8d560c2cc42db8daa8b936101d453e3
diff --git a/ui/build/build.go b/ui/build/build.go
index 3692f4f..c2ad057 100644
--- a/ui/build/build.go
+++ b/ui/build/build.go
@@ -258,8 +258,8 @@
// Run Soong
runSoong(ctx, config)
- if config.Environment().IsEnvTrue("GENERATE_BAZEL_FILES") {
- // Return early, if we're using Soong as the bp2build converter.
+ if config.bazelBuildMode() == generateBuildFiles {
+ // Return early, if we're using Soong as solely the generator of BUILD files.
return
}
}
diff --git a/ui/build/config.go b/ui/build/config.go
index 4816d1f..1d1f71f 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -93,6 +93,21 @@
BUILD_MODULES
)
+type bazelBuildMode int
+
+// Bazel-related build modes.
+const (
+ // Don't use bazel at all.
+ noBazel bazelBuildMode = iota
+
+ // Only generate build files (in a subdirectory of the out directory) and exit.
+ generateBuildFiles
+
+ // 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
+)
+
// checkTopDir validates that the current directory is at the root directory of the source tree.
func checkTopDir(ctx Context) {
if _, err := os.Stat(srcDirFileCheck); err != nil {
@@ -897,6 +912,16 @@
return c.useBazel
}
+func (c *configImpl) bazelBuildMode() bazelBuildMode {
+ if c.Environment().IsEnvTrue("USE_BAZEL_ANALYSIS") {
+ return mixedBuild
+ } else if c.Environment().IsEnvTrue("GENERATE_BAZEL_FILES") {
+ return generateBuildFiles
+ } else {
+ return noBazel
+ }
+}
+
func (c *configImpl) StartRBE() bool {
if !c.UseRBE() {
return false
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 7e94b25..a41dbe1 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -206,7 +206,8 @@
}
}
- integratedBp2Build := config.Environment().IsEnvTrue("INTEGRATED_BP2BUILD")
+ buildMode := config.bazelBuildMode()
+ integratedBp2Build := (buildMode == mixedBuild) || (buildMode == generateBuildFiles)
// This is done unconditionally, but does not take a measurable amount of time
bootstrapBlueprint(ctx, config, integratedBp2Build)
@@ -312,7 +313,7 @@
func shouldCollectBuildSoongMetrics(config Config) bool {
// Do not collect metrics protobuf if the soong_build binary ran as the bp2build converter.
- return config.Environment().IsFalse("GENERATE_BAZEL_FILES")
+ return config.bazelBuildMode() != generateBuildFiles
}
func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {