Skip to content

Rename settings_key_changes to settings_map and reuse it apply_settings. NFC #13743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def expand_byte_size_suffixes(value):


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

Expand All @@ -344,8 +344,7 @@ def standardize_setting_change(key, value):
value = str(1 - int(value))
return key, value

for change in changes:
key, value = change.split('=', 1)
for key, value in changes.items():
key, value = standardize_setting_change(key, value)

if key in shared.Settings.internal_settings:
Expand All @@ -365,14 +364,14 @@ def standardize_setting_change(key, value):
if value and value[0] == '@':
filename = value[1:]
if not os.path.exists(filename):
exit_with_error('%s: file not found parsing argument: %s' % (filename, change))
exit_with_error('%s: file not found parsing argument: %s=%s' % (filename, key, value))
value = open(filename).read()
else:
value = value.replace('\\', '\\\\')
try:
value = parse_value(value)
except Exception as e:
exit_with_error('a problem occurred in evaluating the content after a "-s", specifically "%s": %s', change, str(e))
exit_with_error('a problem occurred in evaluating the content after a "-s", specifically "%s=%s": %s', key, value, str(e))

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

settings_key_changes = {}
settings_map = {}
for s in settings_changes:
key, value = s.split('=', 1)
settings_key_changes[key] = value
settings_map[key] = value

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

strict_cmdline = settings_key_changes.get('STRICT')
strict_cmdline = settings_map.get('STRICT')
if strict_cmdline:
shared.Settings.STRICT = int(strict_cmdline)

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

# For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
# want to opt out of ERROR_ON_UNDEFINED_SYMBOLS.
if settings_key_changes.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS = 0

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

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

specified_target = options.output_file

Expand Down Expand Up @@ -1277,7 +1276,7 @@ def add_link_flag(i, f):
# reactor.
# 2. If the user doesn't export anything we default to exporting `_main` (unless `--no-entry`
# is specified (see above).
if 'EXPORTED_FUNCTIONS' in settings_key_changes:
if 'EXPORTED_FUNCTIONS' in settings_map:
if '_main' not in shared.Settings.USER_EXPORTED_FUNCTIONS:
shared.Settings.EXPECT_MAIN = 0
else:
Expand All @@ -1289,7 +1288,7 @@ def add_link_flag(i, f):
# See https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md
# For a command we always want EXIT_RUNTIME=1
# For a reactor we always want EXIT_RUNTIME=0
if 'EXIT_RUNTIME' in settings_key_changes:
if 'EXIT_RUNTIME' in settings_map:
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).')
shared.Settings.EXIT_RUNTIME = shared.Settings.EXPECT_MAIN

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

def default_setting(name, new_default):
if name not in settings_key_changes:
if name not in settings_map:
setattr(shared.Settings, name, new_default)

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

if shared.Settings.EXPORT_ES6 and not shared.Settings.MODULARIZE:
# EXPORT_ES6 requires output to be a module
if 'MODULARIZE' in settings_key_changes:
if 'MODULARIZE' in settings_map:
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
shared.Settings.MODULARIZE = 1

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

if 'MEM_INIT_METHOD' in settings_key_changes:
if 'MEM_INIT_METHOD' in settings_map:
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.')

if shared.Settings.WASM2JS:
Expand Down Expand Up @@ -2027,7 +2026,7 @@ def get_full_import_name(name):

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

Expand Down