Support a `vndk` tag in gen_stub_libs.py

This hides a particular symbol from the NDK stubs, while allowing the
symbol to be exposed to the VNDK through the LLNDK stubs. This doesn't
introduce any sort of versioning yet, this will need to change when we
add a new symbol to a new version of the VNDK.

Test: test_gen_stub_libs.py
Test: With my LL-NDK patches, inspecting the generated map files
Change-Id: Iee86aafda7985d6d7a016d0d5ff951505634913b
This commit is contained in:
Dan Willemsen 2017-04-03 14:28:36 -07:00
parent f3d98fbb59
commit b01e7f7fd6
2 changed files with 47 additions and 19 deletions

View File

@ -79,7 +79,7 @@ def version_is_private(version):
return version.endswith('_PRIVATE') or version.endswith('_PLATFORM')
def should_omit_version(name, tags, arch, api):
def should_omit_version(name, tags, arch, api, vndk):
"""Returns True if the version section should be ommitted.
We want to omit any sections that do not have any symbols we'll have in the
@ -90,6 +90,8 @@ def should_omit_version(name, tags, arch, api):
return True
if 'platform-only' in tags:
return True
if 'vndk' in tags and not vndk:
return True
if not symbol_in_arch(tags, arch):
return True
if not symbol_in_api(tags, arch, api):
@ -271,11 +273,12 @@ class SymbolFileParser(object):
class Generator(object):
"""Output generator that writes stub source files and version scripts."""
def __init__(self, src_file, version_script, arch, api):
def __init__(self, src_file, version_script, arch, api, vndk):
self.src_file = src_file
self.version_script = version_script
self.arch = arch
self.api = api
self.vndk = vndk
def write(self, versions):
"""Writes all symbol data to the output files."""
@ -286,13 +289,15 @@ class Generator(object):
"""Writes a single version block's data to the output files."""
name = version.name
tags = version.tags
if should_omit_version(name, tags, self.arch, self.api):
if should_omit_version(name, tags, self.arch, self.api, self.vndk):
return
section_versioned = symbol_versioned_in_api(tags, self.api)
version_empty = True
pruned_symbols = []
for symbol in version.symbols:
if not self.vndk and 'vndk' in symbol.tags:
continue
if not symbol_in_arch(symbol.tags, self.arch):
continue
if not symbol_in_api(symbol.tags, self.arch, self.api):
@ -333,6 +338,8 @@ def parse_args():
parser.add_argument(
'--arch', choices=ALL_ARCHITECTURES, required=True,
help='Architecture being targeted.')
parser.add_argument(
'--vndk', action='store_true', help='Use the VNDK variant.')
parser.add_argument(
'symbol_file', type=os.path.realpath, help='Path to symbol file.')
@ -361,7 +368,8 @@ 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, args.api,
args.vndk)
generator.write(versions)

View File

@ -107,27 +107,39 @@ class SymbolPresenceTest(unittest.TestCase):
class OmitVersionTest(unittest.TestCase):
def test_omit_private(self):
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9))
self.assertTrue(gsl.should_omit_version('foo_PRIVATE', [], 'arm', 9))
self.assertTrue(gsl.should_omit_version('foo_PLATFORM', [], 'arm', 9))
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9, False))
self.assertTrue(gsl.should_omit_version(
'foo', ['platform-only'], 'arm', 9))
'foo_PRIVATE', [], 'arm', 9, False))
self.assertTrue(gsl.should_omit_version(
'foo_PLATFORM', [], 'arm', 9, False))
self.assertTrue(gsl.should_omit_version(
'foo', ['platform-only'], 'arm', 9, False))
def test_omit_vndk(self):
self.assertTrue(gsl.should_omit_version(
'foo', ['vndk'], 'arm', 9, False))
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9, True))
self.assertFalse(gsl.should_omit_version(
'foo', ['vndk'], 'arm', 9, True))
def test_omit_arch(self):
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9))
self.assertFalse(gsl.should_omit_version('foo', ['arm'], 'arm', 9))
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9, False))
self.assertFalse(gsl.should_omit_version(
'foo', ['arm'], 'arm', 9, False))
self.assertTrue(gsl.should_omit_version('foo', ['x86'], 'arm', 9))
self.assertTrue(gsl.should_omit_version(
'foo', ['x86'], 'arm', 9, False))
def test_omit_api(self):
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9))
self.assertFalse(gsl.should_omit_version('foo', [], 'arm', 9, False))
self.assertFalse(
gsl.should_omit_version('foo', ['introduced=9'], 'arm', 9))
gsl.should_omit_version('foo', ['introduced=9'], 'arm', 9, False))
self.assertTrue(
gsl.should_omit_version('foo', ['introduced=14'], 'arm', 9))
gsl.should_omit_version('foo', ['introduced=14'], 'arm', 9, False))
class SymbolFileParseTest(unittest.TestCase):
@ -302,7 +314,7 @@ class GeneratorTest(unittest.TestCase):
# OmitVersionTest, PrivateVersionTest, and SymbolPresenceTest.
src_file = cStringIO.StringIO()
version_file = cStringIO.StringIO()
generator = gsl.Generator(src_file, version_file, 'arm', 9)
generator = gsl.Generator(src_file, version_file, 'arm', 9, False)
version = gsl.Version('VERSION_PRIVATE', None, [], [
gsl.Symbol('foo', []),
@ -330,7 +342,7 @@ class GeneratorTest(unittest.TestCase):
# SymbolPresenceTest.
src_file = cStringIO.StringIO()
version_file = cStringIO.StringIO()
generator = gsl.Generator(src_file, version_file, 'arm', 9)
generator = gsl.Generator(src_file, version_file, 'arm', 9, False)
version = gsl.Version('VERSION_1', None, [], [
gsl.Symbol('foo', ['x86']),
@ -346,10 +358,17 @@ class GeneratorTest(unittest.TestCase):
self.assertEqual('', src_file.getvalue())
self.assertEqual('', version_file.getvalue())
version = gsl.Version('VERSION_1', None, [], [
gsl.Symbol('foo', ['vndk']),
])
generator.write_version(version)
self.assertEqual('', src_file.getvalue())
self.assertEqual('', version_file.getvalue())
def test_write(self):
src_file = cStringIO.StringIO()
version_file = cStringIO.StringIO()
generator = gsl.Generator(src_file, version_file, 'arm', 9)
generator = gsl.Generator(src_file, version_file, 'arm', 9, False)
versions = [
gsl.Version('VERSION_1', None, [], [
@ -410,6 +429,7 @@ class IntegrationTest(unittest.TestCase):
VERSION_4 { # versioned=9
wibble;
wizzes; # vndk
} VERSION_2;
VERSION_5 { # versioned=14
@ -421,7 +441,7 @@ class IntegrationTest(unittest.TestCase):
src_file = cStringIO.StringIO()
version_file = cStringIO.StringIO()
generator = gsl.Generator(src_file, version_file, 'arm', 9)
generator = gsl.Generator(src_file, version_file, 'arm', 9, False)
generator.write(versions)
expected_src = textwrap.dedent("""\