Merge changes from topics "soong-apilevel", "soong-config-apilevel"
* changes: Convert more versions in config to ApiLevel. Replace FutureApiLevel with an ApiLevel. Replace ApiStrToNum uses with ApiLevel.
This commit is contained in:
41
cc/cc.go
41
cc/cc.go
@@ -354,7 +354,7 @@ type ModuleContextIntf interface {
|
||||
useClangLld(actx ModuleContext) bool
|
||||
isForPlatform() bool
|
||||
apexVariationName() string
|
||||
apexSdkVersion() int
|
||||
apexSdkVersion() android.ApiLevel
|
||||
hasStubsVariants() bool
|
||||
isStubs() bool
|
||||
bootstrap() bool
|
||||
@@ -615,7 +615,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 {
|
||||
@@ -1328,7 +1328,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
|
||||
}
|
||||
|
||||
@@ -2317,7 +2317,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
// For the dependency from platform to apex, use the latest stubs
|
||||
c.apexSdkVersion = android.FutureApiLevel
|
||||
if !c.IsForPlatform() {
|
||||
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
|
||||
c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
|
||||
}
|
||||
|
||||
if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
|
||||
@@ -2421,7 +2421,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
|
||||
}
|
||||
|
||||
@@ -2465,7 +2465,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
|
||||
@@ -2488,7 +2488,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
|
||||
@@ -3012,21 +3012,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
|
||||
@@ -3050,11 +3037,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
|
||||
|
||||
@@ -354,7 +354,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_NAME__='\""+ctx.apexVariationName()+"\"'")
|
||||
}
|
||||
if ctx.Device() {
|
||||
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_SDK_VERSION__="+strconv.Itoa(ctx.apexSdkVersion()))
|
||||
flags.Global.CommonFlags = append(flags.Global.CommonFlags,
|
||||
fmt.Sprintf("-D__ANDROID_SDK_VERSION__=%d",
|
||||
ctx.apexSdkVersion().FinalOrFutureInt()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +392,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||
if ctx.Os().Class == android.Device {
|
||||
version := ctx.sdkVersion()
|
||||
if version == "" || version == "current" {
|
||||
target += strconv.Itoa(android.FutureApiLevel)
|
||||
target += strconv.Itoa(android.FutureApiLevelInt)
|
||||
} else {
|
||||
target += version
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -1520,20 +1518,18 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
func normalizeVersions(ctx android.BaseModuleContext, versions []string) {
|
||||
numVersions := make([]int, len(versions))
|
||||
var previous android.ApiLevel
|
||||
for i, v := range versions {
|
||||
numVer, err := android.ApiStrToNum(ctx, v)
|
||||
ver, err := android.ApiLevelFromUser(ctx, v)
|
||||
if err != nil {
|
||||
ctx.PropertyErrorf("versions", "%s", err.Error())
|
||||
return
|
||||
}
|
||||
numVersions[i] = numVer
|
||||
}
|
||||
if !sort.IsSorted(sort.IntSlice(numVersions)) {
|
||||
ctx.PropertyErrorf("versions", "not sorted: %v", versions)
|
||||
}
|
||||
for i, v := range numVersions {
|
||||
versions[i] = strconv.Itoa(v)
|
||||
if i > 0 && ver.LessThanOrEqualTo(previous) {
|
||||
ctx.PropertyErrorf("versions", "not sorted: %v", versions)
|
||||
}
|
||||
versions[i] = ver.String()
|
||||
previous = ver
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ func TestStubsVersions(t *testing.T) {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
stubs: {
|
||||
versions: ["29", "R", "10000"],
|
||||
versions: ["29", "R", "current"],
|
||||
},
|
||||
}
|
||||
`
|
||||
@@ -204,7 +204,7 @@ func TestStubsVersions(t *testing.T) {
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
variants := ctx.ModuleVariantsForTests("libfoo")
|
||||
for _, expectedVer := range []string{"29", "9000", "10000"} {
|
||||
for _, expectedVer := range []string{"29", "R", "current"} {
|
||||
expectedVariant := "android_arm_armv7-a-neon_shared_" + expectedVer
|
||||
if !inList(expectedVariant, variants) {
|
||||
t.Errorf("missing expected variant: %q", expectedVariant)
|
||||
@@ -218,7 +218,7 @@ func TestStubsVersions_NotSorted(t *testing.T) {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
stubs: {
|
||||
versions: ["29", "10000", "R"],
|
||||
versions: ["29", "current", "R"],
|
||||
},
|
||||
}
|
||||
`
|
||||
@@ -233,10 +233,10 @@ func TestStubsVersions_ParseError(t *testing.T) {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
stubs: {
|
||||
versions: ["29", "10000", "X"],
|
||||
versions: ["29", "current", "X"],
|
||||
},
|
||||
}
|
||||
`
|
||||
|
||||
testCcError(t, `"libfoo" .*: versions: SDK version should be`, bp)
|
||||
testCcError(t, `"libfoo" .*: versions: "X" could not be parsed as an integer and is not a recognized codename`, bp)
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ func generatePerApiVariants(ctx android.BottomUpMutatorContext, m *Module,
|
||||
versionStrs = append(versionStrs, version.String())
|
||||
}
|
||||
}
|
||||
versions = append(versions, android.CurrentApiLevel)
|
||||
versionStrs = append(versionStrs, android.CurrentApiLevel.String())
|
||||
versions = append(versions, android.FutureApiLevel)
|
||||
versionStrs = append(versionStrs, android.FutureApiLevel.String())
|
||||
|
||||
modules := ctx.CreateVariations(versionStrs...)
|
||||
for i, module := range modules {
|
||||
|
||||
Reference in New Issue
Block a user