Skip to content

Commit 194b514

Browse files
authored
Split apply_settings function out of emcc.py run (#6829)
Minor refactor I did as part of another change.
1 parent 8adf838 commit 194b514

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

emcc.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,40 @@ def embed_memfile(options):
322322
return shared.Settings.SINGLE_FILE or (shared.Settings.MEM_INIT_METHOD == 0 and (not shared.Settings.MAIN_MODULE and not shared.Settings.SIDE_MODULE and not use_source_map(options)))
323323

324324

325+
def apply_settings(changes):
326+
"""Take a list of settings in form `NAME=VALUE` and apply them to the global
327+
Settings object.
328+
"""
329+
330+
for change in changes:
331+
key, value = change.split('=', 1)
332+
333+
# In those settings fields that represent amount of memory, translate suffixes to multiples of 1024.
334+
if key in ('TOTAL_STACK', 'TOTAL_MEMORY', 'GL_MAX_TEMP_BUFFER_SIZE',
335+
'SPLIT_MEMORY', 'WASM_MEM_MAX', 'DEFAULT_PTHREAD_STACK_SIZE'):
336+
value = str(shared.expand_byte_size_suffixes(value))
337+
338+
original_exported_response = False
339+
340+
if value[0] == '@':
341+
if key not in DEFERRED_REPONSE_FILES:
342+
if key == 'EXPORTED_FUNCTIONS':
343+
original_exported_response = value
344+
value = open(value[1:]).read()
345+
else:
346+
value = '"' + value + '"'
347+
else:
348+
value = value.replace('\\', '\\\\')
349+
try:
350+
setattr(shared.Settings, key, parse_value(value))
351+
except Exception as e:
352+
exit_with_error('a problem occured in evaluating the content after a "-s", specifically "%s": %s', change, str(e))
353+
354+
if key == 'EXPORTED_FUNCTIONS':
355+
# used for warnings in emscripten.py
356+
shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = original_exported_response or shared.Settings.EXPORTED_FUNCTIONS[:]
357+
358+
325359
#
326360
# Main run() function
327361
#
@@ -756,11 +790,11 @@ def detect_fixed_language_mode(args):
756790
settings_key_changes = set()
757791

758792
def setting_sub(s):
759-
key, rest = s.split('=', 1)
793+
key, value = s.split('=', 1)
760794
settings_key_changes.add(key)
761-
return '='.join([settings_aliases.get(key, key), rest])
795+
return '='.join([settings_aliases.get(key, key), value])
762796

763-
settings_changes = list(map(setting_sub, settings_changes))
797+
settings_changes = [setting_sub(c) for c in settings_changes]
764798

765799
# Find input files
766800

@@ -940,32 +974,7 @@ def check(input_file):
940974
shared.Settings.ASM_JS = 1 if options.opt_level > 0 else 2
941975

942976
# Apply -s settings in newargs here (after optimization levels, so they can override them)
943-
for change in settings_changes:
944-
key, value = change.split('=', 1)
945-
946-
# In those settings fields that represent amount of memory, translate suffixes to multiples of 1024.
947-
if key in ['TOTAL_STACK', 'TOTAL_MEMORY', 'GL_MAX_TEMP_BUFFER_SIZE', 'SPLIT_MEMORY', 'WASM_MEM_MAX', 'DEFAULT_PTHREAD_STACK_SIZE']:
948-
value = str(shared.expand_byte_size_suffixes(value))
949-
950-
original_exported_response = False
951-
952-
if value[0] == '@':
953-
if key not in DEFERRED_REPONSE_FILES:
954-
if key == 'EXPORTED_FUNCTIONS':
955-
original_exported_response = value
956-
value = open(value[1:]).read()
957-
else:
958-
value = '"' + value + '"'
959-
else:
960-
value = value.replace('\\', '\\\\')
961-
try:
962-
setattr(shared.Settings, key, parse_value(value))
963-
except Exception as e:
964-
exit_with_error('a problem occured in evaluating the content after a "-s", specifically "%s": %s', change, str(e))
965-
966-
if key == 'EXPORTED_FUNCTIONS':
967-
# used for warnings in emscripten.py
968-
shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = original_exported_response or shared.Settings.EXPORTED_FUNCTIONS[:]
977+
apply_settings(settings_changes)
969978

970979
shared.verify_settings()
971980

0 commit comments

Comments
 (0)