Commit 1ea5180e authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[Build] Fix lint warnings for Python functions to extract .info files from .aar.

The following Python functions are directly involved in extracting .info
files from .aar:
* gn_helpers.py: ToGNString().
* aar.py: _IsManifestEmpty().
* aar.py: _CreateInfo().

We wish to port these files to Google3 to enable .info file extraction
(while keeping the Chromium versions around for verification). However,
these functions produce many Python lint warnings in Google3. This CL
fixes these warnings in Chromium first, and improve comments.

Change-Id: I2a826f70ac1d15f2f358195327fd0dd3f12db5fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213206Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771582}
parent e8136dba
......@@ -24,14 +24,20 @@ import gn_helpers
def _IsManifestEmpty(manifest_str):
"""Returns whether the given manifest has merge-worthy elements.
"""Decides whether the given manifest has merge-worthy elements.
E.g.: <activity>, <service>, etc.
Args:
manifest_str: Content of a manifiest XML.
Returns:
Whether the manifest has merge-worthy elements.
"""
doc = ElementTree.fromstring(manifest_str)
for node in doc:
if node.tag == 'application':
if len(node):
if node.getchildren():
return False
elif node.tag != 'uses-sdk':
return False
......@@ -40,6 +46,14 @@ def _IsManifestEmpty(manifest_str):
def _CreateInfo(aar_file):
"""Extracts and return .info data from an .aar file.
Args:
aar_file: Path to an input .aar file.
Returns:
A dict containing .info data.
"""
data = {}
data['aidl'] = []
data['assets'] = []
......@@ -81,7 +95,7 @@ def _CreateInfo(aar_file):
elif name == 'R.txt':
# Some AARs, e.g. gvr_controller_java, have empty R.txt. Such AARs
# have no resources as well. We treat empty R.txt as having no R.txt.
data['has_r_text_file'] = (z.read('R.txt').strip() != '')
data['has_r_text_file'] = bool(z.read('R.txt').strip())
return data
......
This diff is collapsed.
......@@ -27,7 +27,7 @@ class UnitTest(unittest.TestCase):
gn_helpers.FromGNString('[1, -20, true, false,["as\\"", []]]'),
[ 1, -20, True, False, [ 'as"', [] ] ])
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('123 456')
parser.Parse()
......@@ -42,10 +42,10 @@ class UnitTest(unittest.TestCase):
parser = gn_helpers.GNValueParser('123')
self.assertEqual(parser.ParseNumber(), 123)
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('')
parser.ParseNumber()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('a123')
parser.ParseNumber()
......@@ -53,13 +53,13 @@ class UnitTest(unittest.TestCase):
parser = gn_helpers.GNValueParser('"asdf"')
self.assertEqual(parser.ParseString(), 'asdf')
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('') # Empty.
parser.ParseString()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('asdf') # Unquoted.
parser.ParseString()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('"trailing') # Unterminated.
parser.ParseString()
......@@ -67,16 +67,16 @@ class UnitTest(unittest.TestCase):
parser = gn_helpers.GNValueParser('[1,]') # Optional end comma OK.
self.assertEqual(parser.ParseList(), [ 1 ])
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('') # Empty.
parser.ParseList()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('asdf') # No [].
parser.ParseList()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('[1, 2') # Unterminated
parser.ParseList()
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser('[1 2]') # No separating comma.
parser.ParseList()
......@@ -107,15 +107,15 @@ class UnitTest(unittest.TestCase):
self.assertEqual(gn_helpers.FromGNArgs(' \n '), {})
# Non-identifiers should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
gn_helpers.FromGNArgs('123 = true')
# References to other variables should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
gn_helpers.FromGNArgs('foo = bar')
# References to functions should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
gn_helpers.FromGNArgs('foo = exec_script("//build/baz.py")')
# Underscores in identifiers should work.
......@@ -161,19 +161,19 @@ class UnitTest(unittest.TestCase):
"""))
# No trailing parenthesis should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser(
textwrap.dedent('import("//some/args/file.gni"'))
parser.ReplaceImports()
# No double quotes should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser(
textwrap.dedent('import(//some/args/file.gni)'))
parser.ReplaceImports()
# A path that's not source absolute should raise an exception.
with self.assertRaises(gn_helpers.GNException):
with self.assertRaises(gn_helpers.GNError):
parser = gn_helpers.GNValueParser(
textwrap.dedent('import("some/relative/args/file.gni")'))
parser.ReplaceImports()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment