aboutsummaryrefslogtreecommitdiff
path: root/tools/js_optimizer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/js_optimizer.py')
-rw-r--r--tools/js_optimizer.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index 2ecf3cfb..905ae835 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -57,7 +57,7 @@ class Minifier:
if curr not in INVALID_3: self.names.append(curr)
#print >> sys.stderr, self.names
- def minify_shell(self, shell, minify_whitespace):
+ def minify_shell(self, shell, minify_whitespace, source_map=False):
#print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222"
# Run through js-optimizer.js to find and minify the global symbols
# We send it the globals, which it parses at the proper time. JS decides how
@@ -76,7 +76,12 @@ class Minifier:
f.write('// EXTRA_INFO:' + self.serialize())
f.close()
- output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['minifyWhitespace'] if minify_whitespace else []), stdout=subprocess.PIPE).communicate()[0]
+ output = subprocess.Popen(self.js_engine +
+ [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] +
+ (['minifyWhitespace'] if minify_whitespace else []) +
+ (['--debug'] if source_map else []),
+ stdout=subprocess.PIPE).communicate()[0]
+
assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output
#print >> sys.stderr, "minified SHELL 3333333333333333", output, "\n44444444444444444444"
code, metadata = output.split('// EXTRA_INFO:')
@@ -102,7 +107,7 @@ def run_on_chunk(command):
if DEBUG and not shared.WINDOWS: print >> sys.stderr, '.' # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console.
return filename
-def run_on_js(filename, passes, js_engine, jcache):
+def run_on_js(filename, passes, js_engine, jcache, source_map=False):
if isinstance(jcache, bool) and jcache: jcache = shared.JCache
if jcache: shared.JCache.ensure()
@@ -176,7 +181,7 @@ EMSCRIPTEN_FUNCS();
js = js[start_funcs + len(start_funcs_marker):end_funcs]
minifier = Minifier(js, js_engine)
- asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes).split('EMSCRIPTEN_FUNCS();');
+ asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes, source_map).split('EMSCRIPTEN_FUNCS();');
asm_shell_post = asm_shell_post.replace('});', '})');
pre += asm_shell_pre + '\n' + start_funcs_marker
post = end_funcs_marker + asm_shell_post + post
@@ -212,7 +217,9 @@ EMSCRIPTEN_FUNCS();
total_size = len(js)
js = None
- cores = int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
+ # if we are making source maps, we want our debug numbering to start from the
+ # top of the file, so avoid breaking the JS into chunks
+ cores = 1 if source_map else int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count())
intended_num_chunks = int(round(cores * NUM_CHUNKS_PER_CORE))
chunk_size = min(MAX_CHUNK_SIZE, max(MIN_CHUNK_SIZE, total_size / intended_num_chunks))
@@ -252,7 +259,9 @@ EMSCRIPTEN_FUNCS();
if len(filenames) > 0:
# XXX Use '--nocrankshaft' to disable crankshaft to work around v8 bug 1895, needed for older v8/node (node 0.6.8+ should be ok)
- commands = map(lambda filename: js_engine + [JS_OPTIMIZER, filename, 'noPrintMetadata'] + passes, filenames)
+ commands = map(lambda filename: js_engine +
+ [JS_OPTIMIZER, filename, 'noPrintMetadata'] +
+ (['--debug'] if source_map else []) + passes, filenames)
#print [' '.join(command) for command in commands]
cores = min(cores, filenames)
@@ -320,6 +329,6 @@ EMSCRIPTEN_FUNCS();
return filename
-def run(filename, passes, js_engine, jcache):
- return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache))
+def run(filename, passes, js_engine, jcache, source_map=False):
+ return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, source_map))