diff --git a/tools/config.py b/tools/config.py index 18640735a35aa..37eb8474421f2 100644 --- a/tools/config.py +++ b/tools/config.py @@ -77,6 +77,12 @@ def set_config_from_tool_location(config_key, tool_binary, f): exit_with_error('%s is set to empty value in %s', config_key, EM_CONFIG) +def expandvars(value): + if type(value) == list: + return [expandvars(v) for v in value] + return os.path.expandvars(value) + + def parse_config_file(): """Parse the emscripten config file using python's exec. @@ -84,6 +90,7 @@ def parse_config_file(): """ config = {'__file__': EM_CONFIG} config_text = utils.read_file(EM_CONFIG) + os.environ['EM_CONFIG_DIR'] = os.path.dirname(EM_CONFIG) try: exec(config_text, config) except Exception as e: @@ -132,7 +139,7 @@ def parse_config_file(): exit_with_error(f'environment variable {env_var} must be an absolute path: {env_value}') globals()[key] = env_value elif key in config: - globals()[key] = config[key] + globals()[key] = expandvars(config[key]) def read_config(): diff --git a/tools/config_template.py b/tools/config_template.py index 195593ccefa7f..a77107533f09b 100644 --- a/tools/config_template.py +++ b/tools/config_template.py @@ -1,8 +1,9 @@ # This file will be edited (the {{{ }}} things), and written to `.emscripten` # when emscripten is first used and no config file is found. -# Note: If you put paths relative to the home directory, do not forget -# os.path.expanduser +# Note: Use can use environment variables in your settings, e.g. use `$HOME` +# for paths relative to the home directory. You can also use `$EM_CONFIG_DIR` +# for the directory where the config file lives. # # Any config setting in this file can be overridden by setting the # EM_ environment variable. For example, settings EM_LLVM_ROOT override @@ -34,9 +35,8 @@ # # JS_ENGINES = [NODE_JS_TEST] # add V8_ENGINE or SPIDERMONKEY_ENGINE if you have them installed too. # -# import os -# WASMER = os.path.expanduser(os.path.join('~', '.wasmer', 'bin', 'wasmer')) -# WASMTIME = os.path.expanduser(os.path.join('~', 'wasmtime')) +# WASMER = '$HOME/.wasmer/bin/wasmer' +# WASMTIME = '$HOME/wasmtime' # # Wasm engines to use in STANDALONE_WASM tests. #