Skip to content

Commit 8f2ee09

Browse files
authored
Support for embedded .emscripten config (#9547)
emsdk has always had partial support for this. With this change all emscripten users can take advantage of embedded config. This allows different emscripten installations to have different configuration files since they don't need to share a single config file in the user's home directory. As a followup and plan to make this location the default when generating a new sample config file. See #9543
1 parent 696fb5e commit 8f2ee09

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Config file
2+
.emscripten
3+
.emscripten_sanity
4+
.emscripten_sanity_wasm
5+
16
# vim/emacs temporary/backup files
27
*~
38
*.swp

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ v.1.38.47: 10/02/2019
2828
should rebuild them. See #9545.
2929
- Removed build option -s ONLY_MY_CODE as we now have much better solutions
3030
for that, like building to a wasm object file or using STANDALONE_WASM
31-
etc. (see https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone).
31+
etc. (see
32+
https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone).
33+
- Emscripten now supports the config file (.emscripten) being placed in the
34+
emscripten directory rather that the current user's home directory.
35+
See #9543
3236

3337
v.1.38.46: 09/25/2019
3438
---------------------

tools/shared.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,19 @@ def generate_config(path, first_time=False):
231231
''' % (path, abspath, llvm_root, node, __rootpath__), file=sys.stderr)
232232

233233

234-
# Emscripten configuration is done through the --em-config command line option or
235-
# the EM_CONFIG environment variable. If the specified string value contains newline
236-
# or semicolon-separated definitions, then these definitions will be used to configure
237-
# Emscripten. Otherwise, the string is understood to be a path to a settings
238-
# file that contains the required definitions.
239-
240-
try:
234+
# Emscripten configuration is done through the --em-config command line option
235+
# or the EM_CONFIG environment variable. If the specified string value contains
236+
# newline or semicolon-separated definitions, then these definitions will be
237+
# used to configure Emscripten. Otherwise, the string is understood to be a
238+
# path to a settings file that contains the required definitions.
239+
# The search order from the config file is as follows:
240+
# 1. Specified on the command line (--em-config)
241+
# 2. Specified via EM_CONFIG environment variable
242+
# 3. If emscripten-local .emscripten file is found, use that
243+
# 4. Fall back users home directory (~/.emscripten).
244+
245+
embedded_config = path_from_root('.emscripten')
246+
if '--em-config' in sys.argv:
241247
EM_CONFIG = sys.argv[sys.argv.index('--em-config') + 1]
242248
# And now remove it from sys.argv
243249
skip = False
@@ -250,22 +256,25 @@ def generate_config(path, first_time=False):
250256
elif skip:
251257
skip = False
252258
sys.argv = newargs
253-
# Emscripten compiler spawns other processes, which can reimport shared.py, so make sure that
254-
# those child processes get the same configuration file by setting it to the currently active environment.
255-
os.environ['EM_CONFIG'] = EM_CONFIG
256-
except Exception:
257-
EM_CONFIG = os.environ.get('EM_CONFIG')
258-
259-
if EM_CONFIG and not os.path.isfile(EM_CONFIG):
260-
if EM_CONFIG.startswith('-'):
261-
exit_with_error('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config LLVM_ROOT=/path;...')
262-
if '=' not in EM_CONFIG:
263-
exit_with_error('File ' + EM_CONFIG + ' passed to --em-config does not exist!')
264-
else:
265-
EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n'
266-
267-
if not EM_CONFIG:
259+
if not os.path.isfile(EM_CONFIG):
260+
if EM_CONFIG.startswith('-'):
261+
exit_with_error('Passed --em-config without an argument. Usage: --em-config /path/to/.emscripten or --em-config LLVM_ROOT=/path;...')
262+
if '=' not in EM_CONFIG:
263+
exit_with_error('File ' + EM_CONFIG + ' passed to --em-config does not exist!')
264+
else:
265+
EM_CONFIG = EM_CONFIG.replace(';', '\n') + '\n'
266+
elif 'EM_CONFIG' in os.environ:
267+
EM_CONFIG = os.environ['EM_CONFIG']
268+
elif os.path.exists(embedded_config):
269+
EM_CONFIG = embedded_config
270+
else:
268271
EM_CONFIG = '~/.emscripten'
272+
273+
# Emscripten compiler spawns other processes, which can reimport shared.py, so
274+
# make sure that those child processes get the same configuration file by
275+
# setting it to the currently active environment.
276+
os.environ['EM_CONFIG'] = EM_CONFIG
277+
269278
if '\n' in EM_CONFIG:
270279
CONFIG_FILE = None
271280
logger.debug('EM_CONFIG is specified inline without a file')

0 commit comments

Comments
 (0)