Skip to content

Commit 4315e62

Browse files
authored
Minor refactor find_config_file. NFC (#25629)
Avoids calculating paths that are not needed in all cases.
1 parent 8462d7a commit 4315e62

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tools/config.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,21 @@ def find_config_file():
223223
# see below)
224224
# 5. User home directory config (~/.emscripten), if found.
225225

226+
if '--em-config' in sys.argv:
227+
i = sys.argv.index('--em-config')
228+
if len(sys.argv) <= i + 1:
229+
exit_with_error('--em-config must be followed by a filename')
230+
del sys.argv[i]
231+
# Now the i'th argument is the emconfig filename
232+
return sys.argv.pop(i)
233+
234+
if 'EM_CONFIG' in os.environ:
235+
return os.environ['EM_CONFIG']
236+
226237
embedded_config = path_from_root('.emscripten')
238+
if os.path.isfile(embedded_config):
239+
return embedded_config
240+
227241
# For compatibility with `emsdk --embedded` mode also look two levels up. The
228242
# layout of the emsdk puts emcc two levels below emsdk. For example:
229243
# - emsdk/upstream/emscripten/emcc
@@ -238,25 +252,11 @@ def find_config_file():
238252
# See: https://github.com/emscripten-core/emsdk/pull/367
239253
emsdk_root = os.path.dirname(os.path.dirname(path_from_root()))
240254
emsdk_embedded_config = os.path.join(emsdk_root, '.emscripten')
241-
user_home_config = os.path.expanduser('~/.emscripten')
242-
243-
if '--em-config' in sys.argv:
244-
i = sys.argv.index('--em-config')
245-
if len(sys.argv) <= i + 1:
246-
exit_with_error('--em-config must be followed by a filename')
247-
del sys.argv[i]
248-
# Now the i'th argument is the emconfig filename
249-
return sys.argv.pop(i)
250-
251-
if 'EM_CONFIG' in os.environ:
252-
return os.environ['EM_CONFIG']
253-
254-
if os.path.isfile(embedded_config):
255-
return embedded_config
256255

257256
if os.path.isfile(emsdk_embedded_config):
258257
return emsdk_embedded_config
259258

259+
user_home_config = os.path.expanduser('~/.emscripten')
260260
if os.path.isfile(user_home_config):
261261
return user_home_config
262262

0 commit comments

Comments
 (0)