From 3bf236cf8198fc09a0802b95167fccf3c90437d4 Mon Sep 17 00:00:00 2001 From: a3d4 Date: Tue, 2 Jun 2020 02:52:29 +0200 Subject: [PATCH] Refactor error ID checker script --- .circleci/config.yml | 2 +- liblangutil/Exceptions.h | 2 +- ...{correct_error_ids.py => fix_error_ids.py} | 39 +++++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) rename scripts/{correct_error_ids.py => fix_error_ids.py} (89%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f2b46a0c..624af2f0e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -323,7 +323,7 @@ jobs: - checkout - run: name: Check for error codes - command: ./scripts/correct_error_ids.py --noconfirm + command: ./scripts/fix_error_ids.py --check-only chk_pylint: docker: diff --git a/liblangutil/Exceptions.h b/liblangutil/Exceptions.h index 42b76a1fe..3fbf7711a 100644 --- a/liblangutil/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -61,7 +61,7 @@ struct InvalidAstError: virtual util::Exception {}; * They are passed as the first parameter of error reporting functions. * Suffix _error helps to find them in the sources. * The struct ErrorId prevents incidental calls like typeError(3141) instead of typeError(3141_error). - * To create a new ID, one can add 0000_error and then run "python ./scripts/correct_error_ids.py" + * To create a new ID, one can add 0000_error and then run "python ./scripts/fix_error_ids.py" * from the root of the repo. */ struct ErrorId { unsigned long long error = 0; }; diff --git a/scripts/correct_error_ids.py b/scripts/fix_error_ids.py similarity index 89% rename from scripts/correct_error_ids.py rename to scripts/fix_error_ids.py index cbbad8264..d9a201115 100755 --- a/scripts/correct_error_ids.py +++ b/scripts/fix_error_ids.py @@ -119,28 +119,19 @@ def find_source_files(top_dir): def main(argv): + check_only = False noconfirm = False - opts, args = getopt.getopt(argv, "", ["noconfirm"]) + opts, args = getopt.getopt(argv, "", ["check-only", "noconfirm"]) for opt, arg in opts: - if opt == '--noconfirm': + if opt == '--check-only': + check_only = True + elif opt == '--noconfirm': noconfirm = True random.seed() cwd = os.getcwd() - if not noconfirm: - answer = input( - f"This script checks and corrects *_error literals in .h and .cpp files\n" - f"in {cwd}, recursively.\n\n" - f"Please commit current changes first, and review the results when the script finishes.\n\n" - f"Do you want to start [Y/N]? " - ) - while len(answer) == 0 or answer not in "YNyn": - answer = input("[Y/N]? ") - if answer not in "yY": - exit(0) - source_file_names = find_source_files(cwd) used_ids = get_used_ids(source_file_names) @@ -160,11 +151,25 @@ def main(argv): if ok: print("No incorrect IDs found") exit(0) - else: - fix_ids(used_ids, source_file_names) - print("Fixing completed") + + if check_only: exit(1) + if not noconfirm: + answer = input( + "\nDo you want to fix incorrect IDs?\n" + "Please commit current changes first, and review the results when the script finishes.\n" + "[Y/N]? " + ) + while len(answer) == 0 or answer not in "YNyn": + answer = input("[Y/N]? ") + if answer not in "yY": + exit(1) + + fix_ids(used_ids, source_file_names) + print("Fixing completed") + exit(2) + if __name__ == "__main__": main(sys.argv[1:])