Loading android/bazel.go +14 −8 Original line number Diff line number Diff line Loading @@ -604,13 +604,6 @@ func registerBp2buildConversionMutator(ctx RegisterMutatorsContext) { } func bp2buildConversionMutator(ctx TopDownMutatorContext) { if ctx.Config().HasBazelBuildTargetInSource(ctx) { // Defer to the BUILD target. Generating an additional target would // cause a BUILD file conflict. ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, "") return } bModule, ok := ctx.Module().(Bazelable) if !ok { ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") Loading @@ -634,11 +627,24 @@ func bp2buildConversionMutator(ctx TopDownMutatorContext) { ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "") return } if ctx.Module().base().GetUnconvertedReason() != nil { return } bModule.ConvertWithBp2build(ctx) if !ctx.Module().base().IsConvertedByBp2build() && ctx.Module().base().GetUnconvertedReason() == nil { if len(ctx.Module().base().Bp2buildTargets()) == 0 && ctx.Module().base().GetUnconvertedReason() == nil { panic(fmt.Errorf("illegal bp2build invariant: module '%s' was neither converted nor marked unconvertible", ctx.ModuleName())) } for _, targetInfo := range ctx.Module().base().Bp2buildTargets() { if ctx.Config().HasBazelBuildTargetInSource(targetInfo.TargetPackage(), targetInfo.TargetName()) { // Defer to the BUILD target. Generating an additional target would // cause a BUILD file conflict. ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, targetInfo.TargetName()) return } } } func registerApiBp2buildConversionMutator(ctx RegisterMutatorsContext) { Loading android/config.go +3 −4 Original line number Diff line number Diff line Loading @@ -2022,10 +2022,9 @@ func (c *config) LogMixedBuild(ctx BaseModuleContext, useBazel bool) { } } func (c *config) HasBazelBuildTargetInSource(ctx BaseModuleContext) bool { moduleName := ctx.Module().Name() for _, buildTarget := range c.bazelTargetsByDir[ctx.ModuleDir()] { if moduleName == buildTarget { func (c *config) HasBazelBuildTargetInSource(dir string, target string) bool { for _, existingTarget := range c.bazelTargetsByDir[dir] { if target == existingTarget { return true } } Loading android/module.go +2 −21 Original line number Diff line number Diff line Loading @@ -565,8 +565,8 @@ type Module interface { AddProperties(props ...interface{}) GetProperties() []interface{} // IsConvertedByBp2build returns whether this module was converted via bp2build IsConvertedByBp2build() bool // If this module should not have bazel BUILD definitions generated by bp2build, // GetUnconvertedReason returns a reason this is the case. GetUnconvertedReason() *UnconvertedReason // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module Loading Loading @@ -1639,35 +1639,16 @@ func (b bp2buildInfo) BazelAttributes() []interface{} { } func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { reason := m.commonProperties.BazelConversionStatus.UnconvertedReason if reason != nil { panic(fmt.Errorf("bp2build: internal error trying to convert module '%s' marked unconvertible. Reason type %d: %s", m.Name(), reason.ReasonType, reason.Detail)) } m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info) } func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) { if len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 { fmt.Println(m.commonProperties.BazelConversionStatus.Bp2buildInfo) panic(fmt.Errorf("bp2build: internal error trying to mark converted module '%s' as unconvertible. Reason type %d: %s", m.Name(), reasonType, detail)) } m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{ ReasonType: int(reasonType), Detail: detail, } } // IsConvertedByBp2build returns whether this module was converted via bp2build. func (m *ModuleBase) IsConvertedByBp2build() bool { return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 } func (m *ModuleBase) GetUnconvertedReason() *UnconvertedReason { return m.commonProperties.BazelConversionStatus.UnconvertedReason } Loading bp2build/aar_conversion_test.go +2 −1 Original line number Diff line number Diff line Loading @@ -110,7 +110,7 @@ func TestConvertAndroidLibraryImport(t *testing.T) { "import.aar": "", "dep.aar": "", }, StubbedBuildDefinitions: []string{"static_lib_dep", "prebuilt_static_import_dep"}, StubbedBuildDefinitions: []string{"static_lib_dep", "static_import_dep", "static_import_dep-neverlink"}, // Bazel's aar_import can only export *_import targets, so we expect // only "static_import_dep" in exports, but both "static_lib_dep" and // "static_import_dep" in deps Loading @@ -125,6 +125,7 @@ android_library_import { // TODO: b/301007952 - This dep is needed because android_library_import must have aars set. android_library_import { name: "static_import_dep", aars: ["import.aar"], } `, ExpectedBazelTargets: []string{ Loading bp2build/apex_conversion_test.go +3 −3 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ filegroup { } cc_binary { name: "cc_binary_1"} sh_binary { name: "sh_binary_2"} sh_binary { name: "sh_binary_2", src: "foo.sh"} apex { name: "com.android.apogee", Loading Loading @@ -609,7 +609,7 @@ filegroup { } cc_binary { name: "cc_binary_1" } sh_binary { name: "sh_binary_2" } sh_binary { name: "sh_binary_2", src: "foo.sh"} apex { name: "com.android.apogee", Loading Loading @@ -736,7 +736,7 @@ filegroup { } cc_binary { name: "cc_binary_1"} sh_binary { name: "sh_binary_2"} sh_binary { name: "sh_binary_2", src: "foo.sh"} apex_test { name: "com.android.apogee", Loading Loading
android/bazel.go +14 −8 Original line number Diff line number Diff line Loading @@ -604,13 +604,6 @@ func registerBp2buildConversionMutator(ctx RegisterMutatorsContext) { } func bp2buildConversionMutator(ctx TopDownMutatorContext) { if ctx.Config().HasBazelBuildTargetInSource(ctx) { // Defer to the BUILD target. Generating an additional target would // cause a BUILD file conflict. ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, "") return } bModule, ok := ctx.Module().(Bazelable) if !ok { ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") Loading @@ -634,11 +627,24 @@ func bp2buildConversionMutator(ctx TopDownMutatorContext) { ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "") return } if ctx.Module().base().GetUnconvertedReason() != nil { return } bModule.ConvertWithBp2build(ctx) if !ctx.Module().base().IsConvertedByBp2build() && ctx.Module().base().GetUnconvertedReason() == nil { if len(ctx.Module().base().Bp2buildTargets()) == 0 && ctx.Module().base().GetUnconvertedReason() == nil { panic(fmt.Errorf("illegal bp2build invariant: module '%s' was neither converted nor marked unconvertible", ctx.ModuleName())) } for _, targetInfo := range ctx.Module().base().Bp2buildTargets() { if ctx.Config().HasBazelBuildTargetInSource(targetInfo.TargetPackage(), targetInfo.TargetName()) { // Defer to the BUILD target. Generating an additional target would // cause a BUILD file conflict. ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, targetInfo.TargetName()) return } } } func registerApiBp2buildConversionMutator(ctx RegisterMutatorsContext) { Loading
android/config.go +3 −4 Original line number Diff line number Diff line Loading @@ -2022,10 +2022,9 @@ func (c *config) LogMixedBuild(ctx BaseModuleContext, useBazel bool) { } } func (c *config) HasBazelBuildTargetInSource(ctx BaseModuleContext) bool { moduleName := ctx.Module().Name() for _, buildTarget := range c.bazelTargetsByDir[ctx.ModuleDir()] { if moduleName == buildTarget { func (c *config) HasBazelBuildTargetInSource(dir string, target string) bool { for _, existingTarget := range c.bazelTargetsByDir[dir] { if target == existingTarget { return true } } Loading
android/module.go +2 −21 Original line number Diff line number Diff line Loading @@ -565,8 +565,8 @@ type Module interface { AddProperties(props ...interface{}) GetProperties() []interface{} // IsConvertedByBp2build returns whether this module was converted via bp2build IsConvertedByBp2build() bool // If this module should not have bazel BUILD definitions generated by bp2build, // GetUnconvertedReason returns a reason this is the case. GetUnconvertedReason() *UnconvertedReason // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module Loading Loading @@ -1639,35 +1639,16 @@ func (b bp2buildInfo) BazelAttributes() []interface{} { } func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { reason := m.commonProperties.BazelConversionStatus.UnconvertedReason if reason != nil { panic(fmt.Errorf("bp2build: internal error trying to convert module '%s' marked unconvertible. Reason type %d: %s", m.Name(), reason.ReasonType, reason.Detail)) } m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info) } func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) { if len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 { fmt.Println(m.commonProperties.BazelConversionStatus.Bp2buildInfo) panic(fmt.Errorf("bp2build: internal error trying to mark converted module '%s' as unconvertible. Reason type %d: %s", m.Name(), reasonType, detail)) } m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{ ReasonType: int(reasonType), Detail: detail, } } // IsConvertedByBp2build returns whether this module was converted via bp2build. func (m *ModuleBase) IsConvertedByBp2build() bool { return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 } func (m *ModuleBase) GetUnconvertedReason() *UnconvertedReason { return m.commonProperties.BazelConversionStatus.UnconvertedReason } Loading
bp2build/aar_conversion_test.go +2 −1 Original line number Diff line number Diff line Loading @@ -110,7 +110,7 @@ func TestConvertAndroidLibraryImport(t *testing.T) { "import.aar": "", "dep.aar": "", }, StubbedBuildDefinitions: []string{"static_lib_dep", "prebuilt_static_import_dep"}, StubbedBuildDefinitions: []string{"static_lib_dep", "static_import_dep", "static_import_dep-neverlink"}, // Bazel's aar_import can only export *_import targets, so we expect // only "static_import_dep" in exports, but both "static_lib_dep" and // "static_import_dep" in deps Loading @@ -125,6 +125,7 @@ android_library_import { // TODO: b/301007952 - This dep is needed because android_library_import must have aars set. android_library_import { name: "static_import_dep", aars: ["import.aar"], } `, ExpectedBazelTargets: []string{ Loading
bp2build/apex_conversion_test.go +3 −3 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ filegroup { } cc_binary { name: "cc_binary_1"} sh_binary { name: "sh_binary_2"} sh_binary { name: "sh_binary_2", src: "foo.sh"} apex { name: "com.android.apogee", Loading Loading @@ -609,7 +609,7 @@ filegroup { } cc_binary { name: "cc_binary_1" } sh_binary { name: "sh_binary_2" } sh_binary { name: "sh_binary_2", src: "foo.sh"} apex { name: "com.android.apogee", Loading Loading @@ -736,7 +736,7 @@ filegroup { } cc_binary { name: "cc_binary_1"} sh_binary { name: "sh_binary_2"} sh_binary { name: "sh_binary_2", src: "foo.sh"} apex_test { name: "com.android.apogee", Loading