aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorÉloi Rivard <azmeuk@gmail.com>2013-04-12 02:05:52 +0200
committerÉloi Rivard <azmeuk@gmail.com>2013-04-13 16:06:57 +0200
commit06876b9f0ef559553afb708462042fbade0a33c4 (patch)
treedc459fcce5152f67cb9e6e3bdf5818ceee0844c8 /tools
parent74e74ba24278a3e96a9e4dceaaf814e587ea5d0f (diff)
* Little improvements of file_packager.py
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 73ff4919..8a7cca85 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -11,7 +11,7 @@ data downloads.
Usage:
- file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA] [--pre-run] [--crunch[=X]]
+ file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA] [--pre-run] [--crunch[=X]] [--js-output=OUTPUT.js]
--pre-run Will generate wrapper code that does preloading in Module.preRun. This is necessary if you add this
code before the main file has been loading, which includes necessary components like addRunDependency.
@@ -39,6 +39,11 @@ import shared
from shared import Compression, execute, suffix, unsuffixed
from subprocess import Popen, PIPE, STDOUT
+if len(sys.argv) == 1:
+ print '''Usage: file_packager.py TARGET [--preload A...] [--embed C...] [--compress COMPRESSION_DATA] [--pre-run] [--crunch[=X]] [--js-output=OUTPUT.js]
+See the source for more details.'''
+ sys.exit(0)
+
data_target = sys.argv[1]
IMAGE_SUFFIXES = ('.jpg', '.png', '.bmp')
@@ -59,6 +64,7 @@ in_compress = 0
pre_run = False
crunch = 0
plugins = []
+jsoutput = None
for arg in sys.argv[1:]:
if arg == '--preload':
@@ -80,6 +86,8 @@ for arg in sys.argv[1:]:
in_preload = False
in_embed = False
in_compress = 0
+ elif arg.startswith('--js-output'):
+ jsoutput = arg.split('=')[1] if '=' in arg else None
elif arg.startswith('--crunch'):
from shared import CRUNCH
crunch = arg.split('=')[1] if '=' in arg else '128'
@@ -93,9 +101,11 @@ for arg in sys.argv[1:]:
in_embed = False
in_compress = 0
elif in_preload:
- data_files.append({ 'name': arg, 'mode': 'preload' })
+ if os.path.isfile(arg):
+ data_files.append({ 'name': arg, 'mode': 'preload' })
elif in_embed:
- data_files.append({ 'name': arg, 'mode': 'embed' })
+ if os.path.isfile(arg):
+ data_files.append({ 'name': arg, 'mode': 'embed' })
elif in_compress:
if in_compress == 1:
Compression.encoder = arg
@@ -107,7 +117,7 @@ for arg in sys.argv[1:]:
Compression.js_name = arg
in_compress = 0
-print '''
+ret = '''
(function() {
'''
@@ -152,7 +162,7 @@ for file_ in data_files:
# Crunch files
if crunch:
shutil.copyfile(shared.path_from_root('tools', 'crunch-worker.js'), 'crunch-worker.js')
- print '''
+ ret += '''
var decrunchWorker = new Worker('crunch-worker.js');
var decrunchCallbacks = [];
decrunchWorker.onmessage = function(msg) {
@@ -386,26 +396,30 @@ if has_preloaded:
''' % (data_target, os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target), use_data, data_target) # use basename because from the browser's point of view, we need to find the datafile in the same dir as the html file
if pre_run:
- print '''
+ ret += '''
if (typeof Module == 'undefined') Module = {};
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(function() {
'''
-
-print code
+ret += code
if pre_run:
- print ' });\n'
+ ret += ' });\n'
if crunch:
- print '''
+ ret += '''
if (!Module['postRun']) Module['postRun'] = [];
Module["postRun"].push(function() {
decrunchWorker.terminate();
});
'''
-print '''
+ret += '''
})();
'''
+if jsoutput == None:
+ print ret
+else:
+ f = open(jsoutput, 'w')
+ f.write(ret)