diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb949eb..a079f0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: Untar SDK run: sudo mkdir /sce; sudo tar -xf sdk.tar.xz -C /sce; sudo ln -s /sce /usr/local/sce - name: Configure CMake - run: cmake -DCMAKE_TOOLCHAIN_FILE=ps2_ee.cmake -Bbuild + run: cmake -DCMAKE_TOOLCHAIN_FILE=ps2_ee.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -Bbuild - name: Build run: cmake --build build - name: Download original ELF @@ -39,6 +39,6 @@ jobs: run: pip install pyelftools rabbitizer - name: Run diff if: always() - run: python tools/build_diff.py orig.elf build/CMakeFiles/kl2_lv_decomp.dir --json functions.json + run: python tools/build_diff.py orig.elf build --json functions.json diff --git a/tools/build_diff.py b/tools/build_diff.py index 70a230a..0d8a37a 100644 --- a/tools/build_diff.py +++ b/tools/build_diff.py @@ -1,7 +1,8 @@ from elf_diff import diff import argparse -import glob +import json import os +import re if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -13,7 +14,15 @@ parser.add_argument("-j", "--json") args = parser.parse_args() - object_files = glob.glob(os.path.join(args.build_path, "**/*.c.o"), recursive=True) - object_files += glob.glob(os.path.join(args.build_path, "**/*.cc.o"), recursive=True) - for object in object_files: - diff(args.orig_elf, object, args.json) + # Requires -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + with open(os.path.join(args.build_path, "compile_commands.json"), "r") as f: + compile_comands = json.load(f) + objects = [] + for command in compile_comands: + # Older versions of CMake don't have the "output" field, so we have to regex it D: + o = re.findall(r"(CMakeFiles/kl2_lv_decomp\.dir/src/.+?\.o)", command["command"]) + if len(o) > 0: + objects.append(o[0]) + for o in objects: + object_path = os.path.join(args.build_path, o) + diff(args.orig_elf, object_path, args.json) diff --git a/tools/elf_diff.py b/tools/elf_diff.py index 15e519c..fb86ff7 100644 --- a/tools/elf_diff.py +++ b/tools/elf_diff.py @@ -94,7 +94,7 @@ def read_elf(elf_path: str, json_path: str = None) -> GenericElf: def diff(orig_elf_path, decomp_elf_path, orig_json): orig_elf = read_elf(orig_elf_path, orig_json) decomp_elf = read_elf(decomp_elf_path) - print(f"{os.path.basename(orig_elf_path)} -> {os.path.basename(decomp_elf_path)}:") + print(f"{os.path.basename(orig_elf_path)} -> {'/'.join(os.path.abspath(decomp_elf_path).split('/')[-2:])[:-2]}:") for func_name in orig_elf.functions.keys(): if func_name not in decomp_elf.functions: