From 3b97a15ea30b6ce8ed25828be364fb0418785af6 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 1 Jan 2019 00:28:51 +0100 Subject: Add tool to find unnamed symbols This tool should help us identify which are the symbols that still need proper names, and in which files they're located. --- tools/unnamed.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 tools/unnamed.py diff --git a/tools/unnamed.py b/tools/unnamed.py new file mode 100755 index 000000000..205e1efd5 --- /dev/null +++ b/tools/unnamed.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 + +from sys import stderr, exit +from subprocess import run +from struct import unpack, calcsize +from enum import Enum + +class symtype(Enum): + LOCAL = 0 + IMPORT = 1 + EXPORT = 2 + +def unpack_file(fmt, file): + size = calcsize(fmt) + return unpack(fmt, file.read(size)) + +def read_string(file): + buf = bytearray() + while True: + b = file.read(1) + if b is None or b == b'\0': + return buf.decode() + else: + buf += b + + +# Fix broken pipe when using `head` +from signal import signal, SIGPIPE, SIG_DFL +signal(SIGPIPE,SIG_DFL) + +import argparse +parser = argparse.ArgumentParser(description="Parse the symfile to find unnamed symbols") +parser.add_argument('symfile', type=argparse.FileType('r'), help="the list of symbols") +parser.add_argument('-r', '--rootdir', type=str, help="scan the output files to obtain a list of files with unnamed symbols (NOTE: will rebuild objects as necessary)") +args = parser.parse_args() + +# Get list of object files +objects = None +if args.rootdir: + for line in run(["make", "-C", args.rootdir, "-s", "-p"], + capture_output=True).stdout.decode().split("\n"): + if line.startswith("crystal_obj := "): + objects = line[15:].strip().split() + break + else: + print("Error: Object files not found!", file=stderr) + exit(1) + +# Scan all unnamed symbols from the symfile +symbols = set() +for line in args.symfile: + line = line.split(";")[0].strip() + split = line.split(" ") + if len(split) < 2: + continue + + symbol = " ".join(split[1:]).strip() + if symbol[-3:].lower() == split[0][-3:].lower(): + symbols.add(symbol) + +# If no object files were provided, just print what we know and exit +print("Unnamed symbols: %d" % len(symbols)) +if not objects: + for sym in symbols: + print(sym) + exit() + +# Count the amount of symbols in each file +files = {} +for objfile in objects: + f = open(objfile, "rb") + if unpack_file("4s", f)[0] != b'RGB6': + print("Error: File '%s' is of an unknown format." % filename, file=stderr) + exit(1) + + num_symbols = unpack_file(" Date: Tue, 1 Jan 2019 11:41:48 +0100 Subject: unnamed.py: Add completion percentage People love percentages. Gotta show our powerlevel. --- tools/unnamed.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/unnamed.py b/tools/unnamed.py index 205e1efd5..1757ae507 100755 --- a/tools/unnamed.py +++ b/tools/unnamed.py @@ -47,6 +47,7 @@ if args.rootdir: exit(1) # Scan all unnamed symbols from the symfile +symbols_total = 0 symbols = set() for line in args.symfile: line = line.split(";")[0].strip() @@ -54,12 +55,15 @@ for line in args.symfile: if len(split) < 2: continue + symbols_total += 1 + symbol = " ".join(split[1:]).strip() if symbol[-3:].lower() == split[0][-3:].lower(): symbols.add(symbol) # If no object files were provided, just print what we know and exit -print("Unnamed symbols: %d" % len(symbols)) +print("Unnamed symbols: %d (%.2f%% complete)" % (len(symbols), + (symbols_total - len(symbols)) / symbols_total * 100)) if not objects: for sym in symbols: print(sym) -- cgit v1.2.3 From f04f31ea852a36ea94c94bfa9ccaa70a7dfec421 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 1 Jan 2019 12:05:34 +0100 Subject: Add travis webhook for unnamed.py (still requires setup) --- .travis.yml | 2 ++ .travis/webhook.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 .travis/webhook.sh diff --git a/.travis.yml b/.travis.yml index ab3908bb4..ce3402ecf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,5 @@ before_script: script: - make -j2 compare - check_status +after_success: + - .travis/webhook.sh diff --git a/.travis/webhook.sh b/.travis/webhook.sh new file mode 100755 index 000000000..032e2231a --- /dev/null +++ b/.travis/webhook.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Only run this script if it's the master branch build. +[ "$TRAVIS_BRANCH" != 'master' -o "$TRAVIS_PULL_REQUEST" != 'false' ] && exit + +root="$(realpath "$(dirname "$0")/..")" +content="" + +# Report unnamed symbols +content+="$("$root/tools/unnamed.py" -r "$root" "$root/pokecrystal.sym" | grep -v -e '^lib/mobile/' -e '^mobile/' | head)" + +curl -H 'Content-Type: application/json' -X POST "$POKECRYSTAL_DISCORD_WEBHOOK_URL" -d@- << EOF +{ + "username": "$POKECRYSTAL_DISCORD_WEBHOOK_USERNAME", + "avatar_url": "$POKECRYSTAL_DISCORD_WEBHOOK_AVATAR_URL", + "content": "\`\`\`$(echo "$content" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')\`\`\`" +} +EOF -- cgit v1.2.3 From 1bc167379466b67c8b5bd1af311765c8b036c340 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sun, 10 Feb 2019 00:17:19 +0100 Subject: Fix python 3.6 support for unnamed.py --- tools/unnamed.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/unnamed.py b/tools/unnamed.py index 1757ae507..cea500fcd 100755 --- a/tools/unnamed.py +++ b/tools/unnamed.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from sys import stderr, exit -from subprocess import run +from subprocess import Popen, PIPE from struct import unpack, calcsize from enum import Enum @@ -37,8 +37,8 @@ args = parser.parse_args() # Get list of object files objects = None if args.rootdir: - for line in run(["make", "-C", args.rootdir, "-s", "-p"], - capture_output=True).stdout.decode().split("\n"): + for line in Popen(["make", "-C", args.rootdir, "-s", "-p"], + stdout=PIPE).stdout.read().decode().split("\n"): if line.startswith("crystal_obj := "): objects = line[15:].strip().split() break -- cgit v1.2.3