Merge "Always drop deps from android_library with no srcs" into main am: 2201343fce am: 50225c86b6 am: 965367f3e0 am: 489210e8c4 am: 4230ef999f

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2765453

Change-Id: I852f8ebfdd9974e8ab21c47e85b2a107876bdba3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Zi Wang 2023-09-28 20:44:34 +00:00 committed by Automerger Merge Worker
commit e2929e42a4
2 changed files with 19 additions and 6 deletions

View file

@ -86,7 +86,7 @@ android_library {
func TestConvertAndroidLibraryWithNoSources(t *testing.T) { func TestConvertAndroidLibraryWithNoSources(t *testing.T) {
t.Helper() t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
Description: "Android Library - modules with deps must have sources", Description: "Android Library - modules will deps when there are no sources",
ModuleTypeUnderTest: "android_library", ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory, ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{ Filesystem: map[string]string{
@ -102,7 +102,18 @@ android_library {
sdk_version: "current", sdk_version: "current",
} }
`, `,
ExpectedBazelTargets: []string{}, ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `["res/res.png"]`,
"sdk_version": `"current"`, // use as default
},
),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
},
}) })
} }

View file

@ -1358,10 +1358,12 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext)
if !commonAttrs.Srcs.IsEmpty() { if !commonAttrs.Srcs.IsEmpty() {
deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
} else if !depLabels.Deps.IsEmpty() { } else if !depLabels.Deps.IsEmpty() {
ctx.MarkBp2buildUnconvertible( // android_library does not accept deps when there are no srcs because
bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, // there is no compilation happening, but it accepts exports.
"Module has direct dependencies but no sources. Bazel will not allow this.") // The non-empty deps here are unnecessary as deps on the android_library
return // since they aren't being propagated to any dependencies.
// So we can drop deps here.
deps = bazel.LabelListAttribute{}
} }
name := a.Name() name := a.Name()
props := AndroidLibraryBazelTargetModuleProperties() props := AndroidLibraryBazelTargetModuleProperties()