Skip to content

Commit 42633b8

Browse files
committed
Support for embedded .emscripten config
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 05221e7 commit 42633b8

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Current Trunk
2424
unless you use errno defines (like EAGAIN) *and* keep around binaries
2525
compiled with an older version that you link against. In that case, you
2626
should rebuild them. See #9545.
27+
- Emscripten now supports the config file (.emscripten) being placed in the
28+
emscriten directory rather that the current user's home directory.
29+
See #9543
2730

2831
v.1.38.46: 09/25/2019
2932
---------------------

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 emscripen-local .emescripten file is found, use that
243+
# 4. Fall back users home direcotry (~/.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)