apex: checks min_sdk_version for preview/current

If we don't check "current", it won't be checked even in the finalized
branch.

If we don't check "preview", it should be done during the SDK
finalization. It'd be better done before the SDK finalization regarding
that setting min_sdk_version is to get approval from deps library owners.

Bug: 177833148
Test: m (soong tests)
Change-Id: I712b61cfe5a134fbb69c73956d26fb3a1e5c011e
This commit is contained in:
Jooyung Han
2021-01-26 11:43:46 +09:00
parent 700730e69e
commit ed124c308f
5 changed files with 83 additions and 10 deletions

View File

@@ -830,9 +830,8 @@ func CheckMinSdkVersion(m UpdatableModule, ctx ModuleContext, minSdkVersion ApiL
return return
} }
// do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version or // do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version
// min_sdk_version is not finalized (e.g. current or codenames) if minSdkVersion.IsNone() {
if minSdkVersion.IsCurrent() {
return return
} }

View File

@@ -81,6 +81,10 @@ func (this ApiLevel) IsCurrent() bool {
return this.value == "current" return this.value == "current"
} }
func (this ApiLevel) IsNone() bool {
return this.number == -1
}
// Returns -1 if the current API level is less than the argument, 0 if they // Returns -1 if the current API level is less than the argument, 0 if they
// are equal, and 1 if it is greater than the argument. // are equal, and 1 if it is greater than the argument.
func (this ApiLevel) CompareTo(other ApiLevel) int { func (this ApiLevel) CompareTo(other ApiLevel) int {

View File

@@ -854,11 +854,17 @@ func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Contents: apexContents, Contents: apexContents,
}) })
minSdkVersion := a.minSdkVersion(mctx)
// When min_sdk_version is not set, the apex is built against FutureApiLevel.
if minSdkVersion.IsNone() {
minSdkVersion = android.FutureApiLevel
}
// This is the main part of this mutator. Mark the collected dependencies that they need to // This is the main part of this mutator. Mark the collected dependencies that they need to
// be built for this apexBundle. // be built for this apexBundle.
apexInfo := android.ApexInfo{ apexInfo := android.ApexInfo{
ApexVariationName: mctx.ModuleName(), ApexVariationName: mctx.ModuleName(),
MinSdkVersionStr: a.minSdkVersion(mctx).String(), MinSdkVersionStr: minSdkVersion.String(),
RequiredSdks: a.RequiredSdks(), RequiredSdks: a.RequiredSdks(),
Updatable: a.Updatable(), Updatable: a.Updatable(),
InApexes: []string{mctx.ModuleName()}, InApexes: []string{mctx.ModuleName()},
@@ -2116,17 +2122,13 @@ func (a *apexBundle) checkMinSdkVersion(ctx android.ModuleContext) {
func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel { func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLevel {
ver := proptools.String(a.properties.Min_sdk_version) ver := proptools.String(a.properties.Min_sdk_version)
if ver == "" { if ver == "" {
return android.FutureApiLevel return android.NoneApiLevel
} }
apiLevel, err := android.ApiLevelFromUser(ctx, ver) apiLevel, err := android.ApiLevelFromUser(ctx, ver)
if err != nil { if err != nil {
ctx.PropertyErrorf("min_sdk_version", "%s", err.Error()) ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
return android.NoneApiLevel return android.NoneApiLevel
} }
if apiLevel.IsPreview() {
// All codenames should build against "current".
return android.FutureApiLevel
}
return apiLevel return apiLevel
} }

View File

@@ -2135,6 +2135,74 @@ func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion
expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30")
} }
func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) {
withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) {
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S")
config.TestProductVariables.Platform_version_active_codenames = []string{"S"}
}
testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, `
apex {
name: "myapex",
key: "myapex.key",
native_shared_libs: ["libfoo"],
min_sdk_version: "S",
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "libfoo",
shared_libs: ["libbar"],
apex_available: ["myapex"],
min_sdk_version: "29",
}
cc_library {
name: "libbar",
apex_available: ["myapex"],
}
`, withSAsActiveCodeNames)
}
func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) {
withSAsActiveCodeNames := func(fs map[string][]byte, config android.Config) {
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("S")
config.TestProductVariables.Platform_version_active_codenames = []string{"S", "T"}
}
ctx, _ := testApex(t, `
apex {
name: "myapex",
key: "myapex.key",
native_shared_libs: ["libfoo"],
min_sdk_version: "S",
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "libfoo",
shared_libs: ["libbar"],
apex_available: ["myapex"],
min_sdk_version: "S",
}
cc_library {
name: "libbar",
stubs: {
symbol_file: "libbar.map.txt",
versions: ["30", "S", "T"],
},
}
`, withSAsActiveCodeNames)
// ensure libfoo is linked with "S" version of libbar stub
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000")
libFlags := libfoo.Rule("ld").Args["libFlags"]
ensureContains(t, libFlags, "android_arm64_armv8-a_shared_S/libbar.so")
}
func TestFilesInSubDir(t *testing.T) { func TestFilesInSubDir(t *testing.T) {
ctx, _ := testApex(t, ` ctx, _ := testApex(t, `
apex { apex {

View File

@@ -598,7 +598,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
// bundletool doesn't understand what "current" is. We need to transform it to // bundletool doesn't understand what "current" is. We need to transform it to
// codename // codename
if moduleMinSdkVersion.IsCurrent() { if moduleMinSdkVersion.IsCurrent() || moduleMinSdkVersion.IsNone() {
minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String() minSdkVersion = ctx.Config().DefaultAppTargetSdk(ctx).String()
} }
// apex module doesn't have a concept of target_sdk_version, hence for the time // apex module doesn't have a concept of target_sdk_version, hence for the time