Skip to content
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
69 changes: 32 additions & 37 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class EmccOptions:
requested_debug = None
sanitize: Set[str] = set()
sanitize_minimal_runtime = False
s_args: List[str] = []
save_temps = False
shared = False
shell_path = None
Expand Down Expand Up @@ -174,36 +175,29 @@ def is_dash_s_for_emcc(args, i):
return arg.isidentifier() and arg.isupper()


def parse_s_args(args):
settings_changes = []
for i in range(len(args)):
if args[i].startswith('-s'):
if is_dash_s_for_emcc(args, i):
if args[i] == '-s':
key = args[i + 1]
args[i + 1] = ''
else:
key = removeprefix(args[i], '-s')
args[i] = ''

# If not = is specified default to 1
if '=' not in key:
key += '=1'

# Special handling of browser version targets. A version -1 means that the specific version
# is not supported at all. Replace those with INT32_MAX to make it possible to compare e.g.
# #if MIN_FIREFOX_VERSION < 68
if re.match(r'MIN_.*_VERSION(=.*)?', key):
try:
if int(key.split('=')[1]) < 0:
key = key.split('=')[0] + '=0x7FFFFFFF'
except Exception:
pass
def parse_s_args():
for arg in options.s_args:
assert arg.startswith('-s')
arg = removeprefix(arg, '-s')
# If not = is specified default to 1
if '=' in arg:
key, value = arg.split('=', 1)
else:
key = arg
value = '1'

settings_changes.append(key)
# Special handling of browser version targets. A version -1 means that the specific version
# is not supported at all. Replace those with INT32_MAX to make it possible to compare e.g.
# #if MIN_FIREFOX_VERSION < 68
if re.match(r'MIN_.*_VERSION', key):
try:
if int(value) < 0:
value = '0x7FFFFFFF'
except Exception:
pass

newargs = [a for a in args if a]
return (settings_changes, newargs)
key, value = normalize_boolean_setting(key, value)
user_settings[key] = value


def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
Expand Down Expand Up @@ -236,8 +230,6 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
# because that next arg could, for example, start with `-o` and we don't want
# to confuse that with a normal `-o` flag.
skip = True
elif arg == '-s' and is_dash_s_for_emcc(newargs, i):
skip = True

def check_flag(value):
# Check for and consume a flag
Expand Down Expand Up @@ -274,7 +266,14 @@ def consume_arg_file():
exit_with_error("'%s': file not found: '%s'" % (arg, name))
return name

if arg.startswith('-O'):
if arg.startswith('-s') and is_dash_s_for_emcc(newargs, i):
s_arg = arg
if arg == '-s':
s_arg = '-s' + newargs[i + 1]
newargs[i + 1] = ''
newargs[i] = ''
options.s_args.append(s_arg)
elif arg.startswith('-O'):
# Let -O default to -O2, which is what gcc does.
opt_level = removeprefix(arg, '-O') or '2'
if opt_level == 's':
Expand Down Expand Up @@ -857,19 +856,15 @@ def parse_arguments(args):
if options.post_link or options.oformat == OFormat.BARE:
diagnostics.warning('experimental', '--oformat=bare/--post-link are experimental and subject to change.')

settings_changes, newargs = parse_s_args(newargs)
for s in settings_changes:
key, value = s.split('=', 1)
key, value = normalize_boolean_setting(key, value)
user_settings[key] = value
parse_s_args()

# STRICT is used when applying settings so it needs to be applied first before
# calling `apply_user_settings`.
strict_cmdline = user_settings.get('STRICT')
if strict_cmdline:
settings.STRICT = int(strict_cmdline)

# Apply -s settings in newargs here (after optimization levels, so they can override them)
# Apply -s args here (after optimization levels, so they can override them)
apply_user_settings()

return newargs