[clang][deps] NFC: Handle `DependencyOutputOptions` only once

There's no need to pass `DependencyOutputOptions` to each call of `handleFileDependency`, since the options don't ever change.

This patch adds new `handleDependencyOutputOpts` method to the `DependencyConsumer` interface and the dependency scanner uses it to report the options only once.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D104104
This commit is contained in:
Jan Svoboda 2021-06-14 15:06:13 +02:00
parent bb8ce25e88
commit f95ff81627
4 changed files with 20 additions and 12 deletions

View File

@ -34,8 +34,10 @@ class DependencyConsumer {
public:
virtual ~DependencyConsumer() {}
virtual void handleFileDependency(const DependencyOutputOptions &Opts,
StringRef Filename) = 0;
virtual void
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
virtual void handleFileDependency(StringRef Filename) = 0;
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0;

View File

@ -54,10 +54,12 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
/// Prints out all of the gathered dependencies into a string.
class MakeDependencyPrinterConsumer : public DependencyConsumer {
public:
void handleFileDependency(const DependencyOutputOptions &Opts,
StringRef File) override {
if (!this->Opts)
this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
void
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
}
void handleFileDependency(StringRef File) override {
Dependencies.push_back(std::string(File));
}
@ -74,8 +76,7 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
void handleContextHash(std::string Hash) override {}
void printDependencies(std::string &S) {
if (!Opts)
return;
assert(Opts && "Handled dependency output options.");
class DependencyPrinter : public DependencyFileGenerator {
public:
@ -128,8 +129,10 @@ DependencyScanningTool::getFullDependencies(
FullDependencyPrinterConsumer(const llvm::StringSet<> &AlreadySeen)
: AlreadySeen(AlreadySeen) {}
void handleFileDependency(const DependencyOutputOptions &Opts,
StringRef File) override {
void
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {}
void handleFileDependency(StringRef File) override {
Dependencies.push_back(std::string(File));
}

View File

@ -32,11 +32,12 @@ public:
: DependencyFileGenerator(*Opts), Opts(std::move(Opts)), C(C) {}
void finishedMainFile(DiagnosticsEngine &Diags) override {
C.handleDependencyOutputOpts(*Opts);
llvm::SmallString<256> CanonPath;
for (const auto &File : getDependencies()) {
CanonPath = File;
llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true);
C.handleFileDependency(*Opts, CanonPath);
C.handleFileDependency(CanonPath);
}
}

View File

@ -173,11 +173,13 @@ void ModuleDepCollectorPP::EndOfMainFile() {
for (const Module *M : DirectModularDeps)
handleTopLevelModule(M);
MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
for (auto &&I : MDC.ModularDeps)
MDC.Consumer.handleModuleDependency(I.second);
for (auto &&I : MDC.FileDeps)
MDC.Consumer.handleFileDependency(*MDC.Opts, I);
MDC.Consumer.handleFileDependency(I);
for (auto &&I : DirectPrebuiltModularDeps)
MDC.Consumer.handlePrebuiltModuleDependency(PrebuiltModuleDep{I});