Skip to content

Commit e0c3ce6

Browse files
authored
Use isfile rather than exists when checking for config files (#21361)
This avoids trying parse non-files. Also, explicitly log when we are not using a config file at all.
1 parent 71c3d00 commit e0c3ce6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

emcc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def apply_user_settings():
261261
filename = None
262262
if value and value[0] == '@':
263263
filename = removeprefix(value, '@')
264-
if not os.path.exists(filename):
264+
if not os.path.isfile(filename):
265265
exit_with_error('%s: file not found parsing argument: %s=%s' % (filename, key, value))
266266
value = read_file(filename).strip()
267267
else:
@@ -612,7 +612,7 @@ def run(args):
612612
libname = print_file_name[-1].split('=')[1]
613613
system_libpath = cache.get_lib_dir(absolute=True)
614614
fullpath = os.path.join(system_libpath, libname)
615-
if os.path.exists(fullpath):
615+
if os.path.isfile(fullpath):
616616
print(fullpath)
617617
else:
618618
print(libname)

tools/config.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def set_config_from_tool_location(config_key, tool_binary, f):
9999
if val is None:
100100
path = shutil.which(tool_binary)
101101
if not path:
102-
if not os.path.exists(EM_CONFIG):
102+
if not os.path.isfile(EM_CONFIG):
103103
diagnostics.warn('config file not found: %s. You can create one by hand or run `emcc --generate-config`', EM_CONFIG)
104104
exit_with_error('%s not set in config (%s), and `%s` not found in PATH', config_key, EM_CONFIG, tool_binary)
105105
globals()[config_key] = f(path)
@@ -155,11 +155,11 @@ def parse_config_file():
155155

156156

157157
def read_config():
158-
if os.path.exists(EM_CONFIG):
158+
if os.path.isfile(EM_CONFIG):
159159
parse_config_file()
160160

161-
# In the past the default-generated .emscripten config file would read certain environment
162-
# variables.
161+
# In the past the default-generated .emscripten config file would read
162+
# certain environment variables.
163163
LEGACY_ENV_VARS = {
164164
'LLVM': 'EM_LLVM_ROOT',
165165
'BINARYEN': 'EM_BINARYEN_ROOT',
@@ -172,7 +172,8 @@ def read_config():
172172
env_value = os.environ.get(key)
173173
if env_value and new_key not in os.environ:
174174
msg = f'legacy environment variable found: `{key}`. Please switch to using `{new_key}` instead`'
175-
# Use `debug` instead of `warning` for `NODE` specifically since there can be false positives:
175+
# Use `debug` instead of `warning` for `NODE` specifically
176+
# since there can be false positives:
176177
# See https://github.com/emscripten-core/emsdk/issues/862
177178
if key == 'NODE':
178179
logger.debug(msg)
@@ -266,13 +267,13 @@ def find_config_file():
266267
if 'EM_CONFIG' in os.environ:
267268
return os.environ['EM_CONFIG']
268269

269-
if os.path.exists(embedded_config):
270+
if os.path.isfile(embedded_config):
270271
return embedded_config
271272

272-
if os.path.exists(emsdk_embedded_config):
273+
if os.path.isfile(emsdk_embedded_config):
273274
return emsdk_embedded_config
274275

275-
if os.path.exists(user_home_config):
276+
if os.path.isfile(user_home_config):
276277
return user_home_config
277278

278279
# No config file found. Return the default location.
@@ -292,13 +293,17 @@ def init():
292293

293294
EM_CONFIG = os.path.expanduser(EM_CONFIG)
294295

295-
# This command line flag needs to work even in the absence of a config file, so we must process it
296-
# here at script import time (otherwise the error below will trigger).
296+
# This command line flag needs to work even in the absence of a config
297+
# file, so we must process it here at script import time (otherwise
298+
# the error below will trigger).
297299
if '--generate-config' in sys.argv:
298300
generate_config(EM_CONFIG)
299301
sys.exit(0)
300302

301-
logger.debug('emscripten config is located in ' + EM_CONFIG)
303+
if os.path.isfile(EM_CONFIG):
304+
logger.debug(f'using config file: ${EM_CONFIG}')
305+
else:
306+
logger.debug('config file not found; using default config')
302307

303308
# Emscripten compiler spawns other processes, which can reimport shared.py, so
304309
# make sure that those child processes get the same configuration file by

0 commit comments

Comments
 (0)