Merge pull request #9085 from a3d4/refactor-error-ids-script

Refactor error ID checker script
This commit is contained in:
chriseth 2020-06-03 11:12:42 +02:00 committed by GitHub
commit de5e283574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -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:

View File

@ -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; };

View File

@ -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,10 +151,24 @@ def main(argv):
if ok:
print("No incorrect IDs found")
exit(0)
else:
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(1)
exit(2)
if __name__ == "__main__":