@@ -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+
269278if '\n ' in EM_CONFIG :
270279 CONFIG_FILE = None
271280 logger .debug ('EM_CONFIG is specified inline without a file' )
0 commit comments