Merge "Apply pylint to build/soong/cc/ndk_api_coverage_parser"
This commit is contained in:
@@ -21,7 +21,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from xml.etree.ElementTree import Element, SubElement, tostring
|
from xml.etree.ElementTree import Element, SubElement, tostring
|
||||||
from symbolfile import ALL_ARCHITECTURES, FUTURE_API_LEVEL, MultiplyDefinedSymbolError, SymbolFileParser
|
from symbolfile import (
|
||||||
|
ALL_ARCHITECTURES,
|
||||||
|
FUTURE_API_LEVEL,
|
||||||
|
MultiplyDefinedSymbolError,
|
||||||
|
SymbolFileParser,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ROOT_ELEMENT_TAG = 'ndk-library'
|
ROOT_ELEMENT_TAG = 'ndk-library'
|
||||||
@@ -63,6 +68,7 @@ def parse_tags(tags):
|
|||||||
|
|
||||||
class XmlGenerator(object):
|
class XmlGenerator(object):
|
||||||
"""Output generator that writes parsed symbol file to a xml file."""
|
"""Output generator that writes parsed symbol file to a xml file."""
|
||||||
|
|
||||||
def __init__(self, output_file):
|
def __init__(self, output_file):
|
||||||
self.output_file = output_file
|
self.output_file = output_file
|
||||||
|
|
||||||
@@ -74,10 +80,14 @@ class XmlGenerator(object):
|
|||||||
continue
|
continue
|
||||||
version_attributes = parse_tags(version.tags)
|
version_attributes = parse_tags(version.tags)
|
||||||
_, _, postfix = version.name.partition('_')
|
_, _, postfix = version.name.partition('_')
|
||||||
is_platform = postfix == 'PRIVATE' or postfix == 'PLATFORM'
|
is_platform = postfix in ('PRIVATE' , 'PLATFORM')
|
||||||
is_deprecated = postfix == 'DEPRECATED'
|
is_deprecated = postfix == 'DEPRECATED'
|
||||||
version_attributes.update({PLATFORM_ATTRIBUTE_KEY: str(is_platform)})
|
version_attributes.update(
|
||||||
version_attributes.update({DEPRECATED_ATTRIBUTE_KEY: str(is_deprecated)})
|
{PLATFORM_ATTRIBUTE_KEY: str(is_platform)}
|
||||||
|
)
|
||||||
|
version_attributes.update(
|
||||||
|
{DEPRECATED_ATTRIBUTE_KEY: str(is_deprecated)}
|
||||||
|
)
|
||||||
for symbol in version.symbols:
|
for symbol in version.symbols:
|
||||||
if VARIABLE_TAG in symbol.tags:
|
if VARIABLE_TAG in symbol.tags:
|
||||||
continue
|
continue
|
||||||
@@ -103,13 +113,20 @@ def parse_args():
|
|||||||
"""Parses and returns command line arguments."""
|
"""Parses and returns command line arguments."""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument('symbol_file', type=os.path.realpath, help='Path to symbol file.')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'output_file', type=os.path.realpath,
|
'symbol_file', type=os.path.realpath, help='Path to symbol file.'
|
||||||
help='The output parsed api coverage file.')
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--api-map', type=os.path.realpath, required=True,
|
'output_file',
|
||||||
help='Path to the API level map JSON file.')
|
type=os.path.realpath,
|
||||||
|
help='The output parsed api coverage file.',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--api-map',
|
||||||
|
type=os.path.realpath,
|
||||||
|
required=True,
|
||||||
|
help='Path to the API level map JSON file.',
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@@ -122,13 +139,15 @@ def main():
|
|||||||
|
|
||||||
with open(args.symbol_file) as symbol_file:
|
with open(args.symbol_file) as symbol_file:
|
||||||
try:
|
try:
|
||||||
versions = SymbolFileParser(symbol_file, api_map, "", FUTURE_API_LEVEL,
|
versions = SymbolFileParser(
|
||||||
True, True).parse()
|
symbol_file, api_map, "", FUTURE_API_LEVEL, True, True
|
||||||
|
).parse()
|
||||||
except MultiplyDefinedSymbolError as ex:
|
except MultiplyDefinedSymbolError as ex:
|
||||||
sys.exit('{}: error: {}'.format(args.symbol_file, ex))
|
sys.exit('{}: error: {}'.format(args.symbol_file, ex))
|
||||||
|
|
||||||
generator = XmlGenerator(args.output_file)
|
generator = XmlGenerator(args.output_file)
|
||||||
generator.write(versions)
|
generator.write(versions)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@@ -50,10 +50,12 @@ def etree_equal(elem1, elem2):
|
|||||||
return False
|
return False
|
||||||
return all(etree_equal(c1, c2) for c1, c2 in zip(elem1, elem2))
|
return all(etree_equal(c1, c2) for c1, c2 in zip(elem1, elem2))
|
||||||
|
|
||||||
|
# pylint: disable=line-too-long
|
||||||
class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
||||||
def test_parse(self):
|
def test_parse(self):
|
||||||
input_file = io.StringIO(textwrap.dedent(u"""\
|
input_file = io.StringIO(
|
||||||
|
textwrap.dedent(
|
||||||
|
u"""\
|
||||||
LIBLOG { # introduced-arm64=24 introduced-x86=24 introduced-x86_64=24
|
LIBLOG { # introduced-arm64=24 introduced-x86=24 introduced-x86_64=24
|
||||||
global:
|
global:
|
||||||
android_name_to_log_id; # apex llndk introduced=23
|
android_name_to_log_id; # apex llndk introduced=23
|
||||||
@@ -64,22 +66,28 @@ class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
|||||||
local:
|
local:
|
||||||
*;
|
*;
|
||||||
};
|
};
|
||||||
|
|
||||||
LIBLOG_PLATFORM {
|
LIBLOG_PLATFORM {
|
||||||
android_fdtrack; # llndk
|
android_fdtrack; # llndk
|
||||||
android_net; # introduced=23
|
android_net; # introduced=23
|
||||||
};
|
};
|
||||||
|
|
||||||
LIBLOG_FOO { # var
|
LIBLOG_FOO { # var
|
||||||
android_var;
|
android_var;
|
||||||
};
|
};
|
||||||
"""))
|
"""
|
||||||
parser = SymbolFileParser(input_file, {}, "", FUTURE_API_LEVEL, True, True)
|
)
|
||||||
|
)
|
||||||
|
parser = SymbolFileParser(
|
||||||
|
input_file, {}, "", FUTURE_API_LEVEL, True, True
|
||||||
|
)
|
||||||
generator = nparser.XmlGenerator(io.StringIO())
|
generator = nparser.XmlGenerator(io.StringIO())
|
||||||
result = generator.convertToXml(parser.parse())
|
result = generator.convertToXml(parser.parse())
|
||||||
expected = fromstring('<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>')
|
expected = fromstring(
|
||||||
|
'<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>'
|
||||||
|
)
|
||||||
self.assertTrue(etree_equal(expected, result))
|
self.assertTrue(etree_equal(expected, result))
|
||||||
|
# pylint: enable=line-too-long
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
suite = unittest.TestLoader().loadTestsFromName(__name__)
|
suite = unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
Reference in New Issue
Block a user