Skip to content

Commit 01c47cb

Browse files
authored
Cleanup code for reading response files (#6500)
1 parent f2e5079 commit 01c47cb

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def run():
332332
return 1
333333

334334
# read response files very early on
335-
substitute_response_files(sys.argv)
335+
sys.argv = substitute_response_files(sys.argv)
336336

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

emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ def ensure_struct_info():
22672267

22682268

22692269
def _main(args):
2270-
substitute_response_files(args)
2270+
args = substitute_response_files(args)
22712271

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

tools/response_file.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ def read_response_file(response_filename):
4444
if not os.path.exists(response_filename):
4545
raise Exception("Response file '%s' not found!" % response_filename)
4646

47-
response_fd = open(response_filename, 'r')
48-
args = response_fd.read()
49-
response_fd.close()
47+
with open(response_filename) as f:
48+
args = f.read()
5049
args = shlex.split(args)
5150

5251
if DEBUG:
@@ -57,12 +56,10 @@ def read_response_file(response_filename):
5756

5857
def substitute_response_files(args):
5958
"""Substitute any response files found in args with their contents."""
60-
found = True
61-
while found:
62-
found = False
63-
for index in range(len(args)):
64-
if args[index].startswith('@'):
65-
found = True
66-
new_args = read_response_file(args[index])
67-
args[index:index + 1] = new_args
68-
break
59+
new_args = []
60+
for arg in args:
61+
if arg.startswith('@'):
62+
new_args += read_response_file(arg)
63+
else:
64+
new_args.append(arg)
65+
return new_args

0 commit comments

Comments
 (0)