From 76ff33061036b2c808d1ff7210e589153ef227e5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 24 Jun 2022 12:55:42 +0100 Subject: [PATCH] maint/add_warning: Scan all files by default, but insist only in some This will allow us to have add_warning manage test lint blocks. We have to stop printing all the filenames because there are too many. Filenames still come out on error of course. --- .gitlab-ci.yml | 2 +- maint/add_warning | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index afef3ea34..8819498a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,7 +34,7 @@ maint-checks: script: - apt-get update && apt-get install -y python3-toml - ./maint/check_toposort - - ./maint/add_warning --check crates/*/src/{lib,main}.rs + - ./maint/add_warning --check rust-checks: # This is too slow (and the cacheing of the "cargo build" too flaky) to be a "check" diff --git a/maint/add_warning b/maint/add_warning index a1c6615e7..5c5a94b4a 100755 --- a/maint/add_warning +++ b/maint/add_warning @@ -1,6 +1,7 @@ #!/usr/bin/python3 import argparse +import fnmatch import sys import os import re @@ -78,7 +79,7 @@ class ImproperFile(Exception): self.lno = lno self.message = message -def filter_file(lints, inp, outp): +def filter_file(lints, inp, outp, insist): in_lint_list = False found_lint_list = False lno = 0 @@ -107,16 +108,19 @@ def filter_file(lints, inp, outp): outp.write(line) if in_lint_list: raise ImproperFile(lno, 'missing "@@ lint list" delimiter, still in lint list at EOF') - if not found_lint_list: + if insist and not found_lint_list: raise ImproperFile(lno, 'standard lint list block seems to be missing (wrong delimiters?)') -def process(lints, fn): - print("{}...".format(fn)) +def process(lints, fn, always_insist): + insist = (always_insist or + fnmatch.fnmatch(fn, 'crates/*/src/lib.rs') or + fnmatch.fnmatch(fn, 'crates/*/src/main.rs')) + tmp_name = fn+".tmp~" outp = open(tmp_name,'w') inp = open(fn,'r') try: - filter_file(lints, inp, outp) + filter_file(lints, inp, outp, insist) except ImproperFile as e: print('%s:%d: %s' % (fn, e.lno, e.message), file=sys.stderr) deferred_errors.append(fn) @@ -137,12 +141,15 @@ def main(lints,files): print("Run this from the top level of an arti repo.") sys.exit(1) + always_insist = True if not files: - print("No files provided. Example usage:") - print(" ./maint/add_warning crates/*/src/{lib,main}.rs") + files = subprocess.run(['find','-name','*.rs'], + stdout=subprocess.PIPE, check=True).stdout; + files = files.decode('utf-8').rstrip('\n').split('\n') + always_insist = False for fn in files: - process(lints, fn) + process(lints, fn, always_insist) if len(deferred_errors) > 0: print('\n' + sys.argv[0] + ': standard lint block mismatch in the following files:\n ' @@ -153,7 +160,7 @@ def main(lints,files): if __name__ == '__main__': parser = argparse.ArgumentParser('standardise Rust lint blocks') parser.add_argument('--check') - parser.add_argument('file', nargs='+') + parser.add_argument('file', nargs='*') opts = parser.parse_args() main(WANT_LINTS, opts.file)