Skip to content

Fix response file quote bug, add flag for testing, add tests. #19321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def driver_force_one_batch_repartition : Flag<["-"], "driver-force-one-batch-rep
InternalDebugOpt,
HelpText<"Force one batch repartitioning for testing">;

def driver_force_response_files : Flag<["-"], "driver-force-response-files">,
InternalDebugOpt,
HelpText<"Force the use of response files for testing">;

def driver_always_rebuild_dependents :
Flag<["-"], "driver-always-rebuild-dependents">, InternalDebugOpt,
HelpText<"Always rebuild dependents of files that have been modified">;
Expand Down
3 changes: 1 addition & 2 deletions lib/Driver/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,8 @@ bool Job::writeArgsToResponseFile() const {
return true;
}
for (const char *arg : Arguments) {
OS << "\"";
escapeAndPrintString(OS, arg);
OS << "\" ";
OS << " ";
}
OS.flush();
return false;
Expand Down
13 changes: 10 additions & 3 deletions lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "swift/Driver/Compilation.h"
#include "swift/Driver/Driver.h"
#include "swift/Driver/Job.h"
#include "swift/Option/Options.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Option/ArgList.h"
Expand Down Expand Up @@ -120,9 +121,15 @@ ToolChain::constructJob(const JobAction &JA,

const char *responseFilePath = nullptr;
const char *responseFileArg = nullptr;
if (invocationInfo.allowsResponseFiles &&
!llvm::sys::commandLineFitsWithinSystemLimits(
executablePath, invocationInfo.Arguments)) {

const bool forceResponseFiles =
C.getArgs().hasArg(options::OPT_driver_force_response_files);
assert((invocationInfo.allowsResponseFiles || !forceResponseFiles) &&
"Cannot force response file if platform does not allow it");

if (forceResponseFiles || (invocationInfo.allowsResponseFiles &&
!llvm::sys::commandLineFitsWithinSystemLimits(
executablePath, invocationInfo.Arguments))) {
responseFilePath = context.getTemporaryFilePath("arguments", "resp");
responseFileArg = C.getArgs().MakeArgString(Twine("@") + responseFilePath);
}
Expand Down
6 changes: 6 additions & 0 deletions test/Driver/force-response-files.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Ensure that -driver-force-response-files works.


// RUN: %swiftc_driver -driver-force-response-files -typecheck %S/../Inputs/empty.swift -### 2>&1 | %FileCheck %s
// CHECK: @
// CHECK: .resp
4 changes: 4 additions & 0 deletions test/Driver/response-files-with-spaces-in-filenames.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: touch "%t/f i l e.swift"
//
// RUN: %target-build-swift -driver-force-response-files -parse "%t/f i l e.swift"