Skip to content

Support for embedded .emscripten config #9547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Config file
.emscripten
.emscripten_sanity
.emscripten_sanity_wasm

# vim/emacs temporary/backup files
*~
*.swp
Expand Down
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand Down
53 changes: 31 additions & 22 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down