summaryrefslogtreecommitdiff
path: root/scripts/lint-project-xml.py
diff options
context:
space:
mode:
authorJaewoong Jung <jungjw@google.com>2021-04-19 17:38:17 -0700
committerJaewoong Jung <jungjw@google.com>2021-04-19 17:38:17 -0700
commita110439b3c0f13b054a0309304f7d9da5cd5f82b (patch)
tree3031296ffde8ca122475d919b24dbe8c571f0ff0 /scripts/lint-project-xml.py
parent302c5b8d80fb8b850d33a831b2a4b221c743bbee (diff)
Lint baseline file check in lint-project-xml
Add a function to lint-project-xml to scan the given lint baseline file for disallowed baseline lint issues. Test: Manual Bug: 182349282 Change-Id: I0db32bec0da24487b2f2b3f6704629f56ae76f56
Diffstat (limited to 'scripts/lint-project-xml.py')
-rwxr-xr-xscripts/lint-project-xml.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/lint-project-xml.py b/scripts/lint-project-xml.py
index f1ef85dcc..74aebc10a 100755
--- a/scripts/lint-project-xml.py
+++ b/scripts/lint-project-xml.py
@@ -18,6 +18,7 @@
"""This file generates project.xml and lint.xml files used to drive the Android Lint CLI tool."""
import argparse
+from xml.dom import minidom
from ninja_rsp import NinjaRspFileReader
@@ -73,6 +74,8 @@ def parse_args():
help='file containing the module\'s manifest.')
parser.add_argument('--merged_manifest', dest='merged_manifest',
help='file containing merged manifest for the module and its dependencies.')
+ parser.add_argument('--baseline', dest='baseline_path',
+ help='file containing baseline lint issues.')
parser.add_argument('--library', dest='library', action='store_true',
help='mark the module as a library.')
parser.add_argument('--test', dest='test', action='store_true',
@@ -90,6 +93,8 @@ def parse_args():
help='treat a lint issue as a warning.')
group.add_argument('--disable_check', dest='checks', action=check_action('ignore'), default=[],
help='disable a lint issue.')
+ group.add_argument('--disallowed_issues', dest='disallowed_issues', default=[],
+ help='lint issues disallowed in the baseline file')
return parser.parse_args()
@@ -134,10 +139,30 @@ def write_config_xml(f, args):
f.write("</lint>\n")
+def check_baseline_for_disallowed_issues(baseline, forced_checks):
+ issues_element = baseline.documentElement
+ if issues_element.tagName != 'issues':
+ raise RuntimeError('expected issues tag at root')
+ issues = issues_element.getElementsByTagName('issue')
+ disallwed = set()
+ for issue in issues:
+ id = issue.getAttribute('id')
+ if id in forced_checks:
+ disallwed.add(id)
+ return disallwed
+
+
def main():
"""Program entry point."""
args = parse_args()
+ if args.baseline_path:
+ baseline = minidom.parse(args.baseline_path)
+ diallowed_issues = check_baseline_for_disallowed_issues(baseline, args.disallowed_issues)
+ if bool(diallowed_issues):
+ raise RuntimeError('disallowed issues %s found in lint baseline file %s for module %s'
+ % (diallowed_issues, args.baseline_path, args.name))
+
if args.project_out:
with open(args.project_out, 'w') as f:
write_project_xml(f, args)