diff options
author | 2020-04-02 01:41:41 +0900 | |
---|---|---|
committer | 2020-04-09 16:04:17 +0900 | |
commit | aed150d6ed0cd652ee765487f8ab77c8883d5fcc (patch) | |
tree | 0f981c294fb2c5949145548360e211d6b454fbbd /cc | |
parent | b54015fa544b5ab2a2a319b95a9d3e384c259210 (diff) |
Apex: support codenames for min_sdk_version
Apex can use codenames like "Q", "R" for its min_sdk_version property.
Also, cc_library can use codenames for its stubs.versions.
Bug: 152655956
Test: m
Merged-In: I077ad7b2ac5d90b4c8708921e43846206f05ba70
Change-Id: I077ad7b2ac5d90b4c8708921e43846206f05ba70
(cherry picked from commit 29e91d21219485f0bc675c4d6034b5726be4ca92)
Diffstat (limited to 'cc')
-rw-r--r-- | cc/library.go | 12 | ||||
-rw-r--r-- | cc/library_test.go | 54 | ||||
-rw-r--r-- | cc/ndk_library.go | 2 |
3 files changed, 64 insertions, 4 deletions
diff --git a/cc/library.go b/cc/library.go index 140f87a0a..2395f0712 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1489,18 +1489,22 @@ func LatestStubsVersionFor(config android.Config, name string) string { return "" } -func checkVersions(ctx android.BaseModuleContext, versions []string) { +func normalizeVersions(ctx android.BaseModuleContext, versions []string) { numVersions := make([]int, len(versions)) for i, v := range versions { - numVer, err := strconv.Atoi(v) + numVer, err := android.ApiStrToNum(ctx, v) if err != nil { - ctx.PropertyErrorf("versions", "%q is not a number", v) + 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) + } } func createVersionVariations(mctx android.BottomUpMutatorContext, versions []string) { @@ -1522,7 +1526,7 @@ func VersionMutator(mctx android.BottomUpMutatorContext) { if library, ok := mctx.Module().(LinkableInterface); ok && !library.InRecovery() { if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 { versions := library.StubsVersions() - checkVersions(mctx, versions) + normalizeVersions(mctx, versions) if mctx.Failed() { return } diff --git a/cc/library_test.go b/cc/library_test.go index b8d889544..cb167252d 100644 --- a/cc/library_test.go +++ b/cc/library_test.go @@ -17,6 +17,8 @@ package cc import ( "reflect" "testing" + + "android/soong/android" ) func TestLibraryReuse(t *testing.T) { @@ -186,3 +188,55 @@ func TestLibraryReuse(t *testing.T) { } }) } + +func TestStubsVersions(t *testing.T) { + bp := ` + cc_library { + name: "libfoo", + srcs: ["foo.c"], + stubs: { + versions: ["29", "R", "10000"], + }, + } + ` + config := TestConfig(buildDir, android.Android, nil, bp, nil) + config.TestProductVariables.Platform_version_active_codenames = []string{"R"} + ctx := testCcWithConfig(t, config) + + variants := ctx.ModuleVariantsForTests("libfoo") + for _, expectedVer := range []string{"29", "9000", "10000"} { + expectedVariant := "android_arm_armv7-a-neon_shared_" + expectedVer + if !inList(expectedVariant, variants) { + t.Errorf("missing expected variant: %q", expectedVariant) + } + } +} + +func TestStubsVersions_NotSorted(t *testing.T) { + bp := ` + cc_library { + name: "libfoo", + srcs: ["foo.c"], + stubs: { + versions: ["29", "10000", "R"], + }, + } + ` + config := TestConfig(buildDir, android.Android, nil, bp, nil) + config.TestProductVariables.Platform_version_active_codenames = []string{"R"} + testCcErrorWithConfig(t, `"libfoo" .*: versions: not sorted`, config) +} + +func TestStubsVersions_ParseError(t *testing.T) { + bp := ` + cc_library { + name: "libfoo", + srcs: ["foo.c"], + stubs: { + versions: ["29", "10000", "X"], + }, + } + ` + + testCcError(t, `"libfoo" .*: versions: SDK version should be`, bp) +} diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 68d4ac067..1597b88d0 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -96,6 +96,8 @@ type libraryProperties struct { Unversioned_until *string // Private property for use by the mutator that splits per-API level. + // can be one of <number:sdk_version> or <codename> or "current" + // passed to "gen_stub_libs.py" as it is ApiLevel string `blueprint:"mutated"` // True if this API is not yet ready to be shipped in the NDK. It will be |