forked from Ports/perfect_dark
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)
This commit is contained in:
1 parent
53ff42836c
commit
eef42a1e3e
1 file changed
+30
-2
@@ -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'
|
||||
Reference in new issue
Block a user