From deacea7d360ec2db1f47a447b6da55f5dca098a6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 8 Sep 2013 14:42:36 -0700 Subject: [PATCH] initial setup for proxying: add option and generate separate html and js --- emcc | 27 ++++++++++++++++++++------- src/proxyClient.js | 5 +++++ src/settings.js | 3 +++ tests/test_browser.py | 3 +++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/proxyClient.js diff --git a/emcc b/emcc index 958ed7cdf..48aa19e74 100755 --- a/emcc +++ b/emcc @@ -471,6 +471,9 @@ Options that are modified or new in %s include: to hide these warnings and acknowledge that the explicit use of absolute paths is intentional. + --proxy-to-worker Generates both html and js files. The main + program is in js, and the html proxies to/from it. + The target file, if specified (-o ), defines what will be generated: @@ -740,6 +743,7 @@ try: save_bc = False memory_init_file = False use_preload_cache = False + proxy_to_worker = False if use_cxx: default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline. @@ -903,6 +907,9 @@ try: memory_init_file = int(newargs[i+1]) newargs[i] = '' newargs[i+1] = '' + elif newargs[i] == '--proxy-to-worker': + proxy_to_worker = True + newargs[i] = '' elif newargs[i].startswith(('-I', '-L')): path_name = newargs[i][2:] if not absolute_warning_shown and os.path.isabs(path_name): @@ -1128,6 +1135,9 @@ try: if shared.Settings.ASM_JS and shared.Settings.DLOPEN_SUPPORT: assert shared.Settings.DISABLE_EXCEPTION_CATCHING, 'no exceptions support with dlopen in asm yet' + if proxy_to_worker: + shared.Settings.PROXY_TO_WORKER = 1 + ## Compile source code to bitcode logging.debug('compiling to bitcode') @@ -1709,7 +1719,11 @@ try: logging.debug('generating HTML') shell = open(shell_path).read() html = open(target, 'w') - if not Compression.on: + if proxy_to_worker: + html.write(shell.replace('{{{ SCRIPT_CODE }}}', open(shared.path_from_root('src', 'proxyClient.js')).read().replace('{{{ filename }}}', target_basename))) + js_target = unsuffixed(target) + '.js' + shutil.copyfile(final, js_target) + elif not Compression.on: if debug_level >= 4: match = re.match('.*?]*>{{{ SCRIPT_CODE }}}', shell, re.DOTALL) @@ -1783,13 +1797,12 @@ try: html.close() else: if split_js_file: - from tools.split import split_javascript_file - split_javascript_file(final, unsuffixed(target), split_js_file) + from tools.split import split_javascript_file + split_javascript_file(final, unsuffixed(target), split_js_file) else: - if debug_level >= 4: generate_source_map(target) - - # copy final JS to output - shutil.move(final, target) + if debug_level >= 4: generate_source_map(target) + # copy final JS to output + shutil.move(final, target) if DEBUG: logging.debug('total time: %.2f seconds' % (time.time() - start_time)) diff --git a/src/proxyClient.js b/src/proxyClient.js new file mode 100644 index 000000000..645ccca6f --- /dev/null +++ b/src/proxyClient.js @@ -0,0 +1,5 @@ + +// proxy to/from worker + +var worker = new Worker('{{{ filename }}}.js'); + diff --git a/src/settings.js b/src/settings.js index 79c54c2b5..1ef0cd581 100644 --- a/src/settings.js +++ b/src/settings.js @@ -343,6 +343,9 @@ var RUNTIME_LINKED_LIBS = []; // If this is a main file (BUILD_AS_SHARED_LIB == // linked libraries can break things. var BUILD_AS_WORKER = 0; // If set to 1, this is a worker library, a special kind of library // that is run in a worker. See emscripten.h +var PROXY_TO_WORKER = 0; // If set to 1, we build the project into a js file that will run + // in a worker, and generate an html file that proxies input and + // output to/from it. var LINKABLE = 0; // If set to 1, this file can be linked with others, either as a shared // library or as the main file that calls a shared library. To enable that, // we will not internalize all symbols and cull the unused ones, in other diff --git a/tests/test_browser.py b/tests/test_browser.py index 3ac640f13..59c50acab 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -627,6 +627,9 @@ If manually bisecting: Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_canvas.c'), '-o', 'page.html', '-s', 'LEGACY_GL_EMULATION=1']).communicate() self.run_browser('page.html', '', '/report_result?1') + def test_sdl_canvas_proxy(self): + self.btest('sdl_canvas.c', '1', args=['--proxy-to-worker']) + def test_sdl_key(self): open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' Module.postRun = function() {