Skip to content

Commit efaa06f

Browse files
authored
Merge pull request swiftlang#35750 from nkcsgexi/73892564
Frontend: allow retrying expanding response files in argument lists
2 parents 7a7237b + dd83f17 commit efaa06f

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

include/swift/Driver/FrontendUtil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "llvm/ADT/STLExtras.h"
18+
#include "llvm/Support/StringSaver.h"
1819

1920
#include <memory>
2021

@@ -23,6 +24,11 @@ namespace swift {
2324
class DiagnosticEngine;
2425

2526
namespace driver {
27+
/// Expand response files in the argument list with retrying.
28+
/// This function is a wrapper of lvm::cl::ExpandResponseFiles. It will
29+
/// retry calling the function if the previous expansion failed.
30+
void ExpandResponseFilesWithRetry(llvm::StringSaver &Saver,
31+
llvm::SmallVectorImpl<const char *> &Args);
2632

2733
/// Generates the list of arguments that would be passed to the compiler
2834
/// frontend from the given driver arguments.

lib/Driver/FrontendUtil.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
using namespace swift;
2727
using namespace swift::driver;
2828

29+
void swift::driver::ExpandResponseFilesWithRetry(llvm::StringSaver &Saver,
30+
llvm::SmallVectorImpl<const char *> &Args) {
31+
const unsigned MAX_COUNT = 30;
32+
for (unsigned I = 0; I != MAX_COUNT; ++I) {
33+
if (llvm::cl::ExpandResponseFiles(Saver,
34+
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
35+
? llvm::cl::TokenizeWindowsCommandLine
36+
: llvm::cl::TokenizeGNUCommandLine,
37+
Args)) {
38+
return;
39+
}
40+
}
41+
}
42+
2943
bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
3044
ArrayRef<const char *> Argv, DiagnosticEngine &Diags,
3145
llvm::function_ref<bool(ArrayRef<const char *> FrontendArgs)> Action,
@@ -52,12 +66,7 @@ bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
5266
// Expand any file list args.
5367
llvm::BumpPtrAllocator Allocator;
5468
llvm::StringSaver Saver(Allocator);
55-
llvm::cl::ExpandResponseFiles(
56-
Saver,
57-
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
58-
? llvm::cl::TokenizeWindowsCommandLine
59-
: llvm::cl::TokenizeGNUCommandLine,
60-
Args);
69+
ExpandResponseFilesWithRetry(Saver, Args);
6170

6271
// Force the driver into batch mode by specifying "swiftc" as the name.
6372
Driver TheDriver("swiftc", "swiftc", Args, Diags);

tools/driver/driver.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,7 @@ int main(int argc_, const char **argv_) {
281281
SmallVector<const char *, 256> ExpandedArgs(&argv_[0], &argv_[argc_]);
282282
llvm::BumpPtrAllocator Allocator;
283283
llvm::StringSaver Saver(Allocator);
284-
llvm::cl::ExpandResponseFiles(
285-
Saver,
286-
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
287-
? llvm::cl::TokenizeWindowsCommandLine
288-
: llvm::cl::TokenizeGNUCommandLine,
289-
ExpandedArgs);
284+
swift::driver::ExpandResponseFilesWithRetry(Saver, ExpandedArgs);
290285

291286
// Initialize the stack trace using the parsed argument vector with expanded
292287
// response files.

0 commit comments

Comments
 (0)