Replace FutureApiLevel with an ApiLevel.

Keeping the int constant around for now as FutureApiLevelInt because
it's still useful in places that haven't adopted ApiLevel yet for
testing if their non-ApiLevel API level is current or not.

Test: treehugger
Bug: http://b/154667674
Change-Id: I47a7012703f41fdeb56f91edf9c83afa93042deb
This commit is contained in:
Dan Albert
2020-07-23 16:43:25 -07:00
parent c8060536e8
commit 0b176c8038
7 changed files with 19 additions and 19 deletions

View File

@@ -51,7 +51,7 @@ type ApiLevel struct {
func (this ApiLevel) FinalOrFutureInt() int { func (this ApiLevel) FinalOrFutureInt() int {
if this.IsPreview() { if this.IsPreview() {
return FutureApiLevel return FutureApiLevelInt
} else { } else {
return this.number return this.number
} }
@@ -127,13 +127,6 @@ func uncheckedFinalApiLevel(num int) ApiLevel {
} }
} }
// TODO: Merge with FutureApiLevel
var CurrentApiLevel = ApiLevel{
value: "current",
number: 10000,
isPreview: true,
}
var NoneApiLevel = ApiLevel{ var NoneApiLevel = ApiLevel{
value: "(no version)", value: "(no version)",
// Not 0 because we don't want this to compare equal with the first preview. // Not 0 because we don't want this to compare equal with the first preview.
@@ -188,7 +181,7 @@ func ApiLevelFromUser(ctx EarlyModuleContext, raw string) (ApiLevel, error) {
} }
if raw == "current" { if raw == "current" {
return CurrentApiLevel, nil return FutureApiLevel, nil
} }
for _, preview := range ctx.Config().PreviewApiLevels() { for _, preview := range ctx.Config().PreviewApiLevels() {

View File

@@ -37,7 +37,13 @@ var Bool = proptools.Bool
var String = proptools.String var String = proptools.String
var StringDefault = proptools.StringDefault var StringDefault = proptools.StringDefault
const FutureApiLevel = 10000 const FutureApiLevelInt = 10000
var FutureApiLevel = ApiLevel{
value: "current",
number: FutureApiLevelInt,
isPreview: true,
}
// The configuration file name // The configuration file name
const configFileName = "soong.config" const configFileName = "soong.config"
@@ -672,11 +678,12 @@ func (c *config) AllSupportedApiLevels() []ApiLevel {
return append(levels, c.PreviewApiLevels()...) return append(levels, c.PreviewApiLevels()...)
} }
// TODO: Merge this and DefaultAppTargetSdk to just return an ApiLevel.
func (c *config) DefaultAppTargetSdkInt() int { func (c *config) DefaultAppTargetSdkInt() int {
if Bool(c.productVariables.Platform_sdk_final) { if Bool(c.productVariables.Platform_sdk_final) {
return c.PlatformSdkVersionInt() return c.PlatformSdkVersionInt()
} else { } else {
return FutureApiLevel return FutureApiLevelInt
} }
} }

View File

@@ -1955,7 +1955,7 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo
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.CurrentApiLevel return android.FutureApiLevel
} }
apiLevel, err := android.ApiLevelFromUser(ctx, ver) apiLevel, err := android.ApiLevelFromUser(ctx, ver)
if err != nil { if err != nil {
@@ -1964,7 +1964,7 @@ func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) android.ApiLev
} }
if apiLevel.IsPreview() { if apiLevel.IsPreview() {
// All codenames should build against "current". // All codenames should build against "current".
return android.CurrentApiLevel return android.FutureApiLevel
} }
return apiLevel return apiLevel
} }

View File

@@ -2291,7 +2291,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
// For the dependency from platform to apex, use the latest stubs // For the dependency from platform to apex, use the latest stubs
c.apexSdkVersion = android.CurrentApiLevel c.apexSdkVersion = android.FutureApiLevel
if !c.IsForPlatform() { if !c.IsForPlatform() {
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx) c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
} }
@@ -2300,7 +2300,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
// so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
// (b/144430859) // (b/144430859)
c.apexSdkVersion = android.CurrentApiLevel c.apexSdkVersion = android.FutureApiLevel
} }
ctx.VisitDirectDeps(func(dep android.Module) { ctx.VisitDirectDeps(func(dep android.Module) {

View File

@@ -392,7 +392,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
if ctx.Os().Class == android.Device { if ctx.Os().Class == android.Device {
version := ctx.sdkVersion() version := ctx.sdkVersion()
if version == "" || version == "current" { if version == "" || version == "current" {
target += strconv.Itoa(android.FutureApiLevel) target += strconv.Itoa(android.FutureApiLevelInt)
} else { } else {
target += version target += version
} }

View File

@@ -118,8 +118,8 @@ func generatePerApiVariants(ctx android.BottomUpMutatorContext, m *Module,
versionStrs = append(versionStrs, version.String()) versionStrs = append(versionStrs, version.String())
} }
} }
versions = append(versions, android.CurrentApiLevel) versions = append(versions, android.FutureApiLevel)
versionStrs = append(versionStrs, android.CurrentApiLevel.String()) versionStrs = append(versionStrs, android.FutureApiLevel.String())
modules := ctx.CreateVariations(versionStrs...) modules := ctx.CreateVariations(versionStrs...)
for i, module := range modules { for i, module := range modules {

View File

@@ -107,7 +107,7 @@ type sdkVersion int
const ( const (
// special version number for a not-yet-frozen SDK // special version number for a not-yet-frozen SDK
sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevel) sdkVersionCurrent sdkVersion = sdkVersion(android.FutureApiLevelInt)
// special version number to be used for SDK specs where version number doesn't // special version number to be used for SDK specs where version number doesn't
// make sense, e.g. "none", "", etc. // make sense, e.g. "none", "", etc.
sdkVersionNone sdkVersion = sdkVersion(0) sdkVersionNone sdkVersion = sdkVersion(0)