Skip to content
Open
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
17 changes: 12 additions & 5 deletions clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ dependencies::initializeScanInstanceDependencyCollector(
}

bool DependencyScanningAction::runInvocation(
std::unique_ptr<CompilerInvocation> Invocation,
std::string Executable, std::unique_ptr<CompilerInvocation> Invocation,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer) {
Expand All @@ -654,9 +654,12 @@ bool DependencyScanningAction::runInvocation(
if (Scanned) {
// Scanning runs once for the first -cc1 invocation in a chain of driver
// jobs. For any dependent jobs, reuse the scanning result and just
// update the LastCC1Arguments to correspond to the new invocation.
// update the new invocation.
// FIXME: to support multi-arch builds, each arch requires a separate scan
setLastCC1Arguments(std::move(OriginalInvocation));
if (MDC)
MDC->applyDiscoveredDependencies(OriginalInvocation);
Consumer.handleBuildCommand(
{Executable, OriginalInvocation.getCC1CommandLine()});
return true;
}

Expand Down Expand Up @@ -701,8 +704,12 @@ bool DependencyScanningAction::runInvocation(
// ExecuteAction is responsible for calling finish.
DiagConsumerFinished = true;

if (Result)
setLastCC1Arguments(std::move(OriginalInvocation));
if (Result) {
if (MDC)
MDC->applyDiscoveredDependencies(OriginalInvocation);
Consumer.handleBuildCommand(
{Executable, OriginalInvocation.getCC1CommandLine()});
}

return Result;
}
Expand Down
19 changes: 2 additions & 17 deletions clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,23 @@ class DependencyScanningAction {
std::optional<StringRef> ModuleName = std::nullopt)
: Service(Service), WorkingDirectory(WorkingDirectory),
Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)) {}
bool runInvocation(std::unique_ptr<CompilerInvocation> Invocation,
bool runInvocation(std::string Executable,
std::unique_ptr<CompilerInvocation> Invocation,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer);

bool hasScanned() const { return Scanned; }
bool hasDiagConsumerFinished() const { return DiagConsumerFinished; }

/// Take the cc1 arguments corresponding to the most recent invocation used
/// with this action. Any modifications implied by the discovered dependencies
/// will have already been applied.
std::vector<std::string> takeLastCC1Arguments() {
std::vector<std::string> Result;
std::swap(Result, LastCC1Arguments); // Reset LastCC1Arguments to empty.
return Result;
}

private:
void setLastCC1Arguments(CompilerInvocation &&CI) {
if (MDC)
MDC->applyDiscoveredDependencies(CI);
LastCC1Arguments = CI.getCC1CommandLine();
}

DependencyScanningService &Service;
StringRef WorkingDirectory;
DependencyConsumer &Consumer;
DependencyActionController &Controller;
IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
std::optional<CompilerInstance> ScanInstanceStorage;
std::shared_ptr<ModuleDepCollector> MDC;
std::vector<std::string> LastCC1Arguments;
bool Scanned = false;
bool DiagConsumerFinished = false;
};
Expand Down
22 changes: 9 additions & 13 deletions clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,14 @@ static bool createAndRunToolInvocation(
DependencyScanningAction &Action,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
DiagnosticsEngine &Diags, DependencyConsumer &Consumer) {
DiagnosticsEngine &Diags) {
auto Invocation = createCompilerInvocation(CommandLine, Diags);
if (!Invocation)
return false;

if (!Action.runInvocation(std::move(Invocation), std::move(FS),
PCHContainerOps, Diags.getClient()))
return false;

std::vector<std::string> Args = Action.takeLastCC1Arguments();
Consumer.handleBuildCommand({CommandLine[0], std::move(Args)});
return true;
return Action.runInvocation(CommandLine[0], std::move(Invocation),
std::move(FS), PCHContainerOps,
Diags.getClient());
}

bool DependencyScanningWorker::scanDependencies(
Expand All @@ -109,9 +105,9 @@ bool DependencyScanningWorker::scanDependencies(

bool Success = false;
if (CommandLine[1] == "-cc1") {
Success = createAndRunToolInvocation(
CommandLine, Action, FS, PCHContainerOps,
*DiagEngineWithCmdAndOpts.DiagEngine, Consumer);
Success =
createAndRunToolInvocation(CommandLine, Action, FS, PCHContainerOps,
*DiagEngineWithCmdAndOpts.DiagEngine);
} else {
Success = forEachDriverJob(
CommandLine, *DiagEngineWithCmdAndOpts.DiagEngine, FS,
Expand All @@ -125,7 +121,7 @@ bool DependencyScanningWorker::scanDependencies(
return true;
}

// Insert -cc1 comand line options into Argv
// Insert -cc1 command line options into Argv
std::vector<std::string> Argv;
Argv.push_back(Cmd.getExecutable());
llvm::append_range(Argv, Cmd.getArguments());
Expand All @@ -136,7 +132,7 @@ bool DependencyScanningWorker::scanDependencies(
// dependency scanning filesystem.
return createAndRunToolInvocation(
std::move(Argv), Action, FS, PCHContainerOps,
*DiagEngineWithCmdAndOpts.DiagEngine, Consumer);
*DiagEngineWithCmdAndOpts.DiagEngine);
});
}

Expand Down
Loading