diff --git a/.gitignore b/.gitignore index 2737d7571932a..ddfb38a36c70d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Config file +.emscripten +.emscripten_sanity +.emscripten_sanity_wasm + # vim/emacs temporary/backup files *~ *.swp diff --git a/ChangeLog.md b/ChangeLog.md index 7813661e565d1..008c7f2a0f25d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -28,7 +28,11 @@ v.1.38.47: 10/02/2019 should rebuild them. See #9545. - Removed build option -s ONLY_MY_CODE as we now have much better solutions for that, like building to a wasm object file or using STANDALONE_WASM - etc. (see https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone). + etc. (see + https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone). + - Emscripten now supports the config file (.emscripten) being placed in the + emscripten directory rather that the current user's home directory. + See #9543 v.1.38.46: 09/25/2019 --------------------- diff --git a/tools/shared.py b/tools/shared.py index 20bf003d285e0..90c4e343725c2 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -231,13 +231,19 @@ def generate_config(path, first_time=False): ''' % (path, abspath, llvm_root, node, __rootpath__), file=sys.stderr) -# 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. - -try: +# 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. +# The search order from the config file is as follows: +# 1. Specified on the command line (--em-config) +# 2. Specified via EM_CONFIG environment variable +# 3. If emscripten-local .emscripten file is found, use that +# 4. Fall back users home directory (~/.emscripten). + +embedded_config = path_from_root('.emscripten') +if '--em-config' in sys.argv: EM_CONFIG = sys.argv[sys.argv.index('--em-config') + 1] # And now remove it from sys.argv skip = False @@ -250,22 +256,25 @@ def generate_config(path, first_time=False): elif skip: skip = False sys.argv = newargs - # 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 Exception: - EM_CONFIG = os.environ.get('EM_CONFIG') - -if EM_CONFIG and not os.path.isfile(EM_CONFIG): - if EM_CONFIG.startswith('-'): - exit_with_error('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config LLVM_ROOT=/path;...') - if '=' not in EM_CONFIG: - exit_with_error('File ' + EM_CONFIG + ' passed to --em-config does not exist!') - else: - EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n' - -if not EM_CONFIG: + if not os.path.isfile(EM_CONFIG): + if EM_CONFIG.startswith('-'): + exit_with_error('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config LLVM_ROOT=/path;...') + if '=' not in EM_CONFIG: + exit_with_error('File ' + EM_CONFIG + ' passed to --em-config does not exist!') + else: + EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n' +elif 'EM_CONFIG' in os.environ: + EM_CONFIG = os.environ['EM_CONFIG'] +elif os.path.exists(embedded_config): + EM_CONFIG = embedded_config +else: EM_CONFIG = '~/.emscripten' + +# 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 + if '\n' in EM_CONFIG: CONFIG_FILE = None logger.debug('EM_CONFIG is specified inline without a file')