diff options
author | 2024-09-25 15:41:19 -0700 | |
---|---|---|
committer | 2024-09-26 12:12:14 -0700 | |
commit | 874273545b58747a617cf418dd93cb1902d7de89 (patch) | |
tree | 460889e1f16f5e533126958b8b9a002dba56fcff /scripts | |
parent | b34ca77d473778926bdf42d69884cc37f2f7cc2e (diff) |
Remove top down strict updatability checks
The enforce_strict_updatability_linting and apex_strict_updatability_lint
are some of the last top down mutators, and removing them will help
with incremental analysis. Both mutators are used to propagate a flag
to transitive java dependencies that causes them to add extra checks to
their lint rules to require that baselines not include any skipped
NewApi checks.
Instead of modifying dependencies to check the baselines, propagate the
baselines up to the modules that are requesting the checks, and perform
the checks on all transitive baselines there.
Bug: 367784740
Test: TestJavaLintStrictUpdatabilityLinting
Test: TestApexStrictUpdtabilityLint
Flag: EXEMPT refactor
Change-Id: Ief2e3b26d745da61f13e621d635a5879d9c56779
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Android.bp | 17 | ||||
-rwxr-xr-x | scripts/lint_project_xml.py | 24 | ||||
-rwxr-xr-x | scripts/lint_strict_updatability_checks.py | 81 | ||||
-rwxr-xr-x[-rw-r--r--] | scripts/lint_strict_updatability_checks_test.py (renamed from scripts/lint_project_xml_test.py) | 6 |
4 files changed, 97 insertions, 31 deletions
diff --git a/scripts/Android.bp b/scripts/Android.bp index 3d81b83c2..00b3ca591 100644 --- a/scripts/Android.bp +++ b/scripts/Android.bp @@ -184,12 +184,21 @@ python_binary_host { libs: ["ninja_rsp"], } +python_binary_host { + name: "lint_strict_updatability_checks", + main: "lint_strict_updatability_checks.py", + srcs: [ + "lint_strict_updatability_checks.py", + ], + libs: ["ninja_rsp"], +} + python_test_host { - name: "lint_project_xml_test", - main: "lint_project_xml_test.py", + name: "lint_strict_updatability_checks_test", + main: "lint_strict_updatability_checks_test.py", srcs: [ - "lint_project_xml_test.py", - "lint_project_xml.py", + "lint_strict_updatability_checks_test.py", + "lint_strict_updatability_checks.py", ], libs: ["ninja_rsp"], test_suites: ["general-tests"], diff --git a/scripts/lint_project_xml.py b/scripts/lint_project_xml.py index c40b07d38..ce6aa21a2 100755 --- a/scripts/lint_project_xml.py +++ b/scripts/lint_project_xml.py @@ -75,8 +75,6 @@ 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', @@ -94,8 +92,6 @@ 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() @@ -140,30 +136,10 @@ 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') - disallowed = set() - for issue in issues: - id = issue.getAttribute('id') - if id in forced_checks: - disallowed.add(id) - return disallowed - - def main(): """Program entry point.""" args = parse_args() - if args.baseline_path: - baseline = minidom.parse(args.baseline_path) - disallowed_issues = check_baseline_for_disallowed_issues(baseline, args.disallowed_issues) - if disallowed_issues: - sys.exit('disallowed issues %s found in lint baseline file %s for module %s' - % (disallowed_issues, args.baseline_path, args.name)) - if args.project_out: with open(args.project_out, 'w') as f: write_project_xml(f, args) diff --git a/scripts/lint_strict_updatability_checks.py b/scripts/lint_strict_updatability_checks.py new file mode 100755 index 000000000..5b5dfd81a --- /dev/null +++ b/scripts/lint_strict_updatability_checks.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2018 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""This file checks baselines passed to Android Lint for checks that must not be baselined.""" + +import argparse +import sys +from xml.dom import minidom + +from ninja_rsp import NinjaRspFileReader + + +def parse_args(): + """Parse commandline arguments.""" + + def convert_arg_line_to_args(arg_line): + for arg in arg_line.split(): + if arg.startswith('#'): + return + if not arg.strip(): + continue + yield arg + + parser = argparse.ArgumentParser(fromfile_prefix_chars='@') + parser.convert_arg_line_to_args = convert_arg_line_to_args + parser.add_argument('--name', dest='name', + help='name of the module.') + parser.add_argument('--baselines', dest='baselines', action='append', default=[], + help='file containing whitespace separated list of baseline files.') + parser.add_argument('--disallowed_issues', dest='disallowed_issues', default=[], + help='lint issues disallowed in the baseline file') + return parser.parse_args() + + +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') + disallowed = set() + for issue in issues: + id = issue.getAttribute('id') + if id in forced_checks: + disallowed.add(id) + return disallowed + + +def main(): + """Program entry point.""" + args = parse_args() + + error = False + for baseline_rsp_file in args.baselines: + for baseline_path in NinjaRspFileReader(baseline_rsp_file): + baseline = minidom.parse(baseline_path) + disallowed_issues = check_baseline_for_disallowed_issues(baseline, args.disallowed_issues) + if disallowed_issues: + print('disallowed issues %s found in lint baseline file %s for module %s' + % (disallowed_issues, baseline_path, args.name)) + error = True + + if error: + sys.exit(1) + + +if __name__ == '__main__': + main() diff --git a/scripts/lint_project_xml_test.py b/scripts/lint_strict_updatability_checks_test.py index 344691d00..fd8610f3a 100644..100755 --- a/scripts/lint_project_xml_test.py +++ b/scripts/lint_strict_updatability_checks_test.py @@ -15,12 +15,12 @@ # limitations under the License. # -"""Unit tests for lint_project_xml.py.""" +"""Unit tests for lint_strict_updatability_checks.py.""" import unittest from xml.dom import minidom -import lint_project_xml +import lint_strict_updatability_checks class CheckBaselineForDisallowedIssuesTest(unittest.TestCase): @@ -44,7 +44,7 @@ class CheckBaselineForDisallowedIssuesTest(unittest.TestCase): '</issues>\n') def test_check_baseline_for_disallowed_issues(self): - disallowed_issues = lint_project_xml.check_baseline_for_disallowed_issues(self.baseline_xml, ["foo", "bar", "qux"]) + disallowed_issues = lint_strict_updatability_checks.check_baseline_for_disallowed_issues(self.baseline_xml, ["foo", "bar", "qux"]) self.assertEqual({"foo", "bar"}, disallowed_issues) |