Replace ApiStrToNum uses with ApiLevel.

Test: treehugger
Bug: http://b/154667674
Change-Id: I2954bb21c1cfdeb305f25cfb6c8711c930f6ed50
This commit is contained in:
Dan Albert
2020-07-22 22:32:17 -07:00
parent af6073f78d
commit c8060536e8
17 changed files with 134 additions and 125 deletions

View File

@@ -353,7 +353,7 @@ type ModuleContextIntf interface {
useClangLld(actx ModuleContext) bool
isForPlatform() bool
apexVariationName() string
apexSdkVersion() int
apexSdkVersion() android.ApiLevel
hasStubsVariants() bool
isStubs() bool
bootstrap() bool
@@ -614,7 +614,7 @@ type Module struct {
kytheFiles android.Paths
// For apex variants, this is set as apex.min_sdk_version
apexSdkVersion int
apexSdkVersion android.ApiLevel
}
func (c *Module) Toc() android.OptionalPath {
@@ -1306,7 +1306,7 @@ func (ctx *moduleContextImpl) apexVariationName() string {
return ctx.mod.ApexVariationName()
}
func (ctx *moduleContextImpl) apexSdkVersion() int {
func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
return ctx.mod.apexSdkVersion
}
@@ -2291,16 +2291,16 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
// For the dependency from platform to apex, use the latest stubs
c.apexSdkVersion = android.FutureApiLevel
c.apexSdkVersion = android.CurrentApiLevel
if !c.IsForPlatform() {
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
}
if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
// 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+)).
// (b/144430859)
c.apexSdkVersion = android.FutureApiLevel
c.apexSdkVersion = android.CurrentApiLevel
}
ctx.VisitDirectDeps(func(dep android.Module) {
@@ -2397,7 +2397,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if libDepTag, ok := depTag.(libraryDependencyTag); ok {
// Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
return
}
@@ -2441,7 +2441,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// when to use (unspecified) stubs, check min_sdk_version and choose the right one
if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion.FinalOrFutureInt())
if err != nil {
ctx.OtherModuleErrorf(dep, err.Error())
return
@@ -2464,7 +2464,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// if this is for use_vendor apex && dep has stubsVersions
// apply the same rule of apex sdk enforcement to choose right version
var err error
versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion.FinalOrFutureInt())
if err != nil {
ctx.OtherModuleErrorf(dep, err.Error())
return
@@ -2988,21 +2988,8 @@ func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
return true
}
// b/154667674: refactor this to handle "current" in a consistent way
func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
if versionString == "" {
return 0, fmt.Errorf("not specified")
}
if versionString == "current" {
if ctx.Config().PlatformSdkCodename() == "REL" {
return ctx.Config().PlatformSdkVersionInt(), nil
}
return android.FutureApiLevel, nil
}
return android.ApiStrToNum(ctx, versionString)
}
func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
sdkVersion android.ApiLevel) error {
// We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
return nil
@@ -3026,11 +3013,17 @@ func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersi
// non-SDK variant resets sdk_version, which works too.
minSdkVersion = c.SdkVersion()
}
ver, err := decodeSdkVersionString(ctx, minSdkVersion)
if minSdkVersion == "" {
return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
}
// Not using nativeApiLevelFromUser because the context here is not
// necessarily a native context.
ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
if err != nil {
return err
}
if ver > sdkVersion {
if ver.GreaterThan(sdkVersion) {
return fmt.Errorf("newer SDK(%v)", ver)
}
return nil