bp2build support .kt in android_library

Bug: 258690851
Test: bp2build tests and built target renderscript_toolkit
Change-Id: I43ddf5637c97e4849b63abd2423f29519d44c28f
This commit is contained in:
Alix 2023-01-20 16:10:52 +00:00
parent 2d0349f133
commit 36795a74dc
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",