mirror of
https://github.com/pmret/papermario.git
synced 2024-11-08 12:02:30 +01:00
a4e1c2f522
* fix vscode cpp extension messing with files.associations * move stuff * it builds! * symlink papermario.us.z64 * ci: put baserom in right place * add jp * fix splat dir * ignore starrod dump * .s deps * update jenkins * add dsl back * configure.py versions * wups * fine ethan * fix paths * configure: default to only the version(s) with existing baseroms * fix coverage * fix progress.py * progress.py verisoning * remove format.sh from CONTRIBUTING * update CONTRIBUTING * fix first_diff * diff.py: use ver/current/ * update splat.yaml * trying to fix subrepo * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "06a737f02d" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "06a737f02d" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * configure fix * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "41786effd3" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "41786effd3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" Co-authored-by: Ethan Roseman <ethteck@gmail.com>
120 lines
3.6 KiB
Python
Executable File
120 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import git
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from colour import Color
|
|
|
|
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")
|
|
|
|
def get_func_sizes():
|
|
try:
|
|
result = subprocess.run(['objdump', '-x', elf_path], stdout=subprocess.PIPE)
|
|
nm_lines = result.stdout.decode().split("\n")
|
|
except:
|
|
print(f"Error: Could not run objdump on {elf_path} - make sure that the project is built")
|
|
sys.exit(1)
|
|
|
|
sizes = {}
|
|
total = 0
|
|
|
|
for line in nm_lines:
|
|
if " F " in line:
|
|
components = line.split()
|
|
size = int(components[4], 16)
|
|
name = components[5]
|
|
total += size
|
|
sizes[name] = size
|
|
|
|
return sizes, total
|
|
|
|
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
|
|
|
|
def get_funcs_sizes(sizes, matchings, nonmatchings):
|
|
msize = 0
|
|
nmsize = 0
|
|
|
|
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
|
|
|
|
def lerp(a, b, alpha):
|
|
return a + (b - a) * alpha
|
|
|
|
def main(args):
|
|
set_version(args.version)
|
|
|
|
func_sizes, total_size = get_func_sizes()
|
|
all_funcs = set(func_sizes.keys())
|
|
|
|
nonmatching_funcs = get_nonmatching_funcs()
|
|
matching_funcs = all_funcs - nonmatching_funcs
|
|
|
|
matching_size, nonmatching_size = get_funcs_sizes(func_sizes, matching_funcs, nonmatching_funcs)
|
|
|
|
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
|
|
|
|
if args.csv:
|
|
version = 1
|
|
git_object = git.Repo().head.object
|
|
timestamp = str(git_object.committed_date)
|
|
git_hash = git_object.hexsha
|
|
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)]
|
|
print(",".join(csv_list))
|
|
elif args.shield_json:
|
|
import json
|
|
|
|
# https://shields.io/endpoint
|
|
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,
|
|
}))
|
|
else:
|
|
if matching_size + nonmatching_size != total_size:
|
|
print("Warning: category/total size mismatch!\n")
|
|
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}%)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Reports progress for the project")
|
|
parser.add_argument("version", default="current", nargs="?")
|
|
parser.add_argument("--csv", action="store_true")
|
|
parser.add_argument("--shield-json", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
main(args)
|