Skip to content

Add -driver-force-response-files to enable testing. #19313

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
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
12 changes: 9 additions & 3 deletions lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ std::unique_ptr<Job> ToolChain::constructJob(

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 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invocationInfo.allowsResponseFiles should still guard the whole thing, since one swiftc invocation can invoke multiple tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that if -driver-force-response-files is set on a platform that disallows them, you want the compiler just silently disregard the option? Or what do you want in that case? The current code is meant to fail an assertion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misread the assertion, but the problem is that it's not a platform-by-platform decision; it's a tool-by-tool decision. You could easily have a platform where calling the frontend allows response files (all of them) but calling the linker does not.

Then again, since this is for testing purposes only, maybe the assertion is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Merged this a bit too quickly, let me know if you want a change. (I can't find the revert button, but can merge a fix.)

!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