@@ -812,6 +812,29 @@ def normalize_boolean_setting(name, value):
812812 return name , value
813813
814814
815+ def normalize_args (args ):
816+ """Normalize argument that can be specific as either one or two arguments.
817+
818+ In some cases these arguments are simply joined together. For example
819+ [`-o` `foo`] becomes `-ofoo` and [`-L` `bar`] becomes `-Lbar`.
820+
821+ In other cases they are joined by an equals sign. For example ['--js-library`, `foo.js`]
822+ becomes `--js-library=foo.js`.
823+ """
824+ equals_args = {'--js-library' }
825+ join_args = {'-l' , '-L' , '-I' , '-z' , '-o' , '-x' , '-u' } | equals_args
826+ for i in range (len (args )):
827+ if args [i ] in join_args :
828+ if args [i ] in equals_args :
829+ args [i ] += '='
830+ if len (args ) <= i + 1 :
831+ exit_with_error (f"option '{ args [i ]} ' requires an argument" )
832+ args [i ] += args [i + 1 ]
833+ args [i + 1 ] = ''
834+
835+ return [a for a in args if a ]
836+
837+
815838@ToolchainProfiler .profile ()
816839def parse_arguments (args ):
817840 newargs = list (args )
@@ -824,17 +847,7 @@ def parse_arguments(args):
824847 if not diagnostics .is_enabled ('deprecated' ):
825848 settings .WARN_DEPRECATED = 0
826849
827- for i in range (len (newargs )):
828- if newargs [i ] in ('-l' , '-L' , '-I' , '-z' , '--js-library' , '-o' , '-x' , '-u' ):
829- # Scan for flags that can be written as either one or two arguments
830- # and normalize them to the single argument form.
831- if newargs [i ] == '--js-library' :
832- newargs [i ] += '='
833- if len (newargs ) <= i + 1 :
834- exit_with_error (f"option '{ newargs [i ]} ' requires an argument" )
835- newargs [i ] += newargs [i + 1 ]
836- newargs [i + 1 ] = ''
837-
850+ newargs = normalize_args (newargs )
838851 newargs = parse_args (newargs )
839852
840853 if options .post_link or options .oformat == OFormat .BARE :
0 commit comments