diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a5a0e290..55127b75e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,17 +47,15 @@ jobs: Remove-Item '.\tools.zip' Remove-Item -LiteralPath 'tools2' -Force -Recurse - - name: Re-generate assembly - run: python -m mkwutil.gen_asm + - uses: actions/cache@v2 + with: + path: asm/dol + key: asm-dol - # https://stackoverflow.com/a/56389437 - - name: Verify assembly still the same - run: | - $ChangedFiles = $(git status --porcelain | Measure-Object | Select-Object -expand Count) - if ($ChangedFiles -gt 0) { - git status --porcelain - throw "Found $ChangedFiles changed files! Did you run gen_asm?" - } + - uses: actions/cache@v2 + with: + path: asm/rel + key: asm-rel - name: Build mkw shell: bash diff --git a/.gitignore b/.gitignore index 2949f224e..1b03f4115 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,10 @@ /pack/dol.lcf /pack/rel.lcf +# Auto-generated assembly +/asm/dol/ +/asm/rel/ + # Executables *.exe *.dll @@ -58,9 +62,6 @@ tmp *.map out.html -# Compiler tools bundle -tools.7z - # Editors .vscode/ *.bndb diff --git a/README.md b/README.md index 875871c4d..654d15119 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,6 @@ The dead-stripping feature can be re-enabled by: - [pack/dol_slices.csv](./pack/dol_slices.csv) - [pack/rel_slices.csv](./pack/rel_slices.csv) - Entries must be sorted in the spreadsheet (current limitation). -- After modifying slices, run `python3 -m mkwutil.gen_asm`. - Add your new build target to `mkwutil/sources.py`. - Run `build.py`. diff --git a/build.py b/build.py index d5b7d1bda..a91a94981 100644 --- a/build.py +++ b/build.py @@ -3,6 +3,7 @@ """ +import argparse from itertools import chain import os import os.path @@ -26,9 +27,17 @@ from mkwutil.verify_main_dol import verify_dol from mkwutil.verify_staticr_rel import verify_rel from mkwutil.progress.percent_decompiled import percent_decompiled - +from mkwutil.gen_asm import gen_asm from mkwutil.project import load_dol_slices + +parser = argparse.ArgumentParser(description="Build main.dol and StaticR.rel.") +parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM") +args = parser.parse_args() +# Start by running gen_asm. +gen_asm(args.regen_asm) + + colorama.init() print_mutex = Lock() diff --git a/mkwutil/gen_asm.py b/mkwutil/gen_asm.py index bdbdbf9e9..dff2674e8 100644 --- a/mkwutil/gen_asm.py +++ b/mkwutil/gen_asm.py @@ -454,52 +454,47 @@ def __gen_asm(self, section: Section, _slice: Slice): gen = AsmGenerator(data, _slice, SymbolsList(), asm_file) gen.dump_section() -def main(): - parser = argparse.ArgumentParser( - description="Generate ASM blobs and linker object lists." - ) - parser.add_argument("--asm_dir", type=Path, default="./asm", help="Path to ASM dir") - parser.add_argument( - "--pack_dir", type=Path, default="./pack", help="Path to link instructions dir" - ) - parser.add_argument( - "--binary_dir", - type=Path, - default="./artifacts/orig/pal", - help="Binary containing main.dol and StaticR.rel", - ) - parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM") - args = parser.parse_args() - args.asm_dir.mkdir(exist_ok=True) - symbols = read_symbol_map(args.pack_dir / "symbols.txt") +def gen_asm(regen_asm=False): + asm_dir = Path("./asm") + pack_dir = Path("./pack") + binary_dir = Path("./artifacts/orig/pal") - dol = read_dol(args.binary_dir / "main.dol") - dol_slices = read_enabled_slices(dol, args.pack_dir / "dol_slices.csv") + asm_dir.mkdir(exist_ok=True) + + symbols = read_symbol_map(pack_dir / "symbols.txt") + + dol = read_dol(binary_dir / "main.dol") + dol_slices = read_enabled_slices(dol, pack_dir / "dol_slices.csv") # Disassemble DOL sections. - dol_asm_dir = args.asm_dir / "dol" + dol_asm_dir = asm_dir / "dol" dol_asm_dir.mkdir(exist_ok=True) dol_gen = DOLSrcGenerator( - dol_slices, dol, symbols, dol_asm_dir, args.pack_dir, args.regen_asm + dol_slices, dol, symbols, dol_asm_dir, pack_dir, regen_asm ) dol_gen.run() - rel = read_rel(args.binary_dir / "StaticR.rel") + rel = read_rel(binary_dir / "StaticR.rel") # Dump StaticR.rel segments. - rel_bin_dir = args.binary_dir / "rel" + rel_bin_dir = binary_dir / "rel" dump_staticr(rel, rel_bin_dir) # Map out slices in REL. rel_slices = load_rel_slices(sections=REL_SECTIONS) rel_slices.filter(SliceTable.ONLY_ENABLED) # Disassemble REL sections. - rel_asm_dir = args.asm_dir / "rel" + rel_asm_dir = asm_dir / "rel" rel_asm_dir.mkdir(exist_ok=True) rel_gen = RELSrcGenerator( - rel_slices, rel, rel_asm_dir, rel_bin_dir, args.pack_dir, args.regen_asm + rel_slices, rel, rel_asm_dir, rel_bin_dir, pack_dir, regen_asm ) rel_gen.run() if __name__ == "__main__": - main() + parser = argparse.ArgumentParser( + description="Generate ASM blobs and linker object lists." + ) + parser.add_argument("--regen_asm", action="store_true", help="Regenerate all ASM") + args = parser.parse_args() + gen_asm(args.regen_asm)