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
This commit is contained in:
parent
b8ea9f3cc8
commit
ec1a3dc6f8
|
@ -174,7 +174,7 @@ func writeJsonModuleGraph(configuration android.Config, ctx *android.Context, pa
|
|||
}
|
||||
|
||||
func doChosenActivity(configuration android.Config, extraNinjaDeps []string) string {
|
||||
bazelConversionRequested := configuration.IsEnvTrue("GENERATE_BAZEL_FILES") || bp2buildMarker != ""
|
||||
bazelConversionRequested := bp2buildMarker != ""
|
||||
mixedModeBuild := configuration.BazelContext.BazelEnabled()
|
||||
generateQueryView := bazelQueryViewDir != ""
|
||||
jsonModuleFile := configuration.Getenv("SOONG_DUMP_JSON_MODULE_GRAPH")
|
||||
|
|
|
@ -482,14 +482,14 @@ function test_null_build_after_docs {
|
|||
fi
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_smoke {
|
||||
function test_bp2build_smoke {
|
||||
setup
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
[[ -e out/soong/.bootstrap/bp2build_workspace_marker ]] || fail "bp2build marker file not created"
|
||||
[[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_add_android_bp {
|
||||
function test_bp2build_add_android_bp {
|
||||
setup
|
||||
|
||||
mkdir -p a
|
||||
|
@ -502,7 +502,7 @@ filegroup {
|
|||
}
|
||||
EOF
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
[[ -e out/soong/bp2build/a/BUILD ]] || fail "a/BUILD not created"
|
||||
[[ -L out/soong/workspace/a/BUILD ]] || fail "a/BUILD not symlinked"
|
||||
|
||||
|
@ -516,18 +516,18 @@ filegroup {
|
|||
}
|
||||
EOF
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
[[ -e out/soong/bp2build/b/BUILD ]] || fail "a/BUILD not created"
|
||||
[[ -L out/soong/workspace/b/BUILD ]] || fail "a/BUILD not symlinked"
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_null_build {
|
||||
function test_bp2build_null_build {
|
||||
setup
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
local mtime1=$(stat -c "%y" out/soong/build.ninja)
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
local mtime2=$(stat -c "%y" out/soong/build.ninja)
|
||||
|
||||
if [[ "$mtime1" != "$mtime2" ]]; then
|
||||
|
@ -535,7 +535,7 @@ function test_integrated_bp2build_null_build {
|
|||
fi
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_add_to_glob {
|
||||
function test_bp2build_add_to_glob {
|
||||
setup
|
||||
|
||||
mkdir -p a
|
||||
|
@ -548,11 +548,11 @@ filegroup {
|
|||
}
|
||||
EOF
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
grep -q a1.txt out/soong/bp2build/a/BUILD || fail "a1.txt not in BUILD file"
|
||||
|
||||
touch a/a2.txt
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
grep -q a2.txt out/soong/bp2build/a/BUILD || fail "a2.txt not in BUILD file"
|
||||
}
|
||||
|
||||
|
@ -564,7 +564,7 @@ function test_dump_json_module_graph() {
|
|||
fi
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_bazel_workspace_structure {
|
||||
function test_bp2build_bazel_workspace_structure {
|
||||
setup
|
||||
|
||||
mkdir -p a/b
|
||||
|
@ -578,7 +578,7 @@ filegroup {
|
|||
}
|
||||
EOF
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
[[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
|
||||
[[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
|
||||
[[ -L out/soong/workspace/a/b/BUILD ]] || fail "BUILD file not symlinked"
|
||||
|
@ -589,7 +589,7 @@ EOF
|
|||
[[ ! -e out/soong/workspace/out ]] || fail "out directory symlinked"
|
||||
}
|
||||
|
||||
function test_integrated_bp2build_bazel_workspace_add_file {
|
||||
function test_bp2build_bazel_workspace_add_file {
|
||||
setup
|
||||
|
||||
mkdir -p a
|
||||
|
@ -602,10 +602,10 @@ filegroup {
|
|||
}
|
||||
EOF
|
||||
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
|
||||
touch a/a2.txt # No reference in the .bp file needed
|
||||
INTEGRATED_BP2BUILD=1 run_soong
|
||||
GENERATE_BAZEL_FILES=1 run_soong
|
||||
[[ -L out/soong/workspace/a/a2.txt ]] || fail "a/a2.txt not symlinked"
|
||||
}
|
||||
|
||||
|
@ -622,9 +622,9 @@ test_add_file_to_soong_build
|
|||
test_glob_during_bootstrapping
|
||||
test_soong_build_rerun_iff_environment_changes
|
||||
test_dump_json_module_graph
|
||||
test_integrated_bp2build_smoke
|
||||
test_integrated_bp2build_null_build
|
||||
test_integrated_bp2build_add_android_bp
|
||||
test_integrated_bp2build_add_to_glob
|
||||
test_integrated_bp2build_bazel_workspace_structure
|
||||
test_integrated_bp2build_bazel_workspace_add_file
|
||||
test_bp2build_smoke
|
||||
test_bp2build_null_build
|
||||
test_bp2build_add_android_bp
|
||||
test_bp2build_add_to_glob
|
||||
test_bp2build_bazel_workspace_structure
|
||||
test_bp2build_bazel_workspace_add_file
|
||||
|
|
|
@ -258,8 +258,8 @@ func Build(ctx Context, config Config, what int) {
|
|||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,21 @@ const (
|
|||
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 @@ func (c *configImpl) UseBazel() bool {
|
|||
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
|
||||
|
|
|
@ -206,7 +206,8 @@ func runSoong(ctx Context, config Config) {
|
|||
}
|
||||
}
|
||||
|
||||
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 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.Environment().IsFalse("GENERATE_BAZEL_FILES")
|
||||
return config.bazelBuildMode() != generateBuildFiles
|
||||
}
|
||||
|
||||
func loadSoongBuildMetrics(ctx Context, config Config) *soong_metrics_proto.SoongBuildMetrics {
|
||||
|
|
Loading…
Reference in New Issue