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/android/bazel.go b/android/bazel.go
index 373e292..46fd9b6 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -61,8 +61,8 @@
HandcraftedLabel() string
GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
ConvertWithBp2build(ctx BazelConversionPathContext) bool
+ convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool
GetBazelBuildFileContents(c Config, path, name string) (string, error)
- ConvertedToBazel(ctx BazelConversionPathContext) bool
}
// BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules.
@@ -311,9 +311,10 @@
if !ctx.Config().BazelContext.BazelEnabled() {
return false
}
- if len(b.GetBazelLabel(ctx, ctx.Module())) == 0 {
+ if !convertedToBazel(ctx, ctx.Module()) {
return false
}
+
if GenerateCcLibraryStaticOnly(ctx) {
// Don't use partially-converted cc_library targets in mixed builds,
// since mixed builds would generally rely on both static and shared
@@ -323,20 +324,33 @@
return !mixedBuildsDisabled[ctx.Module().Name()]
}
+// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.
+func convertedToBazel(ctx BazelConversionPathContext, module blueprint.Module) bool {
+ b, ok := module.(Bazelable)
+ if !ok {
+ return false
+ }
+ return b.convertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
+}
+
// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionPathContext) bool {
- if bp2buildModuleDoNotConvert[ctx.Module().Name()] {
+ return b.convertWithBp2build(ctx, ctx.Module())
+}
+
+func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool {
+ if bp2buildModuleDoNotConvert[module.Name()] {
return false
}
// Ensure that the module type of this module has a bp2build converter. This
// prevents mixed builds from using auto-converted modules just by matching
// the package dir; it also has to have a bp2build mutator as well.
- if ctx.Config().bp2buildModuleTypeConfig[ctx.ModuleType()] == false {
+ if ctx.Config().bp2buildModuleTypeConfig[ctx.OtherModuleType(module)] == false {
return false
}
- packagePath := ctx.ModuleDir()
+ packagePath := ctx.OtherModuleDir(module)
config := ctx.Config().bp2buildPackageConfig
// This is a tristate value: true, false, or unset.
@@ -407,9 +421,3 @@
}
return string(data[:]), nil
}
-
-// ConvertedToBazel returns whether this module has been converted to Bazel, whether automatically
-// or manually
-func (b *BazelModuleBase) ConvertedToBazel(ctx BazelConversionPathContext) bool {
- return b.ConvertWithBp2build(ctx) || b.HasHandcraftedLabel()
-}
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index a4bd2ef..ccbc156 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -75,9 +75,10 @@
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
ModuleFromName(name string) (blueprint.Module, bool)
Module() Module
- ModuleType() string
+ OtherModuleType(m blueprint.Module) string
OtherModuleName(m blueprint.Module) string
OtherModuleDir(m blueprint.Module) string
+ AddUnconvertedBp2buildDep(string)
}
// BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>"
@@ -345,6 +346,9 @@
if m == nil {
panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name()))
}
+ if !convertedToBazel(ctx, m) {
+ ctx.AddUnconvertedBp2buildDep(dep)
+ }
otherLabel := bazelModuleLabel(ctx, m, tag)
label := bazelModuleLabel(ctx, ctx.Module(), "")
if isWholeLibs {
@@ -363,11 +367,10 @@
func bazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module, tag string) string {
// TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets.
- b, ok := module.(Bazelable)
- // TODO(b/181155349): perhaps return an error here if the module can't be/isn't being converted
- if !ok || !b.ConvertedToBazel(ctx) {
+ if !convertedToBazel(ctx, module) {
return bp2buildModuleLabel(ctx, module)
}
+ b, _ := module.(Bazelable)
return b.GetBazelLabel(ctx, module)
}
diff --git a/android/module.go b/android/module.go
index dd6a25a..9532cbc 100644
--- a/android/module.go
+++ b/android/module.go
@@ -316,6 +316,9 @@
AddMissingDependencies(missingDeps []string)
+ // AddUnconvertedBp2buildDep stores module name of a direct dependency that was not converted via bp2build
+ AddUnconvertedBp2buildDep(dep string)
+
Target() Target
TargetPrimary() bool
@@ -496,6 +499,7 @@
IsConvertedByBp2build() bool
// Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module
Bp2buildTargets() []bp2buildInfo
+ GetUnconvertedBp2buildDeps() []string
BuildParamsForTests() []BuildParams
RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
@@ -833,6 +837,10 @@
// supported as Soong handles some things within a single target that we may choose to split into
// multiple targets, e.g. renderscript, protos, yacc within a cc module.
Bp2buildInfo []bp2buildInfo `blueprint:"mutated"`
+
+ // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to
+ // Bazel
+ UnconvertedBp2buildDeps []string `blueprint:"mutated"`
}
type distProperties struct {
@@ -1212,6 +1220,18 @@
return m.commonProperties.Bp2buildInfo
}
+// AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel.
+func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) {
+ unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps
+ *unconvertedDeps = append(*unconvertedDeps, dep)
+}
+
+// GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that
+// were not converted to Bazel.
+func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string {
+ return m.commonProperties.UnconvertedBp2buildDeps
+}
+
func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
(*d)["Android"] = map[string]interface{}{}
}
diff --git a/android/mutator.go b/android/mutator.go
index 20ec621..c6b6676 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -532,7 +532,6 @@
BazelProps: bazelProps,
Attrs: attrs,
}
-
t.Module().base().addBp2buildInfo(info)
}
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.
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index f652a35..6cce819 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -153,10 +153,11 @@
}
type CodegenContext struct {
- config android.Config
- context android.Context
- mode CodegenMode
- additionalDeps []string
+ config android.Config
+ context android.Context
+ mode CodegenMode
+ additionalDeps []string
+ unconvertedDepMode unconvertedDepsMode
}
func (c *CodegenContext) Mode() CodegenMode {
@@ -181,6 +182,16 @@
QueryView
)
+type unconvertedDepsMode int
+
+const (
+ // Include a warning in conversion metrics about converted modules with unconverted direct deps
+ warnUnconvertedDeps unconvertedDepsMode = iota
+ // Error and fail conversion if encountering a module with unconverted direct deps
+ // Enabled by setting environment variable `BP2BUILD_ERROR_UNCONVERTED`
+ errorModulesUnconvertedDeps
+)
+
func (mode CodegenMode) String() string {
switch mode {
case Bp2Build:
@@ -211,10 +222,15 @@
// NewCodegenContext creates a wrapper context that conforms to PathContext for
// writing BUILD files in the output directory.
func NewCodegenContext(config android.Config, context android.Context, mode CodegenMode) *CodegenContext {
+ var unconvertedDeps unconvertedDepsMode
+ if config.IsEnvTrue("BP2BUILD_ERROR_UNCONVERTED") {
+ unconvertedDeps = errorModulesUnconvertedDeps
+ }
return &CodegenContext{
- context: context,
- config: config,
- mode: mode,
+ context: context,
+ config: config,
+ mode: mode,
+ unconvertedDepMode: unconvertedDeps,
}
}
@@ -230,7 +246,17 @@
return attributes
}
-func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (map[string]BazelTargets, CodegenMetrics, CodegenCompatLayer) {
+type conversionResults struct {
+ buildFileToTargets map[string]BazelTargets
+ metrics CodegenMetrics
+ compatLayer CodegenCompatLayer
+}
+
+func (r conversionResults) BuildDirToTargets() map[string]BazelTargets {
+ return r.buildFileToTargets
+}
+
+func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (conversionResults, []error) {
buildFileToTargets := make(map[string]BazelTargets)
buildFileToAppend := make(map[string]bool)
@@ -245,6 +271,8 @@
dirs := make(map[string]bool)
+ var errs []error
+
bpCtx := ctx.Context()
bpCtx.VisitAllModules(func(m blueprint.Module) {
dir := bpCtx.ModuleDir(m)
@@ -266,13 +294,24 @@
}
t, err := getHandcraftedBuildContent(ctx, b, pathToBuildFile)
if err != nil {
- panic(fmt.Errorf("Error converting %s: %s", bpCtx.ModuleName(m), err))
+ errs = append(errs, fmt.Errorf("Error converting %s: %s", bpCtx.ModuleName(m), err))
+ return
}
targets = append(targets, t)
// TODO(b/181575318): currently we append the whole BUILD file, let's change that to do
// something more targeted based on the rule type and target
buildFileToAppend[pathToBuildFile] = true
} else if aModule, ok := m.(android.Module); ok && aModule.IsConvertedByBp2build() {
+ if unconvertedDeps := aModule.GetUnconvertedBp2buildDeps(); len(unconvertedDeps) > 0 {
+ msg := fmt.Sprintf("%q depends on unconverted modules: %s", m.Name(), strings.Join(unconvertedDeps, ", "))
+ if ctx.unconvertedDepMode == warnUnconvertedDeps {
+ metrics.moduleWithUnconvertedDepsMsgs = append(metrics.moduleWithUnconvertedDepsMsgs, msg)
+ } else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps {
+ metrics.TotalModuleCount += 1
+ errs = append(errs, fmt.Errorf(msg))
+ return
+ }
+ }
targets = generateBazelTargets(bpCtx, aModule)
for _, t := range targets {
if t.name == m.Name() {
@@ -295,11 +334,17 @@
t := generateSoongModuleTarget(bpCtx, m)
targets = append(targets, t)
default:
- panic(fmt.Errorf("Unknown code-generation mode: %s", ctx.Mode()))
+ errs = append(errs, fmt.Errorf("Unknown code-generation mode: %s", ctx.Mode()))
+ return
}
buildFileToTargets[dir] = append(buildFileToTargets[dir], targets...)
})
+
+ if len(errs) > 0 {
+ return conversionResults{}, errs
+ }
+
if generateFilegroups {
// Add a filegroup target that exposes all sources in the subtree of this package
// NOTE: This also means we generate a BUILD file for every Android.bp file (as long as it has at least one module)
@@ -312,7 +357,11 @@
}
}
- return buildFileToTargets, metrics, compatLayer
+ return conversionResults{
+ buildFileToTargets: buildFileToTargets,
+ metrics: metrics,
+ compatLayer: compatLayer,
+ }, errs
}
func getBazelPackagePath(b android.Bazelable) string {
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index ecea6b2..09d536f 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
+ "fmt"
"strings"
"testing"
)
@@ -199,7 +200,8 @@
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, QueryView)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@@ -341,7 +343,8 @@
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("Expected %d bazel target, got %d", expectedCount, actualCount)
@@ -502,7 +505,8 @@
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount {
t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount)
}
@@ -679,59 +683,38 @@
"other/Android.bp": `filegroup {
name: "foo",
srcs: ["a", "b"],
+ bazel_module: { bp2build_available: true },
+}`,
+ },
+ },
+ {
+ description: "depends_on_other_unconverted_module_error",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
+ unconvertedDepsMode: errorModulesUnconvertedDeps,
+ blueprint: `filegroup {
+ name: "foobar",
+ srcs: [
+ ":foo",
+ "c",
+ ],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`),
+ filesystem: map[string]string{
+ "other/Android.bp": `filegroup {
+ name: "foo",
+ srcs: ["a", "b"],
}`,
},
},
}
- dir := "."
for _, testCase := range testCases {
- fs := make(map[string][]byte)
- toParse := []string{
- "Android.bp",
- }
- for f, content := range testCase.filesystem {
- if strings.HasSuffix(f, "Android.bp") {
- toParse = append(toParse, f)
- }
- fs[f] = []byte(content)
- }
- config := android.TestConfig(buildDir, nil, testCase.blueprint, fs)
- ctx := android.NewTestContext(config)
- ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
- ctx.RegisterForBazelConversion()
-
- _, errs := ctx.ParseFileList(dir, toParse)
- if errored(t, testCase, errs) {
- continue
- }
- _, errs = ctx.ResolveDependencies(config)
- if errored(t, testCase, errs) {
- continue
- }
-
- checkDir := dir
- if testCase.dir != "" {
- checkDir = testCase.dir
- }
-
- codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
- if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
- t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
- } else {
- for i, target := range bazelTargets {
- if w, g := testCase.expectedBazelTargets[i], target.content; w != g {
- t.Errorf(
- "%s: Expected generated Bazel target to be '%s', got '%s'",
- testCase.description,
- w,
- g,
- )
- }
- }
- }
+ t.Run(testCase.description, func(t *testing.T) {
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, testCase)
+ })
}
}
@@ -809,7 +792,8 @@
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount := len(bazelTargets); actualCount != testCase.expectedCount {
t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, testCase.expectedCount, actualCount)
}
@@ -921,7 +905,8 @@
// For each directory, test that the expected number of generated targets is correct.
for dir, expectedCount := range testCase.expectedCount {
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount := len(bazelTargets); actualCount != expectedCount {
t.Fatalf(
"%s: Expected %d bazel target for %s package, got %d",
@@ -1064,7 +1049,9 @@
if testCase.dir != "" {
checkDir = testCase.dir
}
- bazelTargets := generateBazelTargetsForDir(NewCodegenContext(config, *ctx.Context, Bp2Build), checkDir)
+ codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir)
+ android.FailIfErrored(t, err)
bazelTargets.sort()
actualCount := len(bazelTargets)
expectedCount := len(testCase.expectedBazelTargets)
@@ -1185,7 +1172,9 @@
if testCase.dir != "" {
checkDir = testCase.dir
}
- bazelTargets := generateBazelTargetsForDir(NewCodegenContext(config, *ctx.Context, Bp2Build), checkDir)
+ codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir)
+ android.FailIfErrored(t, err)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d\n%s", testCase.description, expectedCount, actualCount, bazelTargets)
} else {
diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go
index a991180..f3bc1ba 100644
--- a/bp2build/genrule_conversion_test.go
+++ b/bp2build/genrule_conversion_test.go
@@ -267,7 +267,8 @@
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, checkDir)
+ android.FailIfErrored(t, err)
if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
} else {
@@ -461,7 +462,8 @@
android.FailIfErrored(t, errs)
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
+ bazelTargets, err := generateBazelTargetsForDir(codegenCtx, dir)
+ android.FailIfErrored(t, err)
if actualCount := len(bazelTargets); actualCount != 1 {
t.Fatalf("%s: Expected 1 bazel target, got %d", testCase.description, actualCount)
}
diff --git a/bp2build/metrics.go b/bp2build/metrics.go
index 65b06c6..645ef2d 100644
--- a/bp2build/metrics.go
+++ b/bp2build/metrics.go
@@ -3,6 +3,7 @@
import (
"android/soong/android"
"fmt"
+ "strings"
)
// Simple metrics struct to collect information about a Blueprint to BUILD
@@ -16,6 +17,8 @@
// Total number of handcrafted targets
handCraftedTargetCount int
+
+ moduleWithUnconvertedDepsMsgs []string
}
// Print the codegen metrics to stdout.
@@ -27,8 +30,10 @@
generatedTargetCount += count
}
fmt.Printf(
- "[bp2build] Generated %d total BUILD targets and included %d handcrafted BUILD targets from %d Android.bp modules.\n",
+ "[bp2build] Generated %d total BUILD targets and included %d handcrafted BUILD targets from %d Android.bp modules.\n With %d modules with unconverted deps \n\t%s",
generatedTargetCount,
metrics.handCraftedTargetCount,
- metrics.TotalModuleCount)
+ metrics.TotalModuleCount,
+ len(metrics.moduleWithUnconvertedDepsMsgs),
+ strings.Join(metrics.moduleWithUnconvertedDepsMsgs, "\n\t"))
}
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 3ebe63d..04b8056 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -39,9 +39,8 @@
func checkError(t *testing.T, errs []error, expectedErr error) bool {
t.Helper()
- // expectedErr is not nil, find it in the list of errors
if len(errs) != 1 {
- t.Errorf("Expected only 1 error, got %d: %q", len(errs), errs)
+ return false
}
if errs[0].Error() == expectedErr.Error() {
return true
@@ -83,6 +82,7 @@
filesystem map[string]string
dir string
expectedErr error
+ unconvertedDepsMode unconvertedDepsMode
}
func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) {
@@ -126,7 +126,13 @@
checkDir = tc.dir
}
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
- bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
+ codegenCtx.unconvertedDepMode = tc.unconvertedDepsMode
+ bazelTargets, errs := generateBazelTargetsForDir(codegenCtx, checkDir)
+ if tc.expectedErr != nil && checkError(t, errs, tc.expectedErr) {
+ return
+ } else {
+ android.FailIfErrored(t, errs)
+ }
if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target, got %d; %v",
tc.description, expectedCount, actualCount, bazelTargets)
@@ -316,10 +322,10 @@
}
// Helper method for tests to easily access the targets in a dir.
-func generateBazelTargetsForDir(codegenCtx *CodegenContext, dir string) BazelTargets {
+func generateBazelTargetsForDir(codegenCtx *CodegenContext, dir string) (BazelTargets, []error) {
// TODO: Set generateFilegroups to true and/or remove the generateFilegroups argument completely
- buildFileToTargets, _, _ := GenerateBazelTargets(codegenCtx, false)
- return buildFileToTargets[dir]
+ res, err := GenerateBazelTargets(codegenCtx, false)
+ return res.buildFileToTargets[dir], err
}
func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
diff --git a/cmd/soong_build/queryview.go b/cmd/soong_build/queryview.go
index 98e27c6..d63ded5 100644
--- a/cmd/soong_build/queryview.go
+++ b/cmd/soong_build/queryview.go
@@ -27,12 +27,12 @@
os.RemoveAll(bazelQueryViewDir)
ruleShims := bp2build.CreateRuleShims(android.ModuleTypeFactories())
- // Ignore metrics reporting and compat layers for queryview, since queryview
- // is already a full-repo conversion and can use data from bazel query
- // directly.
- buildToTargets, _, _ := bp2build.GenerateBazelTargets(ctx, true)
+ res, err := bp2build.GenerateBazelTargets(ctx, true)
+ if err != nil {
+ panic(err)
+ }
- filesToWrite := bp2build.CreateBazelFiles(ruleShims, buildToTargets, bp2build.QueryView)
+ filesToWrite := bp2build.CreateBazelFiles(ruleShims, res.BuildDirToTargets(), bp2build.QueryView)
for _, f := range filesToWrite {
if err := writeReadOnlyFile(bazelQueryViewDir, f); err != nil {
return err