aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-05-27 14:58:31 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-05-27 16:08:23 -0700
commitdeaf15da8488537086332cc5c64c4bf0bbf49460 (patch)
tree123bc5a654a6a9d407a36318668c50bbdd3773f3
parenta9798715cf9414f4656b349c7f7f9ad2db1b2bd2 (diff)
clean up shell code using uglify, in optimized builds, when not using closure
-rwxr-xr-xemcc7
-rw-r--r--tests/test_other.py6
-rw-r--r--tools/js_optimizer.py28
3 files changed, 29 insertions, 12 deletions
diff --git a/emcc b/emcc
index 342af478..be987980 100755
--- a/emcc
+++ b/emcc
@@ -1794,8 +1794,11 @@ try:
if emit_symbol_map: js_optimizer_queue += ['symbolMap='+target+'.symbols']
if debug_level == 0: js_optimizer_queue += ['minifyWhitespace']
- if closure and shared.Settings.ASM_JS:
- js_optimizer_queue += ['closure']
+ if shared.Settings.ASM_JS:
+ if closure:
+ js_optimizer_queue += ['closure']
+ elif debug_level <= 2 and not shared.Settings.MAIN_MODULE and not shared.Settings.SIDE_MODULE:
+ js_optimizer_queue += ['cleanup']
if not shared.Settings.SIDE_MODULE: js_optimizer_queue += ['last'] # side modules are not finalized until after relocation
diff --git a/tests/test_other.py b/tests/test_other.py
index 12dd7872..03859a4e 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -203,6 +203,10 @@ Options that are modified or new in %s include:
(['--typed-arrays', '1'], lambda generated: 'IHEAPU = ' in generated, 'typed arrays 1 selected'),
(['--typed-arrays', '2'], lambda generated: 'new Uint16Array' in generated and 'new Uint32Array' in generated, 'typed arrays 2 selected'),
(['--llvm-opts', '1'], lambda generated: '_puts(' in generated, 'llvm opts requested'),
+ ([], lambda generated: '// The Module object' in generated, 'without opts, comments in shell code'),
+ (['-O2'], lambda generated: '// The Module object' not in generated, 'with opts, no comments in shell code'),
+ (['-O2', '-g2'], lambda generated: '// The Module object' not in generated, 'with -g2, no comments in shell code'),
+ (['-O2', '-g3'], lambda generated: '// The Module object' in generated, 'with -g3, yes comments in shell code'),
]:
print params, text
self.clear()
@@ -2218,7 +2222,7 @@ void wakaw::Cm::RasterBase<wakaw::watwat::Polocator?>(unsigned int*, unsigned in
test_js_closure_0 = open(path_from_root('tests', 'Module-exports', 'test.js')).read()
# Check that test.js compiled with --closure 0 contains "module['exports'] = Module;"
- assert "module['exports'] = Module;" in test_js_closure_0
+ assert ("module['exports'] = Module;" in test_js_closure_0) or ('module["exports"]=Module' in test_js_closure_0)
# Check that main.js (which requires test.js) completes successfully when run in node.js
# in order to check that the exports are indeed functioning correctly.
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index d0284528..e06c2d2f 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -137,6 +137,10 @@ def run_on_js(filename, passes, js_engine, jcache, source_map=False, extra_info=
if closure:
passes = filter(lambda p: p != 'closure', passes) # we will do it manually
+ cleanup = 'cleanup' in passes
+ if cleanup:
+ passes = filter(lambda p: p != 'cleanup', passes) # we will do it manually
+
if not know_generated and jcache:
# JCache cannot be used without metadata, since it might reorder stuff, and that's dangerous since only generated can be reordered
# This means jcache does not work after closure compiler runs, for example. But you won't get much benefit from jcache with closure
@@ -291,23 +295,29 @@ EMSCRIPTEN_FUNCS();
for filename in filenames: temp_files.note(filename)
- if closure:
- # run closure on the shell code, everything but what we js-optimize
+ if closure or cleanup:
+ # run on the shell code, everything but what we js-optimize
start_asm = '// EMSCRIPTEN_START_ASM\n'
end_asm = '// EMSCRIPTEN_END_ASM\n'
- closure_sep = 'wakaUnknownBefore(); var asm=wakaUnknownAfter(global,env,buffer)\n'
+ cl_sep = 'wakaUnknownBefore(); var asm=wakaUnknownAfter(global,env,buffer)\n'
- closuree = temp_files.get('.closure.js').name
- c = open(closuree, 'w')
+ cle = temp_files.get('.cl.js').name
+ c = open(cle, 'w')
pre_1, pre_2 = pre.split(start_asm)
post_1, post_2 = post.split(end_asm)
c.write(pre_1)
- c.write(closure_sep)
+ c.write(cl_sep)
c.write(post_2)
c.close()
- closured = shared.Building.closure_compiler(closuree, pretty='minifyWhitespace' not in passes)
- temp_files.note(closured)
- coutput = open(closured).read()
+ if closure:
+ if DEBUG: print >> sys.stderr, 'running closure on shell code'
+ cld = shared.Building.closure_compiler(cle, pretty='minifyWhitespace' not in passes)
+ else:
+ if DEBUG: print >> sys.stderr, 'running cleanup on shell code'
+ cld = cle + '.js'
+ subprocess.Popen(js_engine + [JS_OPTIMIZER, cle, 'noPrintMetadata'] + (['minifyWhitespace'] if 'minifyWhitespace' in passes else []), stdout=open(cld, 'w')).communicate()
+ temp_files.note(cld)
+ coutput = open(cld).read()
coutput = coutput.replace('wakaUnknownBefore();', '')
after = 'wakaUnknownAfter'
start = coutput.find(after)