Skip to content

Commit

Permalink
diff: Use compile_commands.json instead of glob
Browse files Browse the repository at this point in the history
  • Loading branch information
entriphy committed Jul 4, 2023
1 parent cb62d9b commit 8f3d904
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


19 changes: 14 additions & 5 deletions tools/build_diff.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
2 changes: 1 addition & 1 deletion tools/elf_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8f3d904

Please sign in to comment.