Merge "bp2build support .kt in android_library"

This commit is contained in:
Treehugger Robot 2023-01-25 15:47:49 +00:00 committed by Gerrit Code Review
commit 7c30b6bad7
3 changed files with 40 additions and 0 deletions

View file

@ -673,6 +673,9 @@ var (
// kotlin srcs in java binary
"AnalyzerKt",
"trebuchet-core",
// kotlin srcs in android_library
"renderscript_toolkit",
}
Bp2buildModuleTypeAlwaysConvertList = []string{

View file

@ -138,3 +138,36 @@ android_library_import {
},
)
}
func TestConvertAndroidLibraryKotlin(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
Description: "Android Library with .kt srcs and common_srcs attribute",
ModuleTypeUnderTest: "android_library",
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
Filesystem: map[string]string{
"AndroidManifest.xml": "",
},
Blueprint: `
android_library {
name: "TestLib",
srcs: ["a.java", "b.kt"],
common_srcs: ["c.kt"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget(
"android_library",
"TestLib",
AttrNameToString{
"srcs": `[
"a.java",
"b.kt",
]`,
"common_srcs": `["c.kt"]`,
"manifest": `"AndroidManifest.xml"`,
"resource_files": `[]`,
}),
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}})
}

View file

@ -1069,6 +1069,10 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
}
if len(a.properties.Common_srcs) != 0 {
commonAttrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.properties.Common_srcs))
}
name := a.Name()
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_library",