Perform CheckMinSdkVersion for java_sdk_library.

In a follow up, apex would expect that any module that implements
ModuleWithMinSdkVersionCheck to have performed appropate checks on
min_sdk_version, to allow relaxing some of the existing conditions.

This change moves the responsibility of checking min_sdk_version
of java_sdk_library to java_sdk_library itself.

Bug: 205923322
Test: presubmit
Change-Id: I79b5a1fc34098fff60221e416db6e6e69e01f531
This commit is contained in:
satayev
2021-12-06 11:40:46 +00:00
parent ad99149a62
commit 8f088b09d8
2 changed files with 104 additions and 2 deletions

View File

@@ -1129,6 +1129,20 @@ func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext)
return generatedScopes
}
func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) {
android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx).ApiLevel, func(c android.ModuleContext, do android.PayloadDepsCallback) {
ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
isExternal := !module.depIsInSameApex(ctx, child)
if am, ok := child.(android.ApexModule); ok {
if !do(ctx, parent, am, isExternal) {
return false
}
}
return !isExternal
})
})
}
type sdkLibraryComponentTag struct {
blueprint.BaseDependencyTag
name string
@@ -1214,6 +1228,10 @@ func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
}
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if proptools.String(module.deviceProperties.Min_sdk_version) != "" {
module.CheckMinSdkVersion(ctx)
}
module.generateCommonBuildActions(ctx)
// Only build an implementation library if required.
@@ -2605,12 +2623,12 @@ func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleConte
func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
if module.hideApexVariantFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{
return []android.AndroidMkEntries{{
Disabled: true,
}}
}
return []android.AndroidMkEntries{android.AndroidMkEntries{
return []android.AndroidMkEntries{{
Class: "ETC",
OutputFile: android.OptionalPathForPath(module.outputFilePath),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{

View File

@@ -1140,3 +1140,87 @@ func TestJavaSdkLibraryDist(t *testing.T) {
})
}
}
func TestSdkLibrary_CheckMinSdkVersion(t *testing.T) {
preparer := android.GroupFixturePreparers(
PrepareForTestWithJavaBuildComponents,
PrepareForTestWithJavaDefaultModules,
PrepareForTestWithJavaSdkLibraryFiles,
)
preparer.RunTestWithBp(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
static_libs: ["util"],
min_sdk_version: "30",
unsafe_ignore_missing_latest_api: true,
}
java_library {
name: "util",
srcs: ["a.java"],
min_sdk_version: "30",
}
`)
preparer.
RunTestWithBp(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
libs: ["util"],
impl_only_libs: ["util"],
stub_only_libs: ["util"],
stub_only_static_libs: ["util"],
min_sdk_version: "30",
unsafe_ignore_missing_latest_api: true,
}
java_library {
name: "util",
srcs: ["a.java"],
}
`)
preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "util".*should support min_sdk_version\(30\)`)).
RunTestWithBp(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
static_libs: ["util"],
min_sdk_version: "30",
unsafe_ignore_missing_latest_api: true,
}
java_library {
name: "util",
srcs: ["a.java"],
min_sdk_version: "31",
}
`)
preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "another_util".*should support min_sdk_version\(30\)`)).
RunTestWithBp(t, `
java_sdk_library {
name: "sdklib",
srcs: ["a.java"],
static_libs: ["util"],
min_sdk_version: "30",
unsafe_ignore_missing_latest_api: true,
}
java_library {
name: "util",
srcs: ["a.java"],
static_libs: ["another_util"],
min_sdk_version: "30",
}
java_library {
name: "another_util",
srcs: ["a.java"],
min_sdk_version: "31",
}
`)
}