Skip to content

[Dependency Scan] Remove redundant recombination of arguments in 'initCompilerInstanceForScan' into a string, before being re-parsed. #60712

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 1 commit into from
Aug 23, 2022
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
15 changes: 3 additions & 12 deletions lib/DependencyScan/DependencyScanningTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ DependencyScanningTool::initScannerForAction(

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

// Basic error checking on the arguments
if (Command.empty()) {
if (CommandArgs.empty()) {
Instance->getDiags().diagnose(SourceLoc(), diag::error_no_frontend_args);
return std::make_error_code(std::errc::invalid_argument);
}
Expand All @@ -180,16 +180,7 @@ DependencyScanningTool::initCompilerInstanceForScan(
// We must do so because LLVM options parsing is done using a managed
// static `GlobalParser`.
llvm::cl::ResetAllOptionOccurrences();

// Parse arguments.
std::string CommandString;
for (const auto *c : Command) {
CommandString.append(c);
CommandString.append(" ");
}
SmallVector<const char *, 4> Args;
llvm::cl::TokenizeGNUCommandLine(CommandString, Saver, Args);
if (Invocation.parseArgs(Args, Instance->getDiags())) {
if (Invocation.parseArgs(CommandArgs, Instance->getDiags())) {
return std::make_error_code(std::errc::invalid_argument);
}

Expand Down
10 changes: 5 additions & 5 deletions unittests/DependencyScan/ModuleDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ export *\n\
llvm::sys::path::append(StdLibDir, getPlatformNameForTriple(Target));

std::vector<std::string> CommandStrArr = {
std::string("'") + TestPathStr + std::string("'"),
std::string("-I ") + std::string("'") + SwiftDirPath + std::string("'"),
std::string("-I ") + std::string("'") + CHeadersDirPath + std::string("'"),
std::string("-I ") + std::string("'") + StdLibDir.str().str() + std::string("'"),
std::string("-I ") + std::string("'") + ShimsLibDir.str().str() + std::string("'")
TestPathStr,
std::string("-I ") + SwiftDirPath,
std::string("-I ") + CHeadersDirPath,
std::string("-I ") + StdLibDir.str().str(),
std::string("-I ") + ShimsLibDir.str().str(),
};

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