From eef42a1e3e5bdbb16c8a272c75a259d1c1046c12 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 20 Sep 2023 10:58:19 +0200 Subject: [PATCH] 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'