diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 3 | ||||
-rw-r--r-- | tools/js_optimizer.py | 26 | ||||
-rw-r--r-- | tools/shared.py | 4 |
3 files changed, 29 insertions, 4 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index ce67da89..32ed1cce 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2408,7 +2408,8 @@ var passes = { compress: function() { compress = true }, noPrintMetadata: function() { printMetadata = false }, asm: function() { asm = true }, - last: function() { last = true } + last: function() { last = true }, + closure: function(){} // handled in python }; // Main diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index b11d0449..0452a725 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -129,7 +129,7 @@ def run_on_js(filename, passes, js_engine, jcache): end_funcs_marker = '// EMSCRIPTEN_END_FUNCS\n' start_funcs = js.find(start_funcs_marker) end_funcs = js.rfind(end_funcs_marker) - assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix) + #assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix) asm_registerize = 'asm' in passes and 'registerize' in passes if asm_registerize: start_asm_marker = '// EMSCRIPTEN_START_ASM\n' @@ -265,6 +265,30 @@ EMSCRIPTEN_FUNCS(); for filename in filenames: temp_files.note(filename) + if 'closure' in passes: + # run closure 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' + + closuree = temp_files.get('.closure.js').name + c = open(closuree, '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(post_2) + c.close() + closured = shared.Building.closure_compiler(closuree, pretty='compress' not in passes) + temp_files.note(closured) + coutput = open(closured).read() + coutput = coutput.replace('wakaUnknownBefore();', '') + after = 'wakaUnknownAfter' + start = coutput.find(after) + end = coutput.find(')', start) + pre = coutput[:start] + '(function(global,env,buffer) {\n' + start_asm + pre_2[pre_2.find('{')+1:] + post = post_1[:post_1.rfind('}')] + '\n' + end_asm + '\n})' + coutput[end+1:] + filename += '.jo.js' f = open(filename, 'w') f.write(pre); diff --git a/tools/shared.py b/tools/shared.py index 228f1253..321fa073 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1208,7 +1208,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e return js_optimizer.run(filename, passes, listify(NODE_JS), jcache) @staticmethod - def closure_compiler(filename): + def closure_compiler(filename, pretty=True): if not os.path.exists(CLOSURE_COMPILER): raise Exception('Closure compiler appears to be missing, looked at: ' + str(CLOSURE_COMPILER)) @@ -1218,10 +1218,10 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e '-Xmx' + (os.environ.get('JAVA_HEAP_SIZE') or '1024m'), # if you need a larger Java heap, use this environment variable '-jar', CLOSURE_COMPILER, '--compilation_level', 'ADVANCED_OPTIMIZATIONS', - '--formatting', 'PRETTY_PRINT', '--language_in', 'ECMASCRIPT5', #'--variable_map_output_file', filename + '.vars', '--js', filename, '--js_output_file', filename + '.cc.js'] + if pretty: args += ['--formatting', 'PRETTY_PRINT'] if os.environ.get('EMCC_CLOSURE_ARGS'): args += shlex.split(os.environ.get('EMCC_CLOSURE_ARGS')) process = Popen(args, stdout=PIPE, stderr=STDOUT) |