Add frogress badge

This commit is contained in:
1superchip 2023-11-10 22:07:08 -06:00
parent da71aaf33a
commit 2d96842586
4 changed files with 123 additions and 1 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@ disasm.txt
*.dll *.dll
build.ninja build.ninja
order.txt order.txt
cli.py
cli.ini

View File

@ -1,6 +1,7 @@
# ty1-decomp [![Discord Channel][discord-badge]][discord] # ty1-decomp [![Discord Channel][discord-badge]][discord] ![dol progress]
[discord]: https://discord.gg/hKx3FJJgrV [discord]: https://discord.gg/hKx3FJJgrV
[discord-badge]: https://img.shields.io/discord/727908905392275526?color=%237289DA&logo=discord&logoColor=%23FFFFFF [discord-badge]: https://img.shields.io/discord/727908905392275526?color=%237289DA&logo=discord&logoColor=%23FFFFFF
[dol progress]: https://img.shields.io/endpoint?label=dol&url=https%3A%2F%2Fprogress.decomp.club%2Fdata%2Fty%2Fus%2FCode%2F%3Fmode%3Dshield%26measure%3Dcode
Decompilation of Ty the Tasmanian Tiger NTSC-U (GTYE69) Decompilation of Ty the Tasmanian Tiger NTSC-U (GTYE69)

42
generate_progress.py Normal file
View File

@ -0,0 +1,42 @@
from argparse import ArgumentParser
import os.path
import pickle
import json
from typing import Dict, Tuple
import common as c
def load_progress_info(ctx: c.SourceContext, asm_list: str
) -> Tuple[Dict[str, int], Dict[str, int]]:
assert os.path.exists(ctx.labels), "Error: analysis has not ran!"
# Get data
raw = c.get_cmd_stdout(f"{c.PROGRESS} {ctx.binary} {ctx.labels} {ctx.slices}")
dat = json.loads(raw)
assert dat.get("version") == 2, "Outdated progress json version, try a clean & rebuild"
decomp_sizes = dat["decomp_slices_sizes"]
total_sizes = dat["total_sizes"]
symbol_sizes = dat["symbol_sizes"]
# Subtract undecompiled functions in decompiled slices
# TODO: this assumes none of .init is decompiled
with open(asm_list, 'rb') as f:
funcs = pickle.load(f)
for func in funcs:
decomp_sizes[".text"] -= symbol_sizes[str(func)]
return decomp_sizes, total_sizes
def generate_frogress_json(dol_size, dol_total):
return json.dumps({
"Code": {
"code": dol_size,
"code/total": dol_total
}
})
if __name__=="__main__":
decomp_sizes, total_sizes = load_progress_info(c.DOL_CTX, c.DOL_ASM_LIST)
json_str = generate_frogress_json(decomp_sizes[".text"], total_sizes[".text"])
with open("out/progress.json", "w") as f:
f.write(json_str)

77
upload_progress.py Normal file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env python3
###
# Uploads progress information to https://github.com/decompals/frogress.
#
# Usage:
# python3 tools/upload_progress.py -b https://progress.deco.mp/ -p [project] -v [version] build/[version]/progress.json
#
# If changes are made, please submit a PR to
# https://github.com/encounter/dtk-template
###
import argparse
import json
import os
import requests
import subprocess
import sys
def get_git_commit_timestamp() -> int:
return int(
subprocess.check_output(["git", "show", "-s", "--format=%ct"])
.decode("ascii")
.rstrip()
)
def get_git_commit_sha() -> str:
return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
def generate_url(args: argparse.Namespace) -> str:
url_components = [args.base_url.rstrip("/"), "data"]
for arg in [args.project, args.version]:
if arg != "":
url_components.append(arg)
return str.join("/", url_components) + "/"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Upload progress information.")
parser.add_argument("-b", "--base_url", help="API base URL", required=True)
parser.add_argument("-a", "--api_key", help="API key (env var PROGRESS_API_KEY)")
parser.add_argument("-p", "--project", help="Project slug", required=True)
parser.add_argument("-v", "--version", help="Version slug", required=True)
parser.add_argument("input", help="Progress JSON input")
args = parser.parse_args()
api_key = args.api_key or os.environ.get("PROGRESS_API_KEY")
if not api_key:
raise "API key required"
url = generate_url(args)
entries = []
with open(args.input, "r") as f:
data = json.load(f)
entries.append(
{
"timestamp": get_git_commit_timestamp(),
"git_hash": get_git_commit_sha(),
"categories": data,
}
)
print("Publishing entry to", url)
json.dump(entries[0], sys.stdout, indent=4)
print()
r = requests.post(url, json={
"api_key": api_key,
"entries": entries,
})
r.raise_for_status()
print("Done!")