From 53ff42836cfe0b4035dc71399f75f4176e0b7abd Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 20 Sep 2023 10:36:21 +0200 Subject: [PATCH 1/3] tools: rarezip: use system gzip on non-linux --- tools/rarezip | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/rarezip b/tools/rarezip index f53e5d2a6..0429c5cb7 100755 --- a/tools/rarezip +++ b/tools/rarezip @@ -6,4 +6,13 @@ test $size -gt 0 || exit 0 printf "0: 1173 %.6x" $size | xxd -r -g0 -tools/gzip -c --no-name --best $1 | head --bytes=-8 | tail --bytes=+11 +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # use supplied gzip 1.2.4 for Linux + gzipbin="tools/gzip" +else + # use system gzip on other systems + # NOTE: this might result in a non-matching file, but we don't really care + gzipbin="gzip -f" +fi + +$gzipbin -c --no-name --best $1 | head --bytes=-8 | tail --bytes=+11 From eef42a1e3e5bdbb16c8a272c75a259d1c1046c12 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 20 Sep 2023 10:58:19 +0200 Subject: [PATCH 2/3] tools: assetmgr: allow writing raw binary instead of ELF; fix zip() on windows use --raw-out filename to get the raw output (zipped if applicable) --- tools/assetmgr/assetmgr.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/assetmgr/assetmgr.py b/tools/assetmgr/assetmgr.py index d6d644476..0db3935e3 100644 --- a/tools/assetmgr/assetmgr.py +++ b/tools/assetmgr/assetmgr.py @@ -1,4 +1,6 @@ import os +import sys +import tempfile import subprocess def align4(value): @@ -44,6 +46,17 @@ def write_enums(typename, names, filename, terminator, start=0): fd.close() def write_object(data, filename): + if '--raw-out' in sys.argv: + # write the raw data into a user-specified file instead + idx = sys.argv.index('--raw-out') + if idx + 1 < len(sys.argv): + filename = sys.argv[idx + 1] + fd = open(filename, 'wb') + fd.write(data) + fd.close() + print('wrote binary to', filename) + return + filename = 'build/%s/assets/%s' % (os.environ['ROMID'], filename) mkpath(filename) fd = open(filename, 'wb') @@ -107,13 +120,24 @@ def write_object(data, filename): fd.close() def zip(data): - filename = '/tmp/pd-assetmgr-%d' % os.getpid() + if 'win32' in sys.platform or 'cygwin' in sys.platform: + filename = os.path.join(tempfile.gettempdir(), 'pd-assetmgr-%d' % os.getpid()) + else: + filename = '/tmp/pd-assetmgr-%d' % os.getpid() fd = open(filename, 'wb') fd.write(data) fd.close() - stream = subprocess.check_output(['tools/gzip', '-c', '--no-name', '--best', filename])[10:-8] + if sys.platform.startswith('linux'): + # on Linux use supplied gzip 1.2.4 + gzip_args = ['tools/gzip', '-c', '--no-name', '--best', filename] + else: + # on other platforms use system gzip + # NOTE: this might result in a non-matching file, but we don't really care + gzip_args = ['gzip', '-f', '-c', '--no-name', '--best', filename] + + stream = subprocess.check_output(gzip_args)[10:-8] os.remove(filename) return b'\x11\x73' + len(data).to_bytes(3, 'big') + stream @@ -129,3 +153,7 @@ def writefile(filename, contents): fd = open(filename, 'wb') fd.write(contents) fd.close() + +if 'ROMID' not in os.environ: + # default to ntsc-final + os.environ['ROMID'] = 'ntsc-final' From b2cb5c1737493c9dbd637ed6f04ead996affe9b3 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 20 Sep 2023 11:19:36 +0200 Subject: [PATCH 3/3] tools: assetmgr: move --raw-out into a separate function --- tools/assetmgr/assetmgr.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/assetmgr/assetmgr.py b/tools/assetmgr/assetmgr.py index 0db3935e3..bfc859057 100644 --- a/tools/assetmgr/assetmgr.py +++ b/tools/assetmgr/assetmgr.py @@ -45,17 +45,19 @@ def write_enums(typename, names, filename, terminator, start=0): fd.close() +def write_data(data): + idx = sys.argv.index('--raw-out') + filename = sys.argv[idx + 1] + print('writing binary to', filename) + fd = open(filename, 'wb') + fd.write(data) + fd.close() + def write_object(data, filename): if '--raw-out' in sys.argv: # write the raw data into a user-specified file instead - idx = sys.argv.index('--raw-out') - if idx + 1 < len(sys.argv): - filename = sys.argv[idx + 1] - fd = open(filename, 'wb') - fd.write(data) - fd.close() - print('wrote binary to', filename) - return + write_data(data) + return filename = 'build/%s/assets/%s' % (os.environ['ROMID'], filename) mkpath(filename)