42
42
from tools import colored_logger , diagnostics , building
43
43
from tools .shared import unsuffixed , unsuffixed_basename , WINDOWS , safe_copy
44
44
from tools .shared import run_process , read_and_preprocess , exit_with_error , DEBUG
45
- from tools .shared import do_replace
45
+ from tools .shared import do_replace , strip_prefix
46
46
from tools .response_file import substitute_response_files
47
47
from tools .minimal_runtime_shell import generate_minimal_runtime_html
48
48
import tools .line_endings
@@ -335,7 +335,7 @@ def standardize_setting_change(key, value):
335
335
# and we can't just flip them, so leave them as-is to be
336
336
# handled in a special way later)
337
337
if key .startswith ('NO_' ) and value in ('0' , '1' ):
338
- key = key [ 3 :]
338
+ key = strip_prefix ( key , 'NO_' )
339
339
value = str (1 - int (value ))
340
340
return key , value
341
341
@@ -357,7 +357,7 @@ def standardize_setting_change(key, value):
357
357
358
358
filename = None
359
359
if value and value [0 ] == '@' :
360
- filename = value [ 1 :]
360
+ filename = strip_prefix ( value , '@' )
361
361
if not os .path .exists (filename ):
362
362
exit_with_error ('%s: file not found parsing argument: %s=%s' % (filename , key , value ))
363
363
value = open (filename ).read ().strip ()
@@ -618,7 +618,7 @@ def is_dash_s_for_emcc(args, i):
618
618
return False
619
619
arg = args [i + 1 ]
620
620
else :
621
- arg = args [i ][ 2 :]
621
+ arg = strip_prefix ( args [i ], '-s' )
622
622
arg = arg .split ('=' )[0 ]
623
623
return arg .isidentifier () and arg .isupper ()
624
624
@@ -714,7 +714,7 @@ def parse_s_args(args):
714
714
key = args [i + 1 ]
715
715
args [i + 1 ] = ''
716
716
else :
717
- key = args [i ][ 2 :]
717
+ key = strip_prefix ( args [i ], '-s' )
718
718
args [i ] = ''
719
719
720
720
# If not = is specified default to 1
@@ -1244,7 +1244,7 @@ def phase_setup(options, state, newargs, settings_map):
1244
1244
# For shared libraries that are neither bitcode nor wasm, assuming its local native
1245
1245
# library and attempt to find a library by the same name in our own library path.
1246
1246
# TODO(sbc): Do we really need this feature? See test_other.py:test_local_link
1247
- libname = unsuffixed_basename (arg ). lstrip ( 'lib' )
1247
+ libname = strip_prefix ( unsuffixed_basename (arg ), 'lib' )
1248
1248
state .libs .append ((i , libname ))
1249
1249
else :
1250
1250
input_files .append ((i , arg ))
@@ -2294,7 +2294,7 @@ def get_language_mode(args):
2294
2294
return_next = True
2295
2295
continue
2296
2296
if item .startswith ('-x' ):
2297
- return item [ 2 :]
2297
+ return strip_prefix ( item , '-x' )
2298
2298
return ''
2299
2299
2300
2300
language_mode = get_language_mode (newargs )
@@ -2729,7 +2729,7 @@ def consume_arg_file():
2729
2729
2730
2730
if arg .startswith ('-O' ):
2731
2731
# Let -O default to -O2, which is what gcc does.
2732
- options .requested_level = arg [ 2 :] or '2'
2732
+ options .requested_level = strip_prefix ( arg , '-O' ) or '2'
2733
2733
if options .requested_level == 's' :
2734
2734
options .requested_level = 2
2735
2735
settings .SHRINK_LEVEL = 1
@@ -2784,7 +2784,7 @@ def consume_arg_file():
2784
2784
settings .DEBUG_LEVEL = max (1 , settings .DEBUG_LEVEL )
2785
2785
elif arg .startswith ('-g' ):
2786
2786
options .requested_debug = arg
2787
- requested_level = arg [ 2 :] or '3'
2787
+ requested_level = strip_prefix ( arg , '-g' ) or '3'
2788
2788
if is_int (requested_level ):
2789
2789
# the -gX value is the debug level (-g1, -g2, etc.)
2790
2790
settings .DEBUG_LEVEL = validate_arg_level (requested_level , 4 , 'Invalid debug level: ' + arg )
@@ -2959,7 +2959,7 @@ def consume_arg_file():
2959
2959
elif arg == '-frtti' :
2960
2960
settings .USE_RTTI = 1
2961
2961
elif arg .startswith ('-jsD' ):
2962
- key = arg [ 4 :]
2962
+ key = strip_prefix ( arg , '-jsD' )
2963
2963
if '=' in key :
2964
2964
key , value = key .split ('=' )
2965
2965
else :
@@ -2975,7 +2975,7 @@ def consume_arg_file():
2975
2975
elif check_arg ('-o' ):
2976
2976
options .output_file = consume_arg ()
2977
2977
elif arg .startswith ('-o' ):
2978
- options .output_file = arg [ 2 :]
2978
+ options .output_file = strip_prefix ( arg , '-o' )
2979
2979
newargs [i ] = ''
2980
2980
elif arg == '-mllvm' :
2981
2981
# Ignore the next argument rather than trying to parse it. This is needed
0 commit comments