Expand handling of unconverted deps in bp2build
Support three options for converting modules with unconverted
dependencies
1. (default) Warn when converting a module if it has unconverted deps.
2. Error when encountering a module with unconverted deps. (not hooked
up yet)
Test: build/bazel/ci/bp2build.sh
Test: build/bazel/ci/mixed_libc.sh
Test: BP2BUILD_ERROR_UNCONVERTED=1 build/bazel/ci/bp2build.sh with
unconverted deps -- get appropriate error
Bug: 181155349
Change-Id: Ifaabf0cd2e43e963366dc137159c705294165c3d
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index 06a7306..48b2945 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -19,6 +19,7 @@
"android/soong/bazel"
"fmt"
"os"
+ "strings"
)
// Codegen is the backend of bp2build. The code generator is responsible for
@@ -29,14 +30,22 @@
bp2buildDir := android.PathForOutput(ctx, "bp2build")
android.RemoveAllOutputDir(bp2buildDir)
- buildToTargets, metrics, compatLayer := GenerateBazelTargets(ctx, true)
- bp2buildFiles := CreateBazelFiles(nil, buildToTargets, ctx.mode)
+ res, errs := GenerateBazelTargets(ctx, true)
+ if len(errs) > 0 {
+ errMsgs := make([]string, len(errs))
+ for i, err := range errs {
+ errMsgs[i] = fmt.Sprintf("%q", err)
+ }
+ fmt.Printf("ERROR: Encountered %d error(s): \nERROR: %s", len(errs), strings.Join(errMsgs, "\n"))
+ os.Exit(1)
+ }
+ bp2buildFiles := CreateBazelFiles(nil, res.buildFileToTargets, ctx.mode)
writeFiles(ctx, bp2buildDir, bp2buildFiles)
soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
- writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(compatLayer))
+ writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.compatLayer))
- return metrics
+ return res.metrics
}
// Get the output directory and create it if it doesn't exist.