Skip to content

Commit 7d94c24

Browse files
authored
Merge pull request #60712 from artemcm/RemoveRedundantScanCommandCombo
[Dependency Scan] Remove redundant recombination of arguments in 'initCompilerInstanceForScan' into a string, before being re-parsed.
2 parents b9971cc + baec315 commit 7d94c24

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ DependencyScanningTool::initScannerForAction(
160160

161161
llvm::ErrorOr<std::unique_ptr<CompilerInstance>>
162162
DependencyScanningTool::initCompilerInstanceForScan(
163-
ArrayRef<const char *> Command) {
163+
ArrayRef<const char *> CommandArgs) {
164164
// State unique to an individual scan
165165
auto Instance = std::make_unique<CompilerInstance>();
166166
Instance->addDiagnosticConsumer(&PDC);
167167

168168
// Basic error checking on the arguments
169-
if (Command.empty()) {
169+
if (CommandArgs.empty()) {
170170
Instance->getDiags().diagnose(SourceLoc(), diag::error_no_frontend_args);
171171
return std::make_error_code(std::errc::invalid_argument);
172172
}
@@ -180,16 +180,7 @@ DependencyScanningTool::initCompilerInstanceForScan(
180180
// We must do so because LLVM options parsing is done using a managed
181181
// static `GlobalParser`.
182182
llvm::cl::ResetAllOptionOccurrences();
183-
184-
// Parse arguments.
185-
std::string CommandString;
186-
for (const auto *c : Command) {
187-
CommandString.append(c);
188-
CommandString.append(" ");
189-
}
190-
SmallVector<const char *, 4> Args;
191-
llvm::cl::TokenizeGNUCommandLine(CommandString, Saver, Args);
192-
if (Invocation.parseArgs(Args, Instance->getDiags())) {
183+
if (Invocation.parseArgs(CommandArgs, Instance->getDiags())) {
193184
return std::make_error_code(std::errc::invalid_argument);
194185
}
195186

unittests/DependencyScan/ModuleDeps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ export *\n\
157157
llvm::sys::path::append(StdLibDir, getPlatformNameForTriple(Target));
158158

159159
std::vector<std::string> CommandStrArr = {
160-
std::string("'") + TestPathStr + std::string("'"),
161-
std::string("-I ") + std::string("'") + SwiftDirPath + std::string("'"),
162-
std::string("-I ") + std::string("'") + CHeadersDirPath + std::string("'"),
163-
std::string("-I ") + std::string("'") + StdLibDir.str().str() + std::string("'"),
164-
std::string("-I ") + std::string("'") + ShimsLibDir.str().str() + std::string("'")
160+
TestPathStr,
161+
std::string("-I ") + SwiftDirPath,
162+
std::string("-I ") + CHeadersDirPath,
163+
std::string("-I ") + StdLibDir.str().str(),
164+
std::string("-I ") + ShimsLibDir.str().str(),
165165
};
166166

167167
// On Windows we need to add an extra escape for path separator characters because otherwise

0 commit comments

Comments
 (0)