Merge "Support a vndk tag in gen_stub_libs.py"

This commit is contained in:
Dan Willemsen 2017-04-07 17:16:07 +00:00 committed by Gerrit Code Review
commit 86a1c7dd15
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') 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. """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 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 return True
if 'platform-only' in tags: if 'platform-only' in tags:
return True return True
if 'vndk' in tags and not vndk:
return True
if not symbol_in_arch(tags, arch): if not symbol_in_arch(tags, arch):
return True return True
if not symbol_in_api(tags, arch, api): if not symbol_in_api(tags, arch, api):
@ -271,11 +273,12 @@ class SymbolFileParser(object):
class Generator(object): class Generator(object):
"""Output generator that writes stub source files and version scripts.""" """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.src_file = src_file
self.version_script = version_script self.version_script = version_script
self.arch = arch self.arch = arch
self.api = api self.api = api
self.vndk = vndk
def write(self, versions): def write(self, versions):
"""Writes all symbol data to the output files.""" """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.""" """Writes a single version block's data to the output files."""
name = version.name name = version.name
tags = version.tags 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 return
section_versioned = symbol_versioned_in_api(tags, self.api) section_versioned = symbol_versioned_in_api(tags, self.api)
version_empty = True version_empty = True
pruned_symbols = [] pruned_symbols = []
for symbol in version.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): if not symbol_in_arch(symbol.tags, self.arch):
continue continue
if not symbol_in_api(symbol.tags, self.arch, self.api): if not symbol_in_api(symbol.tags, self.arch, self.api):
@ -333,6 +338,8 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--arch', choices=ALL_ARCHITECTURES, required=True, '--arch', choices=ALL_ARCHITECTURES, required=True,
help='Architecture being targeted.') help='Architecture being targeted.')
parser.add_argument(
'--vndk', action='store_true', help='Use the VNDK variant.')
parser.add_argument( parser.add_argument(
'symbol_file', type=os.path.realpath, help='Path to symbol file.') '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.stub_src, 'w') as src_file:
with open(args.version_script, 'w') as version_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) generator.write(versions)

View file

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