Merge "Do not convert android_library_import with no aars." into main

This commit is contained in:
Romain Jobredeaux 2023-09-26 20:08:04 +00:00 committed by Gerrit Code Review
commit 832e131725
2 changed files with 30 additions and 11 deletions

View file

@ -21,6 +21,17 @@ import (
"android/soong/java"
)
func runAndroidLibraryImportTestWithRegistrationCtxFunc(t *testing.T, registrationCtxFunc func(ctx android.RegistrationContext), tc Bp2buildTestCase) {
t.Helper()
(&tc).ModuleTypeUnderTest = "android_library_import"
(&tc).ModuleTypeUnderTestFactory = java.AARImportFactory
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runAndroidLibraryImportTest(t *testing.T, tc Bp2buildTestCase) {
runAndroidLibraryImportTestWithRegistrationCtxFunc(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestConvertAndroidLibrary(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
@ -96,20 +107,12 @@ android_library {
}
func TestConvertAndroidLibraryImport(t *testing.T) {
t.Helper()
RunBp2BuildTestCase(
t,
runAndroidLibraryImportTestWithRegistrationCtxFunc(t,
func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("android_library", java.AndroidLibraryFactory)
},
Bp2buildTestCase{
Description: "Android Library Import",
ModuleTypeUnderTest: "android_library_import",
ModuleTypeUnderTestFactory: java.AARImportFactory,
Filesystem: map[string]string{
"import.aar": "",
"dep.aar": "",
},
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
@ -122,7 +125,6 @@ android_library_import {
sdk_version: "current",
}
// 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"],
@ -220,3 +222,16 @@ android_library {
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
}})
}
func TestAarImportFailsToConvertNoAars(t *testing.T) {
runAndroidLibraryImportTest(t,
Bp2buildTestCase{
Description: "Android Library Import with no aars does not convert.",
Blueprint: `
android_library_import {
name: "no_aar_import",
}
`,
ExpectedBazelTargets: []string{},
})
}

View file

@ -1276,6 +1276,10 @@ func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.Bp2buildMutatorContext)
}
func (a *AARImport) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
if len(a.properties.Aars) == 0 {
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "aars can't be empty")
return
}
aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{})
exportableStaticLibs := []string{}
// TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel.