Skip to content

Commit d136ce6

Browse files
committed
SwiftDriver: change the response file emission
This adjusts the response file emission to follow the clang behaviour. Doing so allows the use of response files on Windows to be passed to clang, which will default to POSIX style response files unless explicitly passed `--rsp-quoting=windows`. This allows for a single path for the emission across platforms, and avoids having to deal with the dynamic switching of the response file formats. With this change, ignoring the serialization issue, it is now possible to build swift-driver with swift-driver.
1 parent f4e80ec commit d136ce6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sources/SwiftDriver/Execution/ArgsResolver.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public final class ArgsResolver {
167167
}
168168

169169
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+
170174
if forceResponseFiles ||
171175
(job.supportsResponseFiles && !commandLineFitsWithinSystemLimits(path: resolvedArguments[0], args: resolvedArguments)) {
172176
assert(!forceResponseFiles || job.supportsResponseFiles,
@@ -176,8 +180,11 @@ public final class ArgsResolver {
176180

177181
// FIXME: Need a way to support this for distributed build systems...
178182
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.
179186
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")
181188
}
182189
resolvedArguments = [resolvedArguments[0], "@\(absPath.pathString)"]
183190
}

0 commit comments

Comments
 (0)