diff options
author | Dan Albert <danalbert@google.com> | 2017-03-28 15:00:46 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2017-04-28 16:11:13 -0700 |
commit | 49927d29d50132b80d1f237682f7ffe44a8a5b74 (patch) | |
tree | 29ac1748cbeca047730769c713231a7c6b5d9d0d /cc/gen_stub_libs.py | |
parent | dd29407e74d796ab4493b3e0a8ccdb5693e15acd (diff) | |
download | build_soong-49927d29d50132b80d1f237682f7ffe44a8a5b74.tar.gz build_soong-49927d29d50132b80d1f237682f7ffe44a8a5b74.tar.bz2 build_soong-49927d29d50132b80d1f237682f7ffe44a8a5b74.zip |
Generate stub libraries for unreleased API levels.
Generating released API levels and android-current is not sufficient
in a trunk-stable world. One branch will have the stable APIs and
possibly multiple unreleased API levels. We need to generate stubs
for each unreleased API level up to our current target.
I still need to add support for things like `# introduced=O` before
this is really done.
Whether or not we still need something like "current" that would map
to the absolute latest even it hasn't been assigned a code name yet
is uncertain.
Test: make ndk
Bug: None
Change-Id: I282be1347ab39c56fa887d4d71c03bb12c300dc5
Diffstat (limited to 'cc/gen_stub_libs.py')
-rwxr-xr-x | cc/gen_stub_libs.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/cc/gen_stub_libs.py b/cc/gen_stub_libs.py index 7c704068..8a4f21e5 100755 --- a/cc/gen_stub_libs.py +++ b/cc/gen_stub_libs.py @@ -16,6 +16,7 @@ # """Generates source for stub shared libraries for the NDK.""" import argparse +import json import logging import os import re @@ -326,6 +327,27 @@ class Generator(object): self.version_script.write('}' + base + ';\n') +def decode_api_level(api, api_map): + """Decodes the API level argument into the API level number. + + For the average case, this just decodes the integer value from the string, + but for unreleased APIs we need to translate from the API codename (like + "O") to the future API level for that codename. + """ + try: + return int(api) + except ValueError: + pass + + if api == "current": + return FUTURE_API_LEVEL + + with open(api_map) as map_file: + api_levels = json.load(map_file) + + return api_levels[api] + + def parse_args(): """Parses and returns command line arguments.""" parser = argparse.ArgumentParser() @@ -333,8 +355,7 @@ def parse_args(): parser.add_argument('-v', '--verbose', action='count', default=0) parser.add_argument( - '--api', type=api_level_arg, required=True, - help='API level being targeted.') + '--api', required=True, help='API level being targeted.') parser.add_argument( '--arch', choices=ALL_ARCHITECTURES, required=True, help='Architecture being targeted.') @@ -342,6 +363,10 @@ def parse_args(): '--vndk', action='store_true', help='Use the VNDK variant.') parser.add_argument( + '--api-map', type=os.path.realpath, required=True, + help='Path to the API level map JSON file.') + + parser.add_argument( 'symbol_file', type=os.path.realpath, help='Path to symbol file.') parser.add_argument( 'stub_src', type=os.path.realpath, @@ -357,6 +382,8 @@ def main(): """Program entry point.""" args = parse_args() + api = decode_api_level(args.api, args.api_map) + verbose_map = (logging.WARNING, logging.INFO, logging.DEBUG) verbosity = args.verbose if verbosity > 2: @@ -368,7 +395,7 @@ def main(): with open(args.stub_src, 'w') as src_file: with open(args.version_script, 'w') as version_file: - generator = Generator(src_file, version_file, args.arch, args.api, + generator = Generator(src_file, version_file, args.arch, api, args.vndk) generator.write(versions) |