diff options
-rwxr-xr-x | emcc | 11 | ||||
-rw-r--r-- | tests/test_sanity.py | 28 | ||||
-rw-r--r-- | tools/shared.py | 23 |
3 files changed, 58 insertions, 4 deletions
@@ -504,6 +504,12 @@ Options that are modified or new in %s include: and exit(returncode) capture when running the generated application through emrun. + --em-config Specifies the location of the .emscripten configuration + file for the current compiler run. If not specified, + the environment variable EM_CONFIG is read for this + file, and if that is not set, the default location + ~/.emscripten is assumed. + The target file, if specified (-o <target>), defines what will be generated: @@ -972,6 +978,11 @@ try: elif newargs[i] == '--emrun': emrun = True newargs[i] = '' + elif newargs[i] == '--em-config': + # This option is parsed in tools/shared.py, here only clean it up from being passed to clang. + newargs[i] = '' + newargs[i+1] = '' + newargs = [ arg for arg in newargs if arg is not '' ] # If user did not specify a default -std for C++ code, specify the emscripten default. diff --git a/tests/test_sanity.py b/tests/test_sanity.py index c7dd86e4..dc3d53db 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -548,3 +548,31 @@ fi if old: os.environ['EMCC_LLVM_TARGET'] = old + def test_emconfig(self): + restore() + + (fd, custom_config_filename) = tempfile.mkstemp(prefix='.emscripten_config_') + + orig_config = open(CONFIG_FILE, 'r').read() + + # Move the ~/.emscripten to a custom location. + tfile = os.fdopen(fd, "w") + tfile.write(orig_config) + tfile.close() + + # Make a syntax error in the original config file so that attempting to access it would fail. + open(CONFIG_FILE, 'w').write('asdfasdfasdfasdf\n\'\'\'' + orig_config) + + temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_') + + os.chdir(temp_dir) + self.do([EMCC, '-O2', '--em-config', custom_config_filename, path_from_root('tests', 'hello_world.c')]) + result = run_js('a.out.js') + + # Clean up created temp files. + os.remove(custom_config_filename) + os.chdir(path_from_root()) + shutil.rmtree(temp_dir) + + self.assertContained('hello, world!', result) + diff --git a/tools/shared.py b/tools/shared.py index cbeb3eda..443ff4c7 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -176,13 +176,28 @@ if WINDOWS: else: logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit) -# Emscripten configuration is done through the EM_CONFIG environment variable. -# If the string value contained in this environment variable contains newline -# separated definitions, then these definitions will be used to configure +# Emscripten configuration is done through the --em-config command line option or +# the EM_CONFIG environment variable. If the specified string value contains newline +# or semicolon-separated definitions, then these definitions will be used to configure # Emscripten. Otherwise, the string is understood to be a path to a settings # file that contains the required definitions. -EM_CONFIG = os.environ.get('EM_CONFIG') +try: + EM_CONFIG = sys.argv[sys.argv.index('--em-config')+1] + # Emscripten compiler spawns other processes, which can reimport shared.py, so make sure that + # those child processes get the same configuration file by setting it to the currently active environment. + os.environ['EM_CONFIG'] = EM_CONFIG +except: + EM_CONFIG = os.environ.get('EM_CONFIG') + +if EM_CONFIG and not os.path.isfile(EM_CONFIG): + if EM_CONFIG.startswith('-'): + raise Exception('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config EMSCRIPTEN_ROOT=/path/;LLVM_ROOT=/path;...') + if not '=' in EM_CONFIG: + raise Exception('File ' + EM_CONFIG + ' passed to --em-config does not exist!') + else: + EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n' + if not EM_CONFIG: EM_CONFIG = '~/.emscripten' if '\n' in EM_CONFIG: |