Skip to content

Commit adc1a44

Browse files
authored
Merge pull request swiftlang#65293 from artemcm/DepScanAlwaysTokenize
[Dependency Scanning] Always tokenize scanning query command-line strings
2 parents 8dcca58 + cfde1fb commit adc1a44

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,23 @@ DependencyScanningTool::initCompilerInstanceForScan(
254254
// We must do so because LLVM options parsing is done using a managed
255255
// static `GlobalParser`.
256256
llvm::cl::ResetAllOptionOccurrences();
257-
if (Invocation.parseArgs(CommandArgs, Instance->getDiags(),
257+
// Parse/tokenize arguments.
258+
std::string CommandString;
259+
for (const auto *c : CommandArgs) {
260+
CommandString.append(c);
261+
CommandString.append(" ");
262+
}
263+
SmallVector<const char *, 4> Args;
264+
llvm::BumpPtrAllocator Alloc;
265+
llvm::StringSaver Saver(Alloc);
266+
// Ensure that we use the Windows command line parsing on Windows as we need
267+
// to ensure that we properly handle paths.
268+
if (llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows())
269+
llvm::cl::TokenizeWindowsCommandLine(CommandString, Saver, Args);
270+
else
271+
llvm::cl::TokenizeGNUCommandLine(CommandString, Saver, Args);
272+
273+
if (Invocation.parseArgs(Args, Instance->getDiags(),
258274
nullptr, WorkingDirectory, "/tmp/foo")) {
259275
return std::make_error_code(std::errc::invalid_argument);
260276
}

0 commit comments

Comments
 (0)