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
This commit is contained in:
parent
302c5b8d80
commit
a110439b3c
|
@ -18,6 +18,7 @@
|
||||||
"""This file generates project.xml and lint.xml files used to drive the Android Lint CLI tool."""
|
"""This file generates project.xml and lint.xml files used to drive the Android Lint CLI tool."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from xml.dom import minidom
|
||||||
|
|
||||||
from ninja_rsp import NinjaRspFileReader
|
from ninja_rsp import NinjaRspFileReader
|
||||||
|
|
||||||
|
@ -73,6 +74,8 @@ def parse_args():
|
||||||
help='file containing the module\'s manifest.')
|
help='file containing the module\'s manifest.')
|
||||||
parser.add_argument('--merged_manifest', dest='merged_manifest',
|
parser.add_argument('--merged_manifest', dest='merged_manifest',
|
||||||
help='file containing merged manifest for the module and its dependencies.')
|
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',
|
parser.add_argument('--library', dest='library', action='store_true',
|
||||||
help='mark the module as a library.')
|
help='mark the module as a library.')
|
||||||
parser.add_argument('--test', dest='test', action='store_true',
|
parser.add_argument('--test', dest='test', action='store_true',
|
||||||
|
@ -90,6 +93,8 @@ def parse_args():
|
||||||
help='treat a lint issue as a warning.')
|
help='treat a lint issue as a warning.')
|
||||||
group.add_argument('--disable_check', dest='checks', action=check_action('ignore'), default=[],
|
group.add_argument('--disable_check', dest='checks', action=check_action('ignore'), default=[],
|
||||||
help='disable a lint issue.')
|
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()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,10 +139,30 @@ def write_config_xml(f, args):
|
||||||
f.write("</lint>\n")
|
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():
|
def main():
|
||||||
"""Program entry point."""
|
"""Program entry point."""
|
||||||
args = parse_args()
|
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:
|
if args.project_out:
|
||||||
with open(args.project_out, 'w') as f:
|
with open(args.project_out, 'w') as f:
|
||||||
write_project_xml(f, args)
|
write_project_xml(f, args)
|
||||||
|
|
Loading…
Reference in New Issue