1313DEBUG = int (os .environ .get ('EMCC_DEBUG' , '0' ))
1414
1515
16- def create_response_file (args , directory ):
17- """Routes the given cmdline param list in args into a new response file and
18- returns the filename to it.
16+ def create_response_file_contents (args ):
17+ """Create response file contents based on list of arguments.
1918 """
20-
21- response_fd , response_filename = tempfile .mkstemp (prefix = 'emscripten_' , suffix = '.rsp.utf-8' , dir = directory , text = True )
22-
23- # Backslashes and other special chars need to be escaped in the response file.
2419 escape_chars = ['\\ ' , '\" ' ]
2520 # When calling llvm-ar on Linux and macOS, single quote characters ' should be escaped.
2621 if not WINDOWS :
@@ -40,6 +35,18 @@ def escape(arg):
4035 arg = '"%s"' % arg
4136 contents += arg + '\n '
4237
38+ return contents
39+
40+
41+ def create_response_file (args , directory ):
42+ """Routes the given cmdline param list in args into a new response file and
43+ returns the filename to it.
44+ """
45+ # Backslashes and other special chars need to be escaped in the response file.
46+ contents = create_response_file_contents (args )
47+
48+ response_fd , response_filename = tempfile .mkstemp (prefix = 'emscripten_' , suffix = '.rsp.utf-8' , dir = directory , text = True )
49+
4350 with os .fdopen (response_fd , 'w' , encoding = 'utf-8' ) as f :
4451 f .write (contents )
4552
@@ -54,7 +61,7 @@ def escape(arg):
5461 return response_filename
5562
5663
57- def read_response_file ( response_filename ):
64+ def expand_response_file ( arg ):
5865 """Reads a response file, and returns the list of cmdline params found in the
5966 file.
6067
@@ -63,12 +70,19 @@ def read_response_file(response_filename):
6370 specified, first UTF-8 and then Python locale.getpreferredencoding() are
6471 attempted.
6572
66- The parameter response_filename may start with '@'."""
67- if response_filename .startswith ('@' ):
68- response_filename = response_filename [1 :]
73+ The parameter `arg` is the command line argument to be expanded."""
74+
75+ if arg .startswith ('@' ):
76+ response_filename = arg [1 :]
77+ elif arg .startswith ('-Wl,@' ):
78+ response_filename = arg [5 :]
79+ else :
80+ response_filename = None
6981
70- if not os .path .exists (response_filename ):
71- raise OSError ("response file not found: %s" % response_filename )
82+ # Is the argument is not a response file, or if the file does not exist
83+ # just return orginal argument.
84+ if not response_filename or not os .path .exists (response_filename ):
85+ return [arg ]
7286
7387 # Guess encoding based on the file suffix
7488 components = os .path .basename (response_filename ).split ('.' )
@@ -97,20 +111,13 @@ def read_response_file(response_filename):
97111 if DEBUG :
98112 logging .warning (f'read response file { response_filename } : { args } ' )
99113
100- return args
114+ # Response file can be recursive so call substitute_response_files on the arguments
115+ return substitute_response_files (args )
101116
102117
103118def substitute_response_files (args ):
104119 """Substitute any response files found in args with their contents."""
105120 new_args = []
106121 for arg in args :
107- if arg .startswith ('@' ):
108- new_args += read_response_file (arg )
109- elif arg .startswith ('-Wl,@' ):
110- for a in read_response_file (arg [5 :]):
111- if a .startswith ('-' ):
112- a = '-Wl,' + a
113- new_args .append (a )
114- else :
115- new_args .append (arg )
122+ new_args += expand_response_file (arg )
116123 return new_args
0 commit comments