From ffafbee94ac0f6bb94b349e2cb30094b7812c1ad Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sun, 9 Oct 2022 21:41:55 -0400 Subject: [PATCH] scripts: revive the gsrc linter script, missing too many mistakes --- Taskfile.yml | 7 ++-- scripts/gsrc/check-gsrc-file.py | 67 --------------------------------- scripts/gsrc/lint-gsrc-file.py | 62 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 70 deletions(-) delete mode 100644 scripts/gsrc/check-gsrc-file.py create mode 100644 scripts/gsrc/lint-gsrc-file.py diff --git a/Taskfile.yml b/Taskfile.yml index 70a0cf6aa3..0cf7d5c03d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -89,6 +89,9 @@ tasks: decomp-clean: cmds: - python ./scripts/tasks/clean-decomp.py --game "{{.GAME}}" + lint-gsrc-file: + cmds: + - python ./scripts/gsrc/lint-gsrc-file.py --game {{.GAME}} --file {{.FILE}} update-gsrc: cmds: - python ./scripts/gsrc/update-gsrc-via-refs.py --game "{{.GAME}}" --decompiler "{{.DECOMP_BIN_RELEASE_DIR}}/decompiler" --decompiler_config {{.DECOMP_CONFIG}} @@ -96,6 +99,7 @@ tasks: cmds: - task: decomp-file - python ./scripts/gsrc/update-from-decomp.py --game "{{.GAME}}" --file {{.FILE}} + - task: lint-gsrc-file # TOOLS analyze-ee-memory: cmds: @@ -131,9 +135,6 @@ tasks: ignore_error: true - python ./scripts/update_decomp_reference.py ./failures ./test/decompiler/reference/ --game {{.GAME}} - task: offline-test-file - # check-gsrc-file: - # cmds: - # - python ./scripts/check-gsrc-file.py --files "{{.FILES}}" type-test: cmds: - cmd: '{{.GOALCTEST_BIN_RELEASE_DIR}}/goalc-test --gtest_brief=0 --gtest_filter="*Jak2TypeConsistency*"' diff --git a/scripts/gsrc/check-gsrc-file.py b/scripts/gsrc/check-gsrc-file.py deleted file mode 100644 index 3b9af31a05..0000000000 --- a/scripts/gsrc/check-gsrc-file.py +++ /dev/null @@ -1,67 +0,0 @@ -import re -from jak1_file_list import file_list -import argparse -import os - -parser = argparse.ArgumentParser() -parser.add_argument("--files") -args = parser.parse_args() - -files = args.files.split(",") - -throw_error = False - -method_split_pattern = re.compile('t9-\d+\s\(method-of-object') -function_split_pattern = re.compile('\(t9-\d+\)') -missing_res_tag_pattern = re.compile('(sv-\d{2,} int)') -decompiler_error_pattern = re.compile(';; ERROR') -missing_arg = re.compile('local-vars.*none\)') - -for file in files: - src_path = "" - for f in file_list: - if f[2] != 3: - continue - if f[0] == file: - src_path = f[4] - break - - if not os.path.exists("./goal_src/{}".format(src_path)): - print("{} couldn't find in /goal_src!".format(file)) - throw_error = True - continue - - file_path = "./goal_src/{}/{}.gc".format(src_path, file) - with open(file_path) as f: - for lineno, line in enumerate(f): - method_split_match = method_split_pattern.search(line) - if method_split_match: - print("method_split - {}:{}".format(file_path, lineno + 1)) - throw_error = True - continue - function_split_match = function_split_pattern.search(line) - if function_split_match: - print("function_split - {}:{}".format(file_path, lineno + 1)) - throw_error = True - continue - missing_res_tag_match = missing_res_tag_pattern.search(line) - if missing_res_tag_match: - print("missing_res_tag - {}:{}".format(file_path, lineno + 1)) - throw_error = True - continue - decompiler_error_match = decompiler_error_pattern.search(line) - if decompiler_error_match: - print("decompiler_error - {}:{}".format(file_path, lineno + 1)) - throw_error = True - continue - missing_arg_match = missing_arg.search(line) - if missing_arg_match: - print("missing_arg - {}:{}".format(file_path, lineno + 1)) - throw_error = True - continue - -if throw_error: - print("found potential problems!") - exit(1) -else: - print("looks good!") diff --git a/scripts/gsrc/lint-gsrc-file.py b/scripts/gsrc/lint-gsrc-file.py new file mode 100644 index 0000000000..3bd6dd3036 --- /dev/null +++ b/scripts/gsrc/lint-gsrc-file.py @@ -0,0 +1,62 @@ +import re +import argparse +import os +from utils import get_gsrc_path_from_filename + +parser = argparse.ArgumentParser("lint-gsrc-file") +parser.add_argument("--game", help="The name of the game", type=str) +parser.add_argument("--file", help="The name of the file", type=str) +args = parser.parse_args() + +throw_error = False + +# TODO - if more code is added here overtime, be smarter about this / group errors +method_split_pattern = re.compile('method-of-type') +function_split_pattern = re.compile('\(t9-\d+(?:\s+[^\s]+\s*)?\)') +missing_res_tag_pattern = re.compile('.pcpyud') +decompiler_error_pattern = re.compile(';; ERROR') +missing_arg = re.compile('local-vars.*[at].*\s+none\)') +casting_stack_var = re.compile('the-as\s+[^\s]*\s+.*\(new \'stack') + +src_path = get_gsrc_path_from_filename(args.game, args.file) + +print("Linting GOAL_SRC File...") + +with open(src_path) as f: + for lineno, line in enumerate(f): + method_split_match = method_split_pattern.search(line) + if method_split_match: + print("method_split - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + function_split_match = function_split_pattern.search(line) + if function_split_match: + print("function_split - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + missing_res_tag_match = missing_res_tag_pattern.search(line) + if missing_res_tag_match: + print("missing_res_tag - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + decompiler_error_match = decompiler_error_pattern.search(line) + if decompiler_error_match: + print("decompiler_error - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + missing_arg_match = missing_arg.search(line) + if missing_arg_match: + print("missing_arg - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + casting_stack_var_match = casting_stack_var.search(line) + if casting_stack_var_match: + print("casting stack var - {}:{}".format(src_path, lineno + 1)) + throw_error = True + continue + +if throw_error: + print("Found potential problems, exiting with code 1!") + exit(1) +else: + print("Looks good!")