Skip to content

Commit a06621b

Browse files
author
David Ungar
committed
Merge pull request #19321 from davidungar/rdar-44458502-fix-spaces-in-files-in-resp-files-swift-4.2
Fix response file quote bug, add flag for testing, add tests.
1 parent 8768d06 commit a06621b

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ def driver_force_one_batch_repartition : Flag<["-"], "driver-force-one-batch-rep
117117
InternalDebugOpt,
118118
HelpText<"Force one batch repartitioning for testing">;
119119

120+
def driver_force_response_files : Flag<["-"], "driver-force-response-files">,
121+
InternalDebugOpt,
122+
HelpText<"Force the use of response files for testing">;
123+
120124
def driver_always_rebuild_dependents :
121125
Flag<["-"], "driver-always-rebuild-dependents">, InternalDebugOpt,
122126
HelpText<"Always rebuild dependents of files that have been modified">;

lib/Driver/Job.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ bool Job::writeArgsToResponseFile() const {
425425
return true;
426426
}
427427
for (const char *arg : Arguments) {
428-
OS << "\"";
429428
escapeAndPrintString(OS, arg);
430-
OS << "\" ";
429+
OS << " ";
431430
}
432431
OS.flush();
433432
return false;

lib/Driver/ToolChain.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Driver/Compilation.h"
2222
#include "swift/Driver/Driver.h"
2323
#include "swift/Driver/Job.h"
24+
#include "swift/Option/Options.h"
2425
#include "llvm/ADT/STLExtras.h"
2526
#include "llvm/ADT/SetVector.h"
2627
#include "llvm/Option/ArgList.h"
@@ -116,9 +117,15 @@ std::unique_ptr<Job> ToolChain::constructJob(
116117

117118
const char *responseFilePath = nullptr;
118119
const char *responseFileArg = nullptr;
119-
if (invocationInfo.allowsResponseFiles &&
120-
!llvm::sys::commandLineFitsWithinSystemLimits(
121-
executablePath, invocationInfo.Arguments)) {
120+
121+
const bool forceResponseFiles =
122+
C.getArgs().hasArg(options::OPT_driver_force_response_files);
123+
assert((invocationInfo.allowsResponseFiles || !forceResponseFiles) &&
124+
"Cannot force response file if platform does not allow it");
125+
126+
if (forceResponseFiles || (invocationInfo.allowsResponseFiles &&
127+
!llvm::sys::commandLineFitsWithinSystemLimits(
128+
executablePath, invocationInfo.Arguments))) {
122129
responseFilePath = context.getTemporaryFilePath("arguments", "resp");
123130
responseFileArg = C.getArgs().MakeArgString(Twine("@") + responseFilePath);
124131
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Ensure that -driver-force-response-files works.
2+
3+
4+
// RUN: %swiftc_driver -driver-force-response-files -typecheck %S/../Inputs/empty.swift -### 2>&1 | %FileCheck %s
5+
// CHECK: @
6+
// CHECK: .resp
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: touch "%t/f i l e.swift"
3+
//
4+
// RUN: %target-build-swift -driver-force-response-files -parse "%t/f i l e.swift"

0 commit comments

Comments
 (0)