Skip to content

Commit b67c3d6

Browse files
froydnjkripken
authored andcommitted
refactor response file substitution (#6171)
We have the same code in two places, we can make a common function for the response_file module.
1 parent 648878b commit b67c3d6

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

emcc.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from subprocess import PIPE
3333
from tools import shared, jsrun, system_libs
3434
from tools.shared import execute, suffix, unsuffixed, unsuffixed_basename, WINDOWS, safe_move, run_process, asbytes
35-
from tools.response_file import read_response_file
35+
from tools.response_file import substitute_response_files
3636
import tools.line_endings
3737

3838
try:
@@ -329,17 +329,7 @@ def run():
329329
exit(1)
330330

331331
# read response files very early on
332-
response_file = True
333-
while response_file:
334-
response_file = None
335-
for index in range(1, len(sys.argv)):
336-
if sys.argv[index][0] == '@':
337-
# found one, loop again next time
338-
response_file = True
339-
extra_args = read_response_file(sys.argv[index])
340-
# slice in extra_args in place of the response file arg
341-
sys.argv[index:index+1] = extra_args
342-
break
332+
substitute_response_files(sys.argv)
343333

344334
if len(sys.argv) == 1 or '--help' in sys.argv:
345335
# Documentation for emcc and its options must be updated in:

emscripten.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from tools import shared
2222
from tools import jsrun, cache as cache_module, tempfiles
23-
from tools.response_file import read_response_file
23+
from tools.response_file import substitute_response_files
2424
from tools.shared import WINDOWS, asstr
2525

2626
__rootpath__ = os.path.abspath(os.path.dirname(__file__))
@@ -2255,17 +2255,7 @@ def _main(args=None):
22552255
if args is None:
22562256
args = sys.argv[1:]
22572257

2258-
response_file = True
2259-
while response_file:
2260-
response_file = None
2261-
for index in range(len(args)):
2262-
if args[index][0] == '@':
2263-
# found one, loop again next time
2264-
response_file = True
2265-
response_file_args = read_response_file(args[index])
2266-
# slice in extra_args in place of the response file arg
2267-
args[index:index+1] = response_file_args
2268-
break
2258+
substitute_response_files(args)
22692259

22702260
parser = argparse.ArgumentParser(
22712261
usage='%(prog)s [-h] [-H HEADERS] [-o OUTFILE] [-c COMPILER_ENGINE] [-s FOO=BAR]* infile',

tools/response_file.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ def read_response_file(response_filename):
4444
logging.warning('Read response file ' + response_filename + ': ' + str(args))
4545

4646
return args
47+
48+
def substitute_response_files(args):
49+
"""Substitute any response files found in args with their contents."""
50+
found = True
51+
while found:
52+
found = False
53+
for index in range(len(args)):
54+
if args[index].startswith('@'):
55+
found = True
56+
new_args = read_response_file(args[index])
57+
args[index:index+1] = new_args
58+
break

0 commit comments

Comments
 (0)