Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
is_windows,
)

from tools.dev_symbols_order_check import configure_symbols_order_check

# Game versions
DEFAULT_VERSION = 0
VERSIONS = [
Expand Down Expand Up @@ -78,6 +80,11 @@
action="store_true",
help="build with debug info (non-matching)",
)
parser.add_argument(
"--check-symbols-order",
action="store_true",
help="add symbols order check at the end of the build"
)
if not is_windows():
parser.add_argument(
"--wrapper",
Expand Down Expand Up @@ -143,6 +150,9 @@
if config.version == "MarioClub_us":
debug = True

if args.check_symbols_order:
configure_symbols_order_check(config)

# Apply arguments
config.build_dir = args.build_dir
config.dtk_path = args.dtk
Expand Down
65 changes: 65 additions & 0 deletions tools/dev_symbols_order_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3

###
# Helper file to add custom rules to the ninja build in order to check the symbols order at the
# end of the build.
# It adds:
# - post-build check of the symbols order of all modified cpp files found in git against main branch
# This is to automate the symbols check in the workflow and ease the developer experience.
###

import subprocess
import sys
from pathlib import Path

def configure_symbols_order_check(
config) -> None:
"""Add custom rules to the project in order to check automatically
the symbols order with the current git diff."""

map_out = f"orig/{config.version}/files/debugInfoM.MAP"

config.custom_build_rules = [
{
"name": "check_symbols_order",
"command": "python3 tools/dev_symbols_order_check.py",
"description": "CHECK symbols order",
"pool": "console",
},
]

config.custom_build_steps = {
"post-build": [
{
"rule": "check_symbols_order",
"outputs": "check_symbols_order.stamp",
"implicit": [map_out],
},
],
}

def get_changed_cpp_files(base="main"):
"""Helper function performing a git diff against a given branch
in order to find which cpp files changed."""
merge_base = subprocess.check_output(
["git", "merge-base", base, "HEAD"], text=True
).strip()
out = subprocess.check_output(
["git", "diff", "--name-only", merge_base, "--", "*.cpp"], text=True
)
return out.split()

def main() -> int:
"""Perform a git diff and run the symbol order check on all found cpp files.
This main will be used during ninja build phase configured in 'configure_symbol_order_check'.
"""
changed = get_changed_cpp_files()
if not changed:
print("No changed .cpp files vs main — nothing to check.")
return 0

script = Path(__file__).parent / "check-changed-symbol-order.py"
return subprocess.call([sys.executable, str(script), *changed])

if __name__ == "__main__":
sys.exit(main())
6 changes: 5 additions & 1 deletion tools/validate-symbol-order.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(script_dir, ".."))

def is_windows() -> bool:
return os.name == "nt"

EXE = ".exe" if is_windows() else ""
DEFAULT_MAP = os.path.join(root_dir, "orig", "MarioClub_us", "files", "debugInfoM.MAP")
NM = os.environ.get("NM", os.path.join(root_dir, "build", "binutils", "powerpc-eabi-nm.exe"))
NM = os.environ.get("NM", os.path.join(root_dir, "build", "binutils", f"powerpc-eabi-nm{EXE}"))
OBJDIFF_JSON = os.path.join(root_dir, "objdiff.json")


Expand Down
Loading