SdkSpec is fully using ApiLevel

Previously, SdkSpec was constructed only from the user string. It didn't
make use of the Config struct where information about the latest stable
SDK version, etc. is recorded. As a result, the build system couldn't
check if the sdk version "current" is referring to the in-development
(i.e.  not-yet-frozen) SDK version or the latest stable version.
"current" was always assumed to be in-development (IsPreview() returns
true) even when Platform_sdk_final == true.

As the first step for fixing that, this change requires
android.EarlyModuleContext to be passed when constructing SdkSpec from
the user string.

In the following changes, "current" will be mapped to either
FutureApiLevel (10000) or one of the FinalApiLevels() depending on
whether the platform SDK was finalized or not.

Bug: 175678607
Test: m
Change-Id: Ifea12ebf147ecccf12e7266dd382819806571543
This commit is contained in:
Jiyong Park
2021-04-02 08:45:46 +09:00
parent 481890dbe2
commit dbd710c426
14 changed files with 145 additions and 123 deletions

View File

@@ -22,15 +22,15 @@ import (
type SdkContext interface { type SdkContext interface {
// SdkVersion returns SdkSpec that corresponds to the sdk_version property of the current module // SdkVersion returns SdkSpec that corresponds to the sdk_version property of the current module
SdkVersion() SdkSpec SdkVersion(ctx EarlyModuleContext) SdkSpec
// SystemModules returns the system_modules property of the current module, or an empty string if it is not set. // SystemModules returns the system_modules property of the current module, or an empty string if it is not set.
SystemModules() string SystemModules() string
// MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module, // MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module,
// or from sdk_version if it is not set. // or from sdk_version if it is not set.
MinSdkVersion() SdkSpec MinSdkVersion(ctx EarlyModuleContext) SdkSpec
// TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module, // TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module,
// or from sdk_version if it is not set. // or from sdk_version if it is not set.
TargetSdkVersion() SdkSpec TargetSdkVersion(ctx EarlyModuleContext) SdkSpec
} }
// SdkKind represents a particular category of an SDK spec like public, system, test, etc. // SdkKind represents a particular category of an SDK spec like public, system, test, etc.
@@ -201,15 +201,23 @@ func (s SdkSpec) EffectiveVersionString(ctx EarlyModuleContext) (string, error)
return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil
} }
func SdkSpecFrom(str string) SdkSpec { var (
SdkSpecNone = SdkSpec{SdkNone, NoneApiLevel, "(no version)"}
// TODO(b/175678607) ApiLevel of SdkSpecPrivate should be FutureApiLevel
SdkSpecPrivate = SdkSpec{SdkPrivate, NoneApiLevel, ""}
// TODO(b/175678607) ApiLevel of SdkSpecCorePlatform should be FutureApiLevel
SdkSpecCorePlatform = SdkSpec{SdkCorePlatform, NoneApiLevel, "core_platform"}
)
func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
switch str { switch str {
// special cases first // special cases first
case "": case "":
return SdkSpec{SdkPrivate, NoneApiLevel, str} return SdkSpecPrivate
case "none": case "none":
return SdkSpec{SdkNone, NoneApiLevel, str} return SdkSpecNone
case "core_platform": case "core_platform":
return SdkSpec{SdkCorePlatform, NoneApiLevel, str} return SdkSpecCorePlatform
default: default:
// the syntax is [kind_]version // the syntax is [kind_]version
sep := strings.LastIndex(str, "_") sep := strings.LastIndex(str, "_")
@@ -242,15 +250,10 @@ func SdkSpecFrom(str string) SdkSpec {
return SdkSpec{SdkInvalid, NoneApiLevel, str} return SdkSpec{SdkInvalid, NoneApiLevel, str}
} }
var apiLevel ApiLevel apiLevel, err := ApiLevelFromUser(ctx, versionString)
if versionString == "current" { if err != nil {
apiLevel = FutureApiLevel
} else if i, err := strconv.Atoi(versionString); err == nil {
apiLevel = uncheckedFinalApiLevel(i)
} else {
return SdkSpec{SdkInvalid, apiLevel, str} return SdkSpec{SdkInvalid, apiLevel, str}
} }
return SdkSpec{kind, apiLevel, str} return SdkSpec{kind, apiLevel, str}
} }
} }

View File

@@ -2272,8 +2272,10 @@ func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
tag := ctx.OtherModuleDependencyTag(module) tag := ctx.OtherModuleDependencyTag(module)
switch tag { switch tag {
case javaLibTag, androidAppTag: case javaLibTag, androidAppTag:
if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok { if m, ok := module.(interface {
if err := m.CheckStableSdkVersion(); err != nil { CheckStableSdkVersion(ctx android.BaseModuleContext) error
}); ok {
if err := m.CheckStableSdkVersion(ctx); err != nil {
ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err) ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
} }
} }

View File

@@ -946,16 +946,19 @@ func (a *apexBundle) buildApexDependencyInfo(ctx android.ModuleContext) {
depInfos[to.Name()] = info depInfos[to.Name()] = info
} else { } else {
toMinSdkVersion := "(no version)" toMinSdkVersion := "(no version)"
if m, ok := to.(interface{ MinSdkVersion() string }); ok { if m, ok := to.(interface {
MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
}); ok {
if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() {
toMinSdkVersion = v.ApiLevel.String()
}
} else if m, ok := to.(interface{ MinSdkVersion() string }); ok {
// TODO(b/175678607) eliminate the use of MinSdkVersion returning
// string
if v := m.MinSdkVersion(); v != "" { if v := m.MinSdkVersion(); v != "" {
toMinSdkVersion = v toMinSdkVersion = v
} }
} else if m, ok := to.(interface{ MinSdkVersionString() string }); ok {
if v := m.MinSdkVersionString(); v != "" {
toMinSdkVersion = v
} }
}
depInfos[to.Name()] = android.ApexModuleDepInfo{ depInfos[to.Name()] = android.ApexModuleDepInfo{
To: to.Name(), To: to.Name(),
From: []string{from.Name()}, From: []string{from.Name()},

View File

@@ -218,7 +218,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte
linkDeps = append(linkDeps, assetDeps...) linkDeps = append(linkDeps, assetDeps...)
// SDK version flags // SDK version flags
minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx) minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil { if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err) ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
} }
@@ -609,6 +609,9 @@ type AARImport struct {
hideApexVariantFromMake bool hideApexVariantFromMake bool
aarPath android.Path aarPath android.Path
sdkVersion android.SdkSpec
minSdkVersion android.SdkSpec
} }
var _ android.OutputFileProducer = (*AARImport)(nil) var _ android.OutputFileProducer = (*AARImport)(nil)
@@ -625,23 +628,23 @@ func (a *AARImport) OutputFiles(tag string) (android.Paths, error) {
} }
} }
func (a *AARImport) SdkVersion() android.SdkSpec { func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(String(a.properties.Sdk_version)) return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version))
} }
func (a *AARImport) SystemModules() string { func (a *AARImport) SystemModules() string {
return "" return ""
} }
func (a *AARImport) MinSdkVersion() android.SdkSpec { func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if a.properties.Min_sdk_version != nil { if a.properties.Min_sdk_version != nil {
return android.SdkSpecFrom(*a.properties.Min_sdk_version) return android.SdkSpecFrom(ctx, *a.properties.Min_sdk_version)
} }
return a.SdkVersion() return a.SdkVersion(ctx)
} }
func (a *AARImport) TargetSdkVersion() android.SdkSpec { func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return a.SdkVersion() return a.SdkVersion(ctx)
} }
func (a *AARImport) javaVersion() string { func (a *AARImport) javaVersion() string {
@@ -727,6 +730,9 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return return
} }
a.sdkVersion = a.SdkVersion(ctx)
a.minSdkVersion = a.MinSdkVersion(ctx)
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
aarName := ctx.ModuleName() + ".aar" aarName := ctx.ModuleName() + ".aar"

View File

@@ -51,7 +51,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
if isLibrary { if isLibrary {
args = append(args, "--library") args = append(args, "--library")
} else { } else {
minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersion(ctx) minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersion(ctx)
if err != nil { if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err) ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
} }
@@ -87,7 +87,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
args = append(args, "--logging-parent", loggingParent) args = append(args, "--logging-parent", loggingParent)
} }
var deps android.Paths var deps android.Paths
targetSdkVersion, err := sdkContext.TargetSdkVersion().EffectiveVersionString(ctx) targetSdkVersion, err := sdkContext.TargetSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil { if err != nil {
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err) ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
} }
@@ -96,7 +96,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
deps = append(deps, ApiFingerprintPath(ctx)) deps = append(deps, ApiFingerprintPath(ctx))
} }
minSdkVersion, err := sdkContext.MinSdkVersion().EffectiveVersionString(ctx) minSdkVersion, err := sdkContext.MinSdkVersion(ctx).EffectiveVersionString(ctx)
if err != nil { if err != nil {
ctx.ModuleErrorf("invalid minSdkVersion: %s", err) ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
} }

View File

@@ -106,7 +106,7 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
if len(library.dexpreopter.builtInstalled) > 0 { if len(library.dexpreopter.builtInstalled) > 0 {
entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled) entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", library.dexpreopter.builtInstalled)
} }
entries.SetString("LOCAL_SDK_VERSION", library.SdkVersion().Raw) entries.SetString("LOCAL_SDK_VERSION", library.sdkVersion.String())
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar) entries.SetPath("LOCAL_SOONG_CLASSES_JAR", library.implementationAndResourcesJar)
entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile) entries.SetPath("LOCAL_SOONG_HEADER_JAR", library.headerJarFile)
@@ -205,7 +205,7 @@ func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
} }
entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile) entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.combinedClasspathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile) entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.combinedClasspathFile)
entries.SetString("LOCAL_SDK_VERSION", prebuilt.makeSdkVersion()) entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem()) entries.SetString("LOCAL_MODULE_STEM", prebuilt.Stem())
}, },
}, },
@@ -255,7 +255,7 @@ func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags) entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile) entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest) entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
entries.SetString("LOCAL_SDK_VERSION", prebuilt.SdkVersion().Raw) entries.SetString("LOCAL_SDK_VERSION", prebuilt.sdkVersion.String())
}, },
}, },
}} }}

View File

@@ -213,7 +213,7 @@ func (c Certificate) AndroidMkString() string {
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.Module.deps(ctx) a.Module.deps(ctx)
if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion().Specified() { if String(a.appProperties.Stl) == "c++_shared" && !a.SdkVersion(ctx).Specified() {
ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared") ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
} }
@@ -222,7 +222,7 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
a.aapt.deps(ctx, sdkDep) a.aapt.deps(ctx, sdkDep)
} }
usesSDK := a.SdkVersion().Specified() && a.SdkVersion().Kind != android.SdkCorePlatform usesSDK := a.SdkVersion(ctx).Specified() && a.SdkVersion(ctx).Kind != android.SdkCorePlatform
if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) { if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) {
ctx.PropertyErrorf("jni_uses_sdk_apis", ctx.PropertyErrorf("jni_uses_sdk_apis",
@@ -279,14 +279,14 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
if a.Updatable() { if a.Updatable() {
if !a.SdkVersion().Stable() { if !a.SdkVersion(ctx).Stable() {
ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion()) ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx))
} }
if String(a.deviceProperties.Min_sdk_version) == "" { if String(a.deviceProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.") ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
} }
if minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx); err == nil { if minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx); err == nil {
a.checkJniLibsSdkVersion(ctx, minSdkVersion) a.checkJniLibsSdkVersion(ctx, minSdkVersion)
android.CheckMinSdkVersion(a, ctx, minSdkVersion) android.CheckMinSdkVersion(a, ctx, minSdkVersion)
} else { } else {
@@ -314,7 +314,7 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer
// The domain of cc.sdk_version is "current" and <number> // The domain of cc.sdk_version is "current" and <number>
// We can rely on android.SdkSpec to convert it to <number> so that "current" is // We can rely on android.SdkSpec to convert it to <number> so that "current" is
// handled properly regardless of sdk finalization. // handled properly regardless of sdk finalization.
jniSdkVersion, err := android.SdkSpecFrom(dep.SdkVersion()).EffectiveVersion(ctx) jniSdkVersion, err := android.SdkSpecFrom(ctx, dep.SdkVersion()).EffectiveVersion(ctx)
if err != nil || minSdkVersion.LessThan(jniSdkVersion) { if err != nil || minSdkVersion.LessThan(jniSdkVersion) {
ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)", ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
dep.SdkVersion(), minSdkVersion, ctx.ModuleName()) dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
@@ -327,9 +327,9 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer
// Returns true if the native libraries should be stored in the APK uncompressed and the // Returns true if the native libraries should be stored in the APK uncompressed and the
// extractNativeLibs application flag should be set to false in the manifest. // extractNativeLibs application flag should be set to false in the manifest.
func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool { func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
minSdkVersion, err := a.MinSdkVersion().EffectiveVersion(ctx) minSdkVersion, err := a.MinSdkVersion(ctx).EffectiveVersion(ctx)
if err != nil { if err != nil {
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(), err) ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.MinSdkVersion(ctx), err)
} }
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
@@ -381,7 +381,7 @@ func (a *AndroidApp) renameResourcesPackage() bool {
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis) usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
if ctx.Module().(android.SdkContext).SdkVersion().Kind == android.SdkModule { if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule {
usePlatformAPI = true usePlatformAPI = true
} }
a.aapt.usesNonSdkApis = usePlatformAPI a.aapt.usesNonSdkApis = usePlatformAPI
@@ -724,8 +724,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
} }
type appDepsInterface interface { type appDepsInterface interface {
SdkVersion() android.SdkSpec SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
MinSdkVersion() android.SdkSpec MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
RequiresStableAPIs(ctx android.BaseModuleContext) bool RequiresStableAPIs(ctx android.BaseModuleContext) bool
} }
@@ -738,8 +738,8 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
seenModulePaths := make(map[string]bool) seenModulePaths := make(map[string]bool)
if checkNativeSdkVersion { if checkNativeSdkVersion {
checkNativeSdkVersion = app.SdkVersion().Specified() && checkNativeSdkVersion = app.SdkVersion(ctx).Specified() &&
app.SdkVersion().Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx) app.SdkVersion(ctx).Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx)
} }
ctx.WalkDeps(func(module android.Module, parent android.Module) bool { ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
@@ -829,12 +829,16 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
depsInfo[depName] = info depsInfo[depName] = info
} else { } else {
toMinSdkVersion := "(no version)" toMinSdkVersion := "(no version)"
if m, ok := to.(interface{ MinSdkVersion() string }); ok { if m, ok := to.(interface {
if v := m.MinSdkVersion(); v != "" { MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec
toMinSdkVersion = v }); ok {
if v := m.MinSdkVersion(ctx); !v.ApiLevel.IsNone() {
toMinSdkVersion = v.ApiLevel.String()
} }
} else if m, ok := to.(interface{ MinSdkVersionString() string }); ok { } else if m, ok := to.(interface{ MinSdkVersion() string }); ok {
if v := m.MinSdkVersionString(); v != "" { // TODO(b/175678607) eliminate the use of MinSdkVersion returning
// string
if v := m.MinSdkVersion(); v != "" {
toMinSdkVersion = v toMinSdkVersion = v
} }
} }
@@ -848,7 +852,7 @@ func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
return true return true
}) })
a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersionString(), depsInfo) a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(ctx).String(), depsInfo)
} }
func (a *AndroidApp) Updatable() bool { func (a *AndroidApp) Updatable() bool {

View File

@@ -394,12 +394,12 @@ func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ androi
return false return false
} }
func (a *AndroidAppImport) SdkVersion() android.SdkSpec { func (a *AndroidAppImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom("") return android.SdkSpecPrivate
} }
func (a *AndroidAppImport) MinSdkVersion() android.SdkSpec { func (a *AndroidAppImport) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom("") return android.SdkSpecPrivate
} }
var _ android.ApexModule = (*AndroidAppImport)(nil) var _ android.ApexModule = (*AndroidAppImport)(nil)

View File

@@ -370,10 +370,13 @@ type Module struct {
modulePaths []string modulePaths []string
hideApexVariantFromMake bool hideApexVariantFromMake bool
sdkVersion android.SdkSpec
minSdkVersion android.SdkSpec
} }
func (j *Module) CheckStableSdkVersion() error { func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
sdkVersion := j.SdkVersion() sdkVersion := j.SdkVersion(ctx)
if sdkVersion.Stable() { if sdkVersion.Stable() {
return nil return nil
} }
@@ -393,7 +396,7 @@ func (j *Module) CheckStableSdkVersion() error {
func (j *Module) checkSdkVersions(ctx android.ModuleContext) { func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
if j.RequiresStableAPIs(ctx) { if j.RequiresStableAPIs(ctx) {
if sc, ok := ctx.Module().(android.SdkContext); ok { if sc, ok := ctx.Module().(android.SdkContext); ok {
if !sc.SdkVersion().Specified() { if !sc.SdkVersion(ctx).Specified() {
ctx.PropertyErrorf("sdk_version", ctx.PropertyErrorf("sdk_version",
"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).") "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
} }
@@ -418,7 +421,7 @@ func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
if sc, ok := ctx.Module().(android.SdkContext); ok { if sc, ok := ctx.Module().(android.SdkContext); ok {
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis) usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
sdkVersionSpecified := sc.SdkVersion().Specified() sdkVersionSpecified := sc.SdkVersion(ctx).Specified()
if usePlatformAPI && sdkVersionSpecified { if usePlatformAPI && sdkVersionSpecified {
ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.") ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
} else if !usePlatformAPI && !sdkVersionSpecified { } else if !usePlatformAPI && !sdkVersionSpecified {
@@ -512,30 +515,30 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
return false return false
} }
func (j *Module) SdkVersion() android.SdkSpec { func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(String(j.deviceProperties.Sdk_version)) return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
} }
func (j *Module) SystemModules() string { func (j *Module) SystemModules() string {
return proptools.String(j.deviceProperties.System_modules) return proptools.String(j.deviceProperties.System_modules)
} }
func (j *Module) MinSdkVersion() android.SdkSpec { func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if j.deviceProperties.Min_sdk_version != nil { if j.deviceProperties.Min_sdk_version != nil {
return android.SdkSpecFrom(*j.deviceProperties.Min_sdk_version) return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version)
} }
return j.SdkVersion() return j.SdkVersion(ctx)
}
func (j *Module) TargetSdkVersion() android.SdkSpec {
if j.deviceProperties.Target_sdk_version != nil {
return android.SdkSpecFrom(*j.deviceProperties.Target_sdk_version)
}
return j.SdkVersion()
} }
func (j *Module) MinSdkVersionString() string { func (j *Module) MinSdkVersionString() string {
return j.MinSdkVersion().ApiLevel.String() return j.minSdkVersion.Raw
}
func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if j.deviceProperties.Target_sdk_version != nil {
return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version)
}
return j.SdkVersion(ctx)
} }
func (j *Module) AvailableFor(what string) bool { func (j *Module) AvailableFor(what string) bool {
@@ -1209,7 +1212,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
} }
// Dex compilation // Dex compilation
var dexOutputFile android.OutputPath var dexOutputFile android.OutputPath
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName) dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
if ctx.Failed() { if ctx.Failed() {
return return
} }
@@ -1267,9 +1270,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
j.linter.srcJars = srcJars j.linter.srcJars = srcJars
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...) j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
j.linter.classes = j.implementationJarFile j.linter.classes = j.implementationJarFile
j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion()) j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion(ctx))
j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion()) j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion(ctx))
j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion()) j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion(ctx))
j.linter.javaLanguageLevel = flags.javaVersion.String() j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3" j.linter.kotlinLanguageLevel = "1.3"
if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() { if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
@@ -1471,7 +1474,7 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
// Implements android.ApexModule // Implements android.ApexModule
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error { sdkVersion android.ApiLevel) error {
sdkSpec := j.MinSdkVersion() sdkSpec := j.MinSdkVersion(ctx)
if !sdkSpec.Specified() { if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified") return fmt.Errorf("min_sdk_version is not specified")
} }
@@ -1551,10 +1554,10 @@ func (lt sdkLinkType) rank() int {
type moduleWithSdkDep interface { type moduleWithSdkDep interface {
android.Module android.Module
getSdkLinkType(name string) (ret sdkLinkType, stubs bool) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool)
} }
func (m *Module) getSdkLinkType(name string) (ret sdkLinkType, stubs bool) { func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) {
switch name { switch name {
case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs", case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
"stub-annotations", "private-stub-annotations-jar", "stub-annotations", "private-stub-annotations-jar",
@@ -1576,7 +1579,7 @@ func (m *Module) getSdkLinkType(name string) (ret sdkLinkType, stubs bool) {
return linkType, true return linkType, true
} }
ver := m.SdkVersion() ver := m.SdkVersion(ctx)
switch ver.Kind { switch ver.Kind {
case android.SdkCore: case android.SdkCore:
return javaCore, false return javaCore, false
@@ -1606,11 +1609,11 @@ func (j *Module) checkSdkLinkType(
return return
} }
myLinkType, stubs := j.getSdkLinkType(ctx.ModuleName()) myLinkType, stubs := j.getSdkLinkType(ctx, ctx.ModuleName())
if stubs { if stubs {
return return
} }
depLinkType, _ := dep.getSdkLinkType(ctx.OtherModuleName(dep)) depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep))
if myLinkType.rank() < depLinkType.rank() { if myLinkType.rank() < depLinkType.rank() {
ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+ ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
@@ -1638,7 +1641,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
} }
} }
sdkLinkType, _ := j.getSdkLinkType(ctx.ModuleName()) sdkLinkType, _ := j.getSdkLinkType(ctx, ctx.ModuleName())
ctx.VisitDirectDeps(func(module android.Module) { ctx.VisitDirectDeps(func(module android.Module) {
otherName := ctx.OtherModuleName(module) otherName := ctx.OtherModuleName(module)
@@ -1656,7 +1659,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
if dep, ok := module.(SdkLibraryDependency); ok { if dep, ok := module.(SdkLibraryDependency); ok {
switch tag { switch tag {
case libTag: case libTag:
deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...) deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
case staticLibTag: case staticLibTag:
ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
} }

View File

@@ -261,20 +261,20 @@ func JavadocHostFactory() android.Module {
var _ android.OutputFileProducer = (*Javadoc)(nil) var _ android.OutputFileProducer = (*Javadoc)(nil)
func (j *Javadoc) SdkVersion() android.SdkSpec { func (j *Javadoc) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(String(j.properties.Sdk_version)) return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
} }
func (j *Javadoc) SystemModules() string { func (j *Javadoc) SystemModules() string {
return proptools.String(j.properties.System_modules) return proptools.String(j.properties.System_modules)
} }
func (j *Javadoc) MinSdkVersion() android.SdkSpec { func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion() return j.SdkVersion(ctx)
} }
func (j *Javadoc) TargetSdkVersion() android.SdkSpec { func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion() return j.SdkVersion(ctx)
} }
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
@@ -386,7 +386,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
} }
case libTag: case libTag:
if dep, ok := module.(SdkLibraryDependency); ok { if dep, ok := module.(SdkLibraryDependency); ok {
deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...) deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
} else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
deps.classpath = append(deps.classpath, dep.HeaderJars...) deps.classpath = append(deps.classpath, dep.HeaderJars...)

View File

@@ -356,7 +356,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an
if javaVersion != "" { if javaVersion != "" {
return normalizeJavaVersion(ctx, javaVersion) return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() { } else if ctx.Device() {
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion()) return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
} else { } else {
return JAVA_VERSION_9 return JAVA_VERSION_9
} }
@@ -463,6 +463,9 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// would the <x> library if <x> was configured as a boot jar. // would the <x> library if <x> was configured as a boot jar.
j.initHiddenAPI(ctx, j.ConfigurationName()) j.initHiddenAPI(ctx, j.ConfigurationName())
j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx)
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() { if !apexInfo.IsForPlatform() {
j.hideApexVariantFromMake = true j.hideApexVariantFromMake = true
@@ -1130,33 +1133,28 @@ type Import struct {
exportAidlIncludeDirs android.Paths exportAidlIncludeDirs android.Paths
hideApexVariantFromMake bool hideApexVariantFromMake bool
sdkVersion android.SdkSpec
minSdkVersion android.SdkSpec
} }
func (j *Import) SdkVersion() android.SdkSpec { func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(String(j.properties.Sdk_version)) return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
}
func (j *Import) makeSdkVersion() string {
return j.SdkVersion().Raw
} }
func (j *Import) SystemModules() string { func (j *Import) SystemModules() string {
return "none" return "none"
} }
func (j *Import) MinSdkVersion() android.SdkSpec { func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if j.properties.Min_sdk_version != nil { if j.properties.Min_sdk_version != nil {
return android.SdkSpecFrom(*j.properties.Min_sdk_version) return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version)
} }
return j.SdkVersion() return j.SdkVersion(ctx)
} }
func (j *Import) TargetSdkVersion() android.SdkSpec { func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion() return j.SdkVersion(ctx)
}
func (j *Import) MinSdkVersionString() string {
return j.MinSdkVersion().ApiLevel.String()
} }
func (j *Import) Prebuilt() *android.Prebuilt { func (j *Import) Prebuilt() *android.Prebuilt {
@@ -1192,6 +1190,9 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
} }
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx)
// Initialize the hiddenapi structure. // Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, j.BaseModuleName()) j.initHiddenAPI(ctx, j.BaseModuleName())
@@ -1230,7 +1231,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else if dep, ok := module.(SdkLibraryDependency); ok { } else if dep, ok := module.(SdkLibraryDependency); ok {
switch tag { switch tag {
case libTag: case libTag:
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...) flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
} }
} }
@@ -1291,7 +1292,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
var dexOutputFile android.OutputPath var dexOutputFile android.OutputPath
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName) dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
if ctx.Failed() { if ctx.Failed() {
return return
} }
@@ -1359,7 +1360,7 @@ func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
// Implements android.ApexModule // Implements android.ApexModule
func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error { sdkVersion android.ApiLevel) error {
sdkSpec := j.MinSdkVersion() sdkSpec := j.MinSdkVersion(ctx)
if !sdkSpec.Specified() { if !sdkSpec.Specified() {
return fmt.Errorf("min_sdk_version is not specified") return fmt.Errorf("min_sdk_version is not specified")
} }

View File

@@ -141,23 +141,23 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC
ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile) ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
} }
func (r *RuntimeResourceOverlay) SdkVersion() android.SdkSpec { func (r *RuntimeResourceOverlay) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return android.SdkSpecFrom(String(r.properties.Sdk_version)) return android.SdkSpecFrom(ctx, String(r.properties.Sdk_version))
} }
func (r *RuntimeResourceOverlay) SystemModules() string { func (r *RuntimeResourceOverlay) SystemModules() string {
return "" return ""
} }
func (r *RuntimeResourceOverlay) MinSdkVersion() android.SdkSpec { func (r *RuntimeResourceOverlay) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
if r.properties.Min_sdk_version != nil { if r.properties.Min_sdk_version != nil {
return android.SdkSpecFrom(*r.properties.Min_sdk_version) return android.SdkSpecFrom(ctx, *r.properties.Min_sdk_version)
} }
return r.SdkVersion() return r.SdkVersion(ctx)
} }
func (r *RuntimeResourceOverlay) TargetSdkVersion() android.SdkSpec { func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return r.SdkVersion() return r.SdkVersion(ctx)
} }
func (r *RuntimeResourceOverlay) Certificate() Certificate { func (r *RuntimeResourceOverlay) Certificate() Certificate {

View File

@@ -61,7 +61,7 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe
} }
func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep { func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) sdkDep {
sdkVersion := sdkContext.SdkVersion() sdkVersion := sdkContext.SdkVersion(ctx)
if !sdkVersion.Valid() { if !sdkVersion.Valid() {
ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw) ctx.PropertyErrorf("sdk_version", "invalid version %q", sdkVersion.Raw)
return sdkDep{} return sdkDep{}

View File

@@ -1512,7 +1512,7 @@ func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion andr
// force override sdk_version to module_current so that the closest possible API // force override sdk_version to module_current so that the closest possible API
// surface could be found in selectHeaderJarsForSdkVersion // surface could be found in selectHeaderJarsForSdkVersion
if module.defaultsToStubs() && !sdkVersion.Specified() { if module.defaultsToStubs() && !sdkVersion.Specified() {
sdkVersion = android.SdkSpecFrom("module_current") sdkVersion = android.SdkSpecFrom(ctx, "module_current")
} }
// Only provide access to the implementation library if it is actually built. // Only provide access to the implementation library if it is actually built.