Apply pylint to build/soong/cc/ndk_api_coverage_parser
1. Run black --line-length 80 -S build/soong/cc/ndk_api_coverage_parser to fix formatting 2. Annotate # pylint: disable=line-too-long for multi line strings in test_ndk_api_coverage_parser.py Test: pytest build/soong/cc/ndk_api_coverage_parser/test_ndk_api_coverage_parser.py Test: pylint --rcfile tools/repohooks/tools/pylintrc build/soong/cc/ndk_api_coverage_parser Bug: 195738175 Change-Id: Ifb6d4cd67399eb3fa201185c5d1ebc2544fa316f
This commit is contained in:
parent
795a9f99f4
commit
30eefd8b84
2 changed files with 46 additions and 19 deletions
|
@ -21,7 +21,12 @@ import os
|
|||
import sys
|
||||
|
||||
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'
|
||||
|
@ -63,6 +68,7 @@ def parse_tags(tags):
|
|||
|
||||
class XmlGenerator(object):
|
||||
"""Output generator that writes parsed symbol file to a xml file."""
|
||||
|
||||
def __init__(self, output_file):
|
||||
self.output_file = output_file
|
||||
|
||||
|
@ -74,10 +80,14 @@ class XmlGenerator(object):
|
|||
continue
|
||||
version_attributes = parse_tags(version.tags)
|
||||
_, _, postfix = version.name.partition('_')
|
||||
is_platform = postfix == 'PRIVATE' or postfix == 'PLATFORM'
|
||||
is_platform = postfix in ('PRIVATE' , 'PLATFORM')
|
||||
is_deprecated = postfix == 'DEPRECATED'
|
||||
version_attributes.update({PLATFORM_ATTRIBUTE_KEY: str(is_platform)})
|
||||
version_attributes.update({DEPRECATED_ATTRIBUTE_KEY: str(is_deprecated)})
|
||||
version_attributes.update(
|
||||
{PLATFORM_ATTRIBUTE_KEY: str(is_platform)}
|
||||
)
|
||||
version_attributes.update(
|
||||
{DEPRECATED_ATTRIBUTE_KEY: str(is_deprecated)}
|
||||
)
|
||||
for symbol in version.symbols:
|
||||
if VARIABLE_TAG in symbol.tags:
|
||||
continue
|
||||
|
@ -103,13 +113,20 @@ def parse_args():
|
|||
"""Parses and returns command line arguments."""
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('symbol_file', type=os.path.realpath, help='Path to symbol file.')
|
||||
parser.add_argument(
|
||||
'output_file', type=os.path.realpath,
|
||||
help='The output parsed api coverage file.')
|
||||
'symbol_file', type=os.path.realpath, help='Path to symbol file.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--api-map', type=os.path.realpath, required=True,
|
||||
help='Path to the API level map JSON file.')
|
||||
'output_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()
|
||||
|
||||
|
||||
|
@ -122,13 +139,15 @@ def main():
|
|||
|
||||
with open(args.symbol_file) as symbol_file:
|
||||
try:
|
||||
versions = SymbolFileParser(symbol_file, api_map, "", FUTURE_API_LEVEL,
|
||||
True, True).parse()
|
||||
versions = SymbolFileParser(
|
||||
symbol_file, api_map, "", FUTURE_API_LEVEL, True, True
|
||||
).parse()
|
||||
except MultiplyDefinedSymbolError as ex:
|
||||
sys.exit('{}: error: {}'.format(args.symbol_file, ex))
|
||||
|
||||
generator = XmlGenerator(args.output_file)
|
||||
generator.write(versions)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -50,10 +50,12 @@ def etree_equal(elem1, elem2):
|
|||
return False
|
||||
return all(etree_equal(c1, c2) for c1, c2 in zip(elem1, elem2))
|
||||
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
||||
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
|
||||
global:
|
||||
android_name_to_log_id; # apex llndk introduced=23
|
||||
|
@ -64,22 +66,28 @@ class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
|||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
|
||||
LIBLOG_PLATFORM {
|
||||
android_fdtrack; # llndk
|
||||
android_net; # introduced=23
|
||||
};
|
||||
|
||||
|
||||
LIBLOG_FOO { # 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())
|
||||
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))
|
||||
|
||||
# pylint: enable=line-too-long
|
||||
|
||||
def main():
|
||||
suite = unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
Loading…
Reference in a new issue