Merge "Delete bazel-related files while bazel is off" into main
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 5ae8430..abdfeda 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -632,6 +632,10 @@
if config.BazelBuildEnabled() || config.Bp2Build() {
checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(bp2buildFilesTag))
+ } else {
+ // Remove bazel files in the event that bazel is disabled for the build.
+ // These files may have been left over from a previous bazel-enabled build.
+ cleanBazelFiles(config)
}
if config.JsonModuleGraph() {
@@ -790,6 +794,18 @@
}
}
+func cleanBazelFiles(config Config) {
+ files := []string{
+ shared.JoinPath(config.SoongOutDir(), "bp2build"),
+ shared.JoinPath(config.SoongOutDir(), "workspace"),
+ shared.JoinPath(config.SoongOutDir(), bazel.SoongInjectionDirName),
+ shared.JoinPath(config.OutDir(), "bazel")}
+
+ for _, f := range files {
+ os.RemoveAll(f)
+ }
+}
+
func runMicrofactory(ctx Context, config Config, name string, pkg string, mapping map[string]string) {
ctx.BeginTrace(metrics.RunSoong, name)
defer ctx.EndTrace()