Skip to content

Commit 0fc1347

Browse files
committed
Rename settings_key_changes to settings_map and reuse it apply_settings. NFC
1 parent 2654899 commit 0fc1347

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

emcc.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def expand_byte_size_suffixes(value):
330330

331331

332332
def apply_settings(changes):
333-
"""Take a list of settings in form `NAME=VALUE` and apply them to the global
333+
"""Take a map of users settings {NAME: VALUE} and apply them to the global
334334
Settings object.
335335
"""
336336

@@ -344,8 +344,7 @@ def standardize_setting_change(key, value):
344344
value = str(1 - int(value))
345345
return key, value
346346

347-
for change in changes:
348-
key, value = change.split('=', 1)
347+
for key, value in changes.items():
349348
key, value = standardize_setting_change(key, value)
350349

351350
if key in shared.Settings.internal_settings:
@@ -365,14 +364,14 @@ def standardize_setting_change(key, value):
365364
if value and value[0] == '@':
366365
filename = value[1:]
367366
if not os.path.exists(filename):
368-
exit_with_error('%s: file not found parsing argument: %s' % (filename, change))
367+
exit_with_error('%s: file not found parsing argument: %=%s' % (filename, key, value))
369368
value = open(filename).read()
370369
else:
371370
value = value.replace('\\', '\\\\')
372371
try:
373372
value = parse_value(value)
374373
except Exception as e:
375-
exit_with_error('a problem occurred in evaluating the content after a "-s", specifically "%s": %s', change, str(e))
374+
exit_with_error('a problem occurred in evaluating the content after a "-s", specifically "%s=%s": %s', key, change, str(e))
376375

377376
# Do some basic type checking by comparing to the existing settings.
378377
# Sadly we can't do this generically in the SettingsManager since there are settings
@@ -1138,15 +1137,15 @@ def add_link_flag(i, f):
11381137
newargs[i] = ''
11391138
newargs = [a for a in newargs if a]
11401139

1141-
settings_key_changes = {}
1140+
settings_map = {}
11421141
for s in settings_changes:
11431142
key, value = s.split('=', 1)
1144-
settings_key_changes[key] = value
1143+
settings_map[key] = value
11451144

11461145
# Libraries are searched before settings_changes are applied, so apply the
11471146
# value for STRICT from command line already now.
11481147

1149-
strict_cmdline = settings_key_changes.get('STRICT')
1148+
strict_cmdline = settings_map.get('STRICT')
11501149
if strict_cmdline:
11511150
shared.Settings.STRICT = int(strict_cmdline)
11521151

@@ -1155,15 +1154,15 @@ def add_link_flag(i, f):
11551154

11561155
# For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
11571156
# want to opt out of ERROR_ON_UNDEFINED_SYMBOLS.
1158-
if settings_key_changes.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
1157+
if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
11591158
shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS = 0
11601159

1161-
if shared.Settings.MINIMAL_RUNTIME or settings_key_changes.get('MINIMAL_RUNTIME') in ('1', '2'):
1160+
if shared.Settings.MINIMAL_RUNTIME or settings_map.get('MINIMAL_RUNTIME') in ('1', '2'):
11621161
# Remove the default exported functions 'malloc', 'free', etc. those should only be linked in if used
11631162
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = []
11641163

11651164
# Apply -s settings in newargs here (after optimization levels, so they can override them)
1166-
apply_settings(settings_changes)
1165+
apply_settings(settings_map)
11671166

11681167
specified_target = options.output_file
11691168

@@ -1277,7 +1276,7 @@ def add_link_flag(i, f):
12771276
# reactor.
12781277
# 2. If the user doesn't export anything we default to exporting `_main` (unless `--no-entry`
12791278
# is specified (see above).
1280-
if 'EXPORTED_FUNCTIONS' in settings_key_changes:
1279+
if 'EXPORTED_FUNCTIONS' in settings_map:
12811280
if '_main' not in shared.Settings.USER_EXPORTED_FUNCTIONS:
12821281
shared.Settings.EXPECT_MAIN = 0
12831282
else:
@@ -1289,7 +1288,7 @@ def add_link_flag(i, f):
12891288
# See https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md
12901289
# For a command we always want EXIT_RUNTIME=1
12911290
# For a reactor we always want EXIT_RUNTIME=0
1292-
if 'EXIT_RUNTIME' in settings_key_changes:
1291+
if 'EXIT_RUNTIME' in settings_map:
12931292
exit_with_error('Explictly setting EXIT_RUNTIME not compatible with STANDALONE_WASM. EXIT_RUNTIME will always be True for programs (with a main function) and False for reactors (not main function).')
12941293
shared.Settings.EXIT_RUNTIME = shared.Settings.EXPECT_MAIN
12951294

@@ -1332,7 +1331,7 @@ def filter_out_duplicate_dynamic_libs(inputs):
13321331
building.user_requested_exports = shared.Settings.EXPORTED_FUNCTIONS[:]
13331332

13341333
def default_setting(name, new_default):
1335-
if name not in settings_key_changes:
1334+
if name not in settings_map:
13361335
setattr(shared.Settings, name, new_default)
13371336

13381337
# -s ASSERTIONS=1 implies basic stack overflow checks, and ASSERTIONS=2
@@ -1774,7 +1773,7 @@ def check_memory_setting(setting):
17741773

17751774
if shared.Settings.EXPORT_ES6 and not shared.Settings.MODULARIZE:
17761775
# EXPORT_ES6 requires output to be a module
1777-
if 'MODULARIZE' in settings_key_changes:
1776+
if 'MODULARIZE' in settings_map:
17781777
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
17791778
shared.Settings.MODULARIZE = 1
17801779

@@ -1847,7 +1846,7 @@ def check_memory_setting(setting):
18471846
if options.use_closure_compiler == 2 and not shared.Settings.WASM2JS:
18481847
exit_with_error('closure compiler mode 2 assumes the code is asm.js, so not meaningful for wasm')
18491848

1850-
if 'MEM_INIT_METHOD' in settings_key_changes:
1849+
if 'MEM_INIT_METHOD' in settings_map:
18511850
exit_with_error('MEM_INIT_METHOD is not supported in wasm. Memory will be embedded in the wasm binary if threads are not used, and included in a separate file if threads are used.')
18521851

18531852
if shared.Settings.WASM2JS:
@@ -2027,7 +2026,7 @@ def get_full_import_name(name):
20272026

20282027
# Any "pointers" passed to JS will now be i64's, in both modes.
20292028
if shared.Settings.MEMORY64:
2030-
if settings_key_changes.get('WASM_BIGINT') == '0':
2029+
if settings_map.get('WASM_BIGINT') == '0':
20312030
exit_with_error('MEMORY64 is not compatible with WASM_BIGINT=0')
20322031
shared.Settings.WASM_BIGINT = 1
20332032

0 commit comments

Comments
 (0)