@@ -103,6 +103,7 @@ class EmccOptions:
103103 requested_debug = None
104104 sanitize : Set [str ] = set ()
105105 sanitize_minimal_runtime = False
106+ s_args : List [str ] = []
106107 save_temps = False
107108 shared = False
108109 shell_path = None
@@ -174,36 +175,29 @@ def is_dash_s_for_emcc(args, i):
174175 return arg .isidentifier () and arg .isupper ()
175176
176177
177- def parse_s_args (args ):
178- settings_changes = []
179- for i in range (len (args )):
180- if args [i ].startswith ('-s' ):
181- if is_dash_s_for_emcc (args , i ):
182- if args [i ] == '-s' :
183- key = args [i + 1 ]
184- args [i + 1 ] = ''
185- else :
186- key = removeprefix (args [i ], '-s' )
187- args [i ] = ''
188-
189- # If not = is specified default to 1
190- if '=' not in key :
191- key += '=1'
192-
193- # Special handling of browser version targets. A version -1 means that the specific version
194- # is not supported at all. Replace those with INT32_MAX to make it possible to compare e.g.
195- # #if MIN_FIREFOX_VERSION < 68
196- if re .match (r'MIN_.*_VERSION(=.*)?' , key ):
197- try :
198- if int (key .split ('=' )[1 ]) < 0 :
199- key = key .split ('=' )[0 ] + '=0x7FFFFFFF'
200- except Exception :
201- pass
178+ def parse_s_args ():
179+ for arg in options .s_args :
180+ assert arg .startswith ('-s' )
181+ arg = removeprefix (arg , '-s' )
182+ # If not = is specified default to 1
183+ if '=' in arg :
184+ key , value = arg .split ('=' , 1 )
185+ else :
186+ key = arg
187+ value = '1'
202188
203- settings_changes .append (key )
189+ # Special handling of browser version targets. A version -1 means that the specific version
190+ # is not supported at all. Replace those with INT32_MAX to make it possible to compare e.g.
191+ # #if MIN_FIREFOX_VERSION < 68
192+ if re .match (r'MIN_.*_VERSION' , key ):
193+ try :
194+ if int (value ) < 0 :
195+ value = '0x7FFFFFFF'
196+ except Exception :
197+ pass
204198
205- newargs = [ a for a in args if a ]
206- return ( settings_changes , newargs )
199+ key , value = normalize_boolean_setting ( key , value )
200+ user_settings [ key ] = value
207201
208202
209203def parse_args (newargs ): # noqa: C901, PLR0912, PLR0915
@@ -236,8 +230,6 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
236230 # because that next arg could, for example, start with `-o` and we don't want
237231 # to confuse that with a normal `-o` flag.
238232 skip = True
239- elif arg == '-s' and is_dash_s_for_emcc (newargs , i ):
240- skip = True
241233
242234 def check_flag (value ):
243235 # Check for and consume a flag
@@ -274,7 +266,14 @@ def consume_arg_file():
274266 exit_with_error ("'%s': file not found: '%s'" % (arg , name ))
275267 return name
276268
277- if arg .startswith ('-O' ):
269+ if arg .startswith ('-s' ) and is_dash_s_for_emcc (newargs , i ):
270+ s_arg = arg
271+ if arg == '-s' :
272+ s_arg = '-s' + newargs [i + 1 ]
273+ newargs [i + 1 ] = ''
274+ newargs [i ] = ''
275+ options .s_args .append (s_arg )
276+ elif arg .startswith ('-O' ):
278277 # Let -O default to -O2, which is what gcc does.
279278 opt_level = removeprefix (arg , '-O' ) or '2'
280279 if opt_level == 's' :
@@ -857,19 +856,15 @@ def parse_arguments(args):
857856 if options .post_link or options .oformat == OFormat .BARE :
858857 diagnostics .warning ('experimental' , '--oformat=bare/--post-link are experimental and subject to change.' )
859858
860- settings_changes , newargs = parse_s_args (newargs )
861- for s in settings_changes :
862- key , value = s .split ('=' , 1 )
863- key , value = normalize_boolean_setting (key , value )
864- user_settings [key ] = value
859+ parse_s_args ()
865860
866861 # STRICT is used when applying settings so it needs to be applied first before
867862 # calling `apply_user_settings`.
868863 strict_cmdline = user_settings .get ('STRICT' )
869864 if strict_cmdline :
870865 settings .STRICT = int (strict_cmdline )
871866
872- # Apply -s settings in newargs here (after optimization levels, so they can override them)
867+ # Apply -s args here (after optimization levels, so they can override them)
873868 apply_user_settings ()
874869
875870 return newargs
0 commit comments