File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
Sources/SwiftDriver/Execution Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,10 @@ public final class ArgsResolver {
167
167
}
168
168
169
169
private func createResponseFileIfNeeded( for job: Job , resolvedArguments: inout [ String ] , forceResponseFiles: Bool ) throws -> Bool {
170
+ func quote( _ string: String ) -> String {
171
+ return " \" \( String ( string. flatMap { [ " \\ " , " \" " ] . contains ( $0) ? " \\ \( $0) " : " \( $0) " } ) ) \" "
172
+ }
173
+
170
174
if forceResponseFiles ||
171
175
( job. supportsResponseFiles && !commandLineFitsWithinSystemLimits( path: resolvedArguments [ 0 ] , args: resolvedArguments) ) {
172
176
assert ( !forceResponseFiles || job. supportsResponseFiles,
@@ -176,8 +180,11 @@ public final class ArgsResolver {
176
180
177
181
// FIXME: Need a way to support this for distributed build systems...
178
182
if let absPath = responseFilePath. absolutePath {
183
+ // Adopt the same technique as clang -
184
+ // Wrap all arguments in double quotes to ensure that both Unix and
185
+ // Windows tools understand the response file.
179
186
try fileSystem. writeFileContents ( absPath) {
180
- $0 <<< resolvedArguments [ 1 ... ] . map{ $0 . spm_shellEscaped ( ) } . joined ( separator: " \n " )
187
+ $0 <<< resolvedArguments [ 1 ... ] . map { quote ( $0 ) } . joined ( separator: " \n " )
181
188
}
182
189
resolvedArguments = [ resolvedArguments [ 0 ] , " @ \( absPath. pathString) " ]
183
190
}
Original file line number Diff line number Diff line change @@ -1205,9 +1205,9 @@ final class SwiftDriverTests: XCTestCase {
1205
1205
XCTAssertEqual ( resolvedArgs [ 1 ] . first, " @ " )
1206
1206
let responseFilePath = try AbsolutePath ( validating: String ( resolvedArgs [ 1 ] . dropFirst ( ) ) )
1207
1207
let contents = try localFileSystem. readFileContents ( responseFilePath) . description
1208
- XCTAssertTrue ( contents. hasPrefix ( " -frontend \n -interpret \n foo .swift" ) )
1209
- XCTAssertTrue ( contents. contains ( " -D \n TEST_20000 " ) )
1210
- XCTAssertTrue ( contents. contains ( " -D \n TEST_1 " ) )
1208
+ XCTAssertTrue ( contents. hasPrefix ( " \" -frontend \" \n \" -interpret \" \n \" foo .swift\" " ) )
1209
+ XCTAssertTrue ( contents. contains ( " \" -D \" \n \" TEST_20000 \" " ) )
1210
+ XCTAssertTrue ( contents. contains ( " \" -D \" \n \" TEST_1 \" " ) )
1211
1211
}
1212
1212
// Forced response file
1213
1213
do {
@@ -1221,7 +1221,7 @@ final class SwiftDriverTests: XCTestCase {
1221
1221
XCTAssertEqual ( resolvedArgs [ 1 ] . first, " @ " )
1222
1222
let responseFilePath = try AbsolutePath ( validating: String ( resolvedArgs [ 1 ] . dropFirst ( ) ) )
1223
1223
let contents = try localFileSystem. readFileContents ( responseFilePath) . description
1224
- XCTAssertTrue ( contents. hasPrefix ( " -frontend \n -interpret \n foo .swift" ) )
1224
+ XCTAssertTrue ( contents. hasPrefix ( " \" -frontend \" \n \" -interpret \" \n \" foo .swift\" " ) )
1225
1225
}
1226
1226
1227
1227
// No response file
You can’t perform that action at this time.
0 commit comments