2021-05-14 14:33:08 -04:00
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import argparse
|
|
|
|
import shutil
|
|
|
|
|
2022-09-13 20:03:00 -04:00
|
|
|
from gsrc.utils import get_ref_path_from_filename
|
|
|
|
|
2021-05-14 14:33:08 -04:00
|
|
|
## Script to update failing _REF.gc files
|
|
|
|
## Instructions:
|
2022-09-13 20:03:00 -04:00
|
|
|
## run offline-test with the `--dump_current_output` flag set. This generates a "failures" folder.
|
2021-05-14 14:33:08 -04:00
|
|
|
## update reference like this
|
2022-09-13 20:03:00 -04:00
|
|
|
## python3 ../scripts/update_decomp_reference.py ./failures ../test/decompiler/reference --game [jak1|jak2]
|
2022-09-13 18:15:02 -04:00
|
|
|
|
2022-09-13 20:03:00 -04:00
|
|
|
def get_failures(root_dir):
|
|
|
|
return [
|
|
|
|
f
|
|
|
|
for file in os.walk(root_dir)
|
|
|
|
for f in glob.glob(os.path.join(file[0], "*.gc"))
|
|
|
|
]
|
2021-05-14 14:33:08 -04:00
|
|
|
|
2022-09-16 20:42:33 -04:00
|
|
|
# removesuffix only added in python 3.9....
|
|
|
|
def removesuffix(self: str, suffix: str, /) -> str:
|
|
|
|
if self.endswith(suffix):
|
|
|
|
return self[:-len(suffix)]
|
|
|
|
else:
|
|
|
|
return self[:]
|
|
|
|
|
2021-05-14 14:33:08 -04:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
2022-09-13 20:03:00 -04:00
|
|
|
parser.add_argument(dest="diff", help="the failures folder")
|
|
|
|
parser.add_argument(dest="reference", help="the test/decompiler/reference folder")
|
|
|
|
parser.add_argument("--game", help="The name of the game (jak1/jak2)", type=str)
|
2021-05-14 14:33:08 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-09-13 20:03:00 -04:00
|
|
|
for replacement in get_failures(args.diff):
|
2022-09-16 20:42:33 -04:00
|
|
|
obj_name = removesuffix(os.path.basename(replacement), ".gc").replace("_REF", "")
|
2021-05-14 14:33:08 -04:00
|
|
|
|
2022-09-13 20:03:00 -04:00
|
|
|
# Find gsrc path, given game-name
|
|
|
|
ref_path = get_ref_path_from_filename(args.game, obj_name, args.reference)
|
2021-05-14 14:33:08 -04:00
|
|
|
|
2022-09-13 20:03:00 -04:00
|
|
|
print("replace {} with {}".format(ref_path, replacement))
|
|
|
|
shutil.copyfile(replacement, ref_path)
|
2021-05-14 14:33:08 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|