2021-01-04 14:50:33 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import git
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2021-02-22 10:21:23 +01:00
|
|
|
from colour import Color
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2021-02-22 10:21:23 +01:00
|
|
|
def set_version(version):
|
|
|
|
global script_dir, root_dir, asm_dir, build_dir, elf_path
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
root_dir = os.path.join(script_dir, "ver", version)
|
|
|
|
asm_dir = os.path.join(root_dir, "asm", "nonmatchings")
|
|
|
|
build_dir = os.path.join(root_dir, "build")
|
|
|
|
elf_path = os.path.join(build_dir, "papermario.elf")
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2021-08-24 12:22:24 +02:00
|
|
|
def load_latest_progress(version):
|
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
if version == "current":
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
version = Path("ver/current").resolve().parts[-1]
|
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
csv = urlopen(f"https://papermar.io/reports/progress_{version}.csv").read().decode("utf-8")
|
2021-08-24 12:22:24 +02:00
|
|
|
latest = csv.split("\n")[-2]
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
(
|
|
|
|
version,
|
|
|
|
timestamp,
|
|
|
|
git_hash,
|
|
|
|
all_funcs,
|
|
|
|
nonmatching_funcs,
|
|
|
|
matching_funcs,
|
|
|
|
total_size,
|
|
|
|
nonmatching_size,
|
|
|
|
matching_size,
|
|
|
|
) = latest.split(",")
|
|
|
|
|
|
|
|
return (
|
|
|
|
int(all_funcs),
|
|
|
|
int(nonmatching_funcs),
|
|
|
|
int(matching_funcs),
|
|
|
|
int(total_size),
|
|
|
|
int(nonmatching_size),
|
|
|
|
int(matching_size),
|
|
|
|
)
|
2021-08-24 12:22:24 +02:00
|
|
|
|
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
def get_func_info():
|
2021-01-04 14:50:33 +01:00
|
|
|
try:
|
2023-07-29 19:03:17 +02:00
|
|
|
result = subprocess.run(["mips-linux-gnu-objdump", "-x", elf_path], stdout=subprocess.PIPE)
|
2021-01-04 14:50:33 +01:00
|
|
|
nm_lines = result.stdout.decode().split("\n")
|
|
|
|
except:
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"Error: Could not run objdump on {elf_path} - make sure that the project is built")
|
2021-01-04 14:50:33 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sizes = {}
|
2022-05-06 00:56:16 +02:00
|
|
|
vrams = {}
|
2021-01-04 14:50:33 +01:00
|
|
|
|
|
|
|
for line in nm_lines:
|
2022-12-17 18:08:52 +01:00
|
|
|
if " F " in line and "*ABS*" not in line:
|
2021-01-04 14:50:33 +01:00
|
|
|
components = line.split()
|
|
|
|
size = int(components[4], 16)
|
|
|
|
name = components[5]
|
|
|
|
sizes[name] = size
|
2022-05-06 00:56:16 +02:00
|
|
|
vrams[name] = int(components[0], 16)
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
return sizes, vrams
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2021-01-04 14:50:33 +01:00
|
|
|
def get_nonmatching_funcs():
|
|
|
|
funcs = set()
|
|
|
|
|
|
|
|
for root, dirs, files in os.walk(asm_dir):
|
|
|
|
for f in files:
|
|
|
|
if f.endswith(".s"):
|
|
|
|
funcs.add(f[:-2])
|
|
|
|
|
|
|
|
return funcs
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
def get_funcs_sizes(sizes, matchings, nonmatchings, restrict_to=None):
|
2021-01-04 14:50:33 +01:00
|
|
|
msize = 0
|
|
|
|
nmsize = 0
|
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
if restrict_to:
|
|
|
|
matchings = matchings.intersection(restrict_to)
|
|
|
|
nonmatchings = nonmatchings.intersection(restrict_to)
|
|
|
|
|
2021-01-04 14:50:33 +01:00
|
|
|
for func in matchings:
|
|
|
|
msize += sizes[func]
|
|
|
|
|
|
|
|
for func in nonmatchings:
|
|
|
|
if func not in sizes:
|
|
|
|
pass
|
|
|
|
# print(func)
|
|
|
|
else:
|
|
|
|
nmsize += sizes[func]
|
|
|
|
|
|
|
|
return msize, nmsize
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2021-02-22 10:21:23 +01:00
|
|
|
def lerp(a, b, alpha):
|
|
|
|
return a + (b - a) * alpha
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
def get_funcs_in_vram_range(vrams, vram_min, vram_max):
|
|
|
|
funcs = set()
|
|
|
|
for func in vrams:
|
|
|
|
if vrams[func] >= vram_min and vrams[func] <= vram_max:
|
|
|
|
funcs.add(func)
|
|
|
|
return funcs
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
|
|
|
|
def do_section_progress(
|
|
|
|
section_name,
|
|
|
|
vrams,
|
|
|
|
sizes,
|
|
|
|
total_size,
|
|
|
|
matchings,
|
|
|
|
nonmatchings,
|
|
|
|
section_vram_start,
|
|
|
|
section_vram_end,
|
|
|
|
):
|
2022-05-06 00:56:16 +02:00
|
|
|
funcs = get_funcs_in_vram_range(vrams, section_vram_start, section_vram_end)
|
2023-07-29 19:03:17 +02:00
|
|
|
matching_size, nonmatching_size = get_funcs_sizes(sizes, matchings, nonmatchings, restrict_to=funcs)
|
2022-05-06 00:56:16 +02:00
|
|
|
section_total_size = matching_size + nonmatching_size
|
|
|
|
progress_ratio = (matching_size / section_total_size) * 100
|
|
|
|
matching_ratio = (matching_size / total_size) * 100
|
|
|
|
total_ratio = (section_total_size / total_size) * 100
|
2023-07-29 19:03:17 +02:00
|
|
|
print(f"\t{section_name}: {matching_size} matching bytes / {section_total_size} total ({progress_ratio:.2f}%)")
|
|
|
|
print(f"\t\t(matched {matching_ratio:.2f}% of {total_ratio:.2f}% total rom for {section_name})")
|
2023-07-03 11:35:05 +02:00
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
|
2021-01-04 14:50:33 +01:00
|
|
|
def main(args):
|
2021-02-22 10:21:23 +01:00
|
|
|
set_version(args.version)
|
|
|
|
|
2022-05-06 00:56:16 +02:00
|
|
|
sizes, vrams = get_func_info()
|
|
|
|
total_size = sum(sizes.values())
|
2023-07-03 11:35:05 +02:00
|
|
|
# TODO hack for now since non-us roms aren't mapped out
|
2023-02-18 10:03:57 +01:00
|
|
|
if args.version != "us":
|
2023-07-03 11:35:05 +02:00
|
|
|
total_size = 3718612
|
2022-05-06 00:56:16 +02:00
|
|
|
all_funcs = set(sizes.keys())
|
2021-01-04 14:50:33 +01:00
|
|
|
|
|
|
|
nonmatching_funcs = get_nonmatching_funcs()
|
|
|
|
matching_funcs = all_funcs - nonmatching_funcs
|
|
|
|
|
2023-07-29 19:03:17 +02:00
|
|
|
matching_size, nonmatching_size = get_funcs_sizes(sizes, matching_funcs, nonmatching_funcs)
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2021-02-22 10:21:23 +01:00
|
|
|
if len(all_funcs) == 0:
|
|
|
|
funcs_matching_ratio = 0.0
|
|
|
|
matching_ratio = 0.0
|
|
|
|
else:
|
|
|
|
funcs_matching_ratio = (len(matching_funcs) / len(all_funcs)) * 100
|
|
|
|
matching_ratio = (matching_size / total_size) * 100
|
2021-01-04 14:50:33 +01:00
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
(
|
|
|
|
old_all_funcs,
|
|
|
|
old_nonmatching_funcs,
|
|
|
|
old_matching_funcs,
|
|
|
|
old_total_size,
|
|
|
|
old_nonmatching_size,
|
|
|
|
old_matching_size,
|
|
|
|
) = load_latest_progress(args.version)
|
2023-02-21 15:37:27 +01:00
|
|
|
|
|
|
|
if old_total_size == 0:
|
|
|
|
old_matching_ratio = 0.0
|
|
|
|
else:
|
|
|
|
old_matching_ratio = (old_matching_size / old_total_size) * 100
|
2021-08-24 12:22:24 +02:00
|
|
|
|
|
|
|
ratio_delta = matching_ratio - old_matching_ratio
|
|
|
|
funcs_delta = len(matching_funcs) - old_matching_funcs
|
|
|
|
|
2021-01-04 14:50:33 +01:00
|
|
|
if args.csv:
|
|
|
|
version = 1
|
|
|
|
git_object = git.Repo().head.object
|
|
|
|
timestamp = str(git_object.committed_date)
|
|
|
|
git_hash = git_object.hexsha
|
2023-07-03 11:35:05 +02:00
|
|
|
csv_list = [
|
|
|
|
str(version),
|
|
|
|
timestamp,
|
|
|
|
git_hash,
|
|
|
|
str(len(all_funcs)),
|
|
|
|
str(len(nonmatching_funcs)),
|
|
|
|
str(len(matching_funcs)),
|
|
|
|
str(total_size),
|
|
|
|
str(nonmatching_size),
|
|
|
|
str(matching_size),
|
|
|
|
]
|
2021-01-04 14:50:33 +01:00
|
|
|
print(",".join(csv_list))
|
2021-01-15 17:28:05 +01:00
|
|
|
elif args.shield_json:
|
|
|
|
import json
|
|
|
|
|
|
|
|
# https://shields.io/endpoint
|
2023-07-03 11:35:05 +02:00
|
|
|
color = Color("#50ca22", hue=lerp(0, 105 / 255, matching_ratio / 100))
|
|
|
|
print(
|
|
|
|
json.dumps(
|
|
|
|
{
|
|
|
|
"schemaVersion": 1,
|
|
|
|
"label": f"progress ({args.version})",
|
|
|
|
"message": f"{matching_ratio:.2f}%",
|
|
|
|
"color": color.hex,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2021-08-24 12:22:24 +02:00
|
|
|
elif args.pr_comment:
|
|
|
|
if funcs_delta > 0:
|
|
|
|
if funcs_delta == 1:
|
|
|
|
s = ""
|
|
|
|
else:
|
|
|
|
s = "s"
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
print(
|
|
|
|
f"{'🚀' * funcs_delta} This PR matches {funcs_delta} function{s} (+{ ratio_delta:.2f}%) on `{args.version}`."
|
|
|
|
)
|
2021-01-04 14:50:33 +01:00
|
|
|
else:
|
2021-01-05 18:04:30 +01:00
|
|
|
if matching_size + nonmatching_size != total_size:
|
2023-03-02 02:16:55 +01:00
|
|
|
print(f"Warning: category/total size mismatch on version {args.version}!\n")
|
|
|
|
print("Matching size: " + str(matching_size))
|
|
|
|
print("Nonmatching size: " + str(nonmatching_size))
|
2023-07-29 19:03:17 +02:00
|
|
|
print("Sum: " + str(matching_size + nonmatching_size) + " (should be " + str(total_size) + ")")
|
|
|
|
print(f"{len(matching_funcs)} matched functions / {len(all_funcs)} total ({funcs_matching_ratio:.2f}%)")
|
|
|
|
print(f"{matching_size} matching bytes / {total_size} total ({matching_ratio:.2f}%)")
|
2023-07-03 11:35:05 +02:00
|
|
|
|
|
|
|
do_section_progress(
|
|
|
|
"effects",
|
|
|
|
vrams,
|
|
|
|
sizes,
|
|
|
|
total_size,
|
|
|
|
matching_funcs,
|
|
|
|
nonmatching_funcs,
|
|
|
|
0xE0000000,
|
|
|
|
0xE1000000,
|
|
|
|
)
|
|
|
|
do_section_progress(
|
|
|
|
"map",
|
|
|
|
vrams,
|
|
|
|
sizes,
|
|
|
|
total_size,
|
|
|
|
matching_funcs,
|
|
|
|
nonmatching_funcs,
|
|
|
|
0x80240000,
|
|
|
|
0x80250000,
|
|
|
|
)
|
2022-05-06 00:56:16 +02:00
|
|
|
|
2021-08-24 12:22:24 +02:00
|
|
|
if funcs_delta > 0:
|
|
|
|
if funcs_delta == 1:
|
|
|
|
s = ""
|
|
|
|
else:
|
|
|
|
s = "s"
|
|
|
|
|
2023-07-03 11:35:05 +02:00
|
|
|
print(
|
|
|
|
f"This local build matches {funcs_delta} function{s} (+{ ratio_delta:.2f}%) over latest '{args.version}'."
|
|
|
|
)
|
2021-08-24 12:22:24 +02:00
|
|
|
|
2021-01-04 14:50:33 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description="Reports progress for the project")
|
2021-02-22 10:21:23 +01:00
|
|
|
parser.add_argument("version", default="current", nargs="?")
|
2021-01-04 14:50:33 +01:00
|
|
|
parser.add_argument("--csv", action="store_true")
|
2021-01-15 17:28:05 +01:00
|
|
|
parser.add_argument("--shield-json", action="store_true")
|
2021-08-24 12:22:24 +02:00
|
|
|
parser.add_argument("--pr-comment", action="store_true")
|
2021-01-04 14:50:33 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
main(args)
|