libs support for android_app->* edge

Test: bp2build tests
Bug: 258688914
Change-Id: I2e24c484019c994b43509f350b3c090a40c3ba6a
This commit is contained in:
Alix
2023-01-05 21:12:31 +00:00
parent ed2491cf20
commit 6c087cf01a
2 changed files with 30 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ func runAndroidAppTestCase(t *testing.T, tc Bp2buildTestCase) {
func registerAndroidAppModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
}
func TestMinimalAndroidApp(t *testing.T) {
@@ -200,3 +201,29 @@ android_app {
}),
}})
}
func TestAndroidAppLibs(t *testing.T) {
runAndroidAppTestCase(t, Bp2buildTestCase{
Description: "Android app with libs",
ModuleTypeUnderTest: "android_app",
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
Filesystem: map[string]string{},
Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
android_app {
name: "foo",
libs: ["barLib"]
}
java_library{
name: "barLib",
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "barLib", AttrNameToString{}),
MakeNeverlinkDuplicateTarget("java_library", "barLib"),
MakeBazelTarget("android_binary", "foo", AttrNameToString{
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
"deps": `[":barLib-neverlink"]`,
}),
}})
}

View File

@@ -2676,7 +2676,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
if m.properties.Libs != nil {
// TODO 244210934 ALIX Check if this else statement breaks presubmits get rid of it if it doesn't
if strings.HasPrefix(ctx.ModuleType(), "java_binary") || strings.HasPrefix(ctx.ModuleType(), "java_library") || ctx.ModuleType() == "android_library" {
modType := ctx.ModuleType()
if strings.HasPrefix(modType, "java_binary") || strings.HasPrefix(modType, "java_library") || modType == "android_app" || modType == "android_library" {
for _, d := range m.properties.Libs {
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"