diff --git a/cc/androidmk.go b/cc/androidmk.go index a4d7fcfb1..50c183e95 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -18,7 +18,6 @@ import ( "fmt" "io" "path/filepath" - "strconv" "strings" "android/soong/android" @@ -217,7 +216,7 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And } func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { - ret.SubName = "." + strconv.Itoa(c.properties.ApiLevel) + ret.SubName = "." + c.properties.ApiLevel ret.Class = "SHARED_LIBRARIES" ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { diff --git a/cc/gen_stub_libs.py b/cc/gen_stub_libs.py index 2db8312e0..eb233f8fe 100755 --- a/cc/gen_stub_libs.py +++ b/cc/gen_stub_libs.py @@ -31,11 +31,30 @@ ALL_ARCHITECTURES = ( ) +# Arbitrary magic number. We use the same one in api-level.h for this purpose. +FUTURE_API_LEVEL = 10000 + + def logger(): """Return the main logger for this module.""" return logging.getLogger(__name__) +def api_level_arg(api_str): + """Parses an API level, handling the "current" special case. + + Args: + api_str: (string) Either a numeric API level or "current". + + Returns: + (int) FUTURE_API_LEVEL if `api_str` is "current", else `api_str` parsed + as an integer. + """ + if api_str == "current": + return FUTURE_API_LEVEL + return int(api_str) + + def get_tags(line): """Returns a list of all tags on this line.""" _, _, all_tags = line.strip().partition('#') @@ -105,10 +124,7 @@ def symbol_in_api(tags, arch, api): introduced_tag = tag arch_specific = True elif tag == 'future': - # This symbol is not in any released API level. - # TODO(danalbert): These need to be emitted for api == current. - # That's not a construct we have yet, so just skip it for now. - return False + return api == FUTURE_API_LEVEL if introduced_tag is None: # We found no "introduced" tags, so the symbol has always been @@ -310,7 +326,8 @@ def parse_args(): parser.add_argument('-v', '--verbose', action='count', default=0) parser.add_argument( - '--api', type=int, required=True, help='API level being targeted.') + '--api', type=api_level_arg, required=True, + help='API level being targeted.') parser.add_argument( '--arch', choices=ALL_ARCHITECTURES, required=True, help='Architecture being targeted.') diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 94be17c5b..d603ad080 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -88,7 +88,7 @@ type libraryProperties struct { First_version string // Private property for use by the mutator that splits per-API level. - ApiLevel int `blueprint:"mutated"` + ApiLevel string `blueprint:"mutated"` } type stubDecorator struct { @@ -147,14 +147,15 @@ func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorat mctx.PropertyErrorf("first_version", err.Error()) } - versionStrs := make([]string, maxVersion-firstVersion+1) + var versionStrs []string for version := firstVersion; version <= maxVersion; version++ { - versionStrs[version-firstVersion] = strconv.Itoa(version) + versionStrs = append(versionStrs, strconv.Itoa(version)) } + versionStrs = append(versionStrs, "current") modules := mctx.CreateVariations(versionStrs...) for i, module := range modules { - module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = firstVersion + i + module.(*Module).compiler.(*stubDecorator).properties.ApiLevel = versionStrs[i] } } @@ -188,7 +189,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O ndkLibrarySuffix) } libName := strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix) - fileBase := fmt.Sprintf("%s.%s.%d", libName, arch, c.properties.ApiLevel) + fileBase := fmt.Sprintf("%s.%s.%s", libName, arch, c.properties.ApiLevel) stubSrcName := fileBase + ".c" stubSrcPath := android.PathForModuleGen(ctx, stubSrcName) versionScriptName := fileBase + ".map" @@ -201,7 +202,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O Input: symbolFilePath, Args: map[string]string{ "arch": arch, - "apiLevel": strconv.Itoa(c.properties.ApiLevel), + "apiLevel": c.properties.ApiLevel, }, }) @@ -252,7 +253,7 @@ func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) { } installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf( - "platforms/android-%d/arch-%s/usr/%s", apiLevel, arch, libDir)) + "platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir)) stub.installPath = ctx.InstallFile(installDir, path).String() } diff --git a/cc/test_gen_stub_libs.py b/cc/test_gen_stub_libs.py index 2c79ded5b..e9e724989 100755 --- a/cc/test_gen_stub_libs.py +++ b/cc/test_gen_stub_libs.py @@ -75,6 +75,8 @@ class SymbolPresenceTest(unittest.TestCase): ['introduced=9', 'introduced-x86=21'], 'arm', 14)) self.assertTrue(gsl.symbol_in_api( ['introduced=21', 'introduced-arm=9'], 'arm', 14)) + self.assertTrue(gsl.symbol_in_api( + ['future'], 'arm', gsl.FUTURE_API_LEVEL)) self.assertFalse(gsl.symbol_in_api(['introduced=14'], 'arm', 9)) self.assertFalse(gsl.symbol_in_api(['introduced-arm=14'], 'arm', 9))