Skip to content

Commit de23585

Browse files
committed
Address code review comments.
1 parent b7b08e8 commit de23585

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,15 @@ computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
586586
}
587587

588588
std::unique_ptr<DependencyOutputOptions>
589-
getDependencyOutputOptions(CompilerInstance &ScanInstance) {
589+
takeDependencyOutputOptionsFrom(CompilerInstance &ScanInstance) {
590590
// This function moves the existing dependency output options from the
591591
// invocation to the collector. The options in the invocation are reset,
592592
// which ensures that the compiler won't create new dependency collectors,
593593
// and thus won't write out the extra '.d' files to disk.
594594
auto Opts = std::make_unique<DependencyOutputOptions>();
595+
596+
// We need at least one -MT equivalent for the generator of make dependency
597+
// files to work.
595598
std::swap(*Opts, ScanInstance.getInvocation().getDependencyOutputOpts());
596599
if (Opts->Targets.empty())
597600
Opts->Targets = {deduceDepTarget(ScanInstance.getFrontendOpts().OutputFile,
@@ -603,29 +606,24 @@ getDependencyOutputOptions(CompilerInstance &ScanInstance) {
603606

604607
std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
605608
CompilerInstance &ScanInstance,
606-
const DependencyOutputOptions &DepOutputOpts, StringRef WorkingDirectory,
607-
DependencyConsumer &Consumer, DependencyScanningService &Service,
608-
CompilerInvocation &Inv, DependencyActionController &Controller,
609+
std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
610+
StringRef WorkingDirectory, DependencyConsumer &Consumer,
611+
DependencyScanningService &Service, CompilerInvocation &Inv,
612+
DependencyActionController &Controller,
609613
PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
610614
llvm::SmallVector<StringRef> &StableDirs) {
611-
// Create the dependency collector that will collect the produced
612-
// dependencies. May return the created ModuleDepCollector depending
613-
// on the scanning format.
614-
615-
auto Opts = std::make_unique<DependencyOutputOptions>(DepOutputOpts);
616-
617615
std::shared_ptr<ModuleDepCollector> MDC;
618616
switch (Service.getFormat()) {
619617
case ScanningOutputFormat::Make:
620618
ScanInstance.addDependencyCollector(
621619
std::make_shared<DependencyConsumerForwarder>(
622-
std::move(Opts), WorkingDirectory, Consumer));
620+
std::move(DepOutputOpts), WorkingDirectory, Consumer));
623621
break;
624622
case ScanningOutputFormat::P1689:
625623
case ScanningOutputFormat::Full:
626624
MDC = std::make_shared<ModuleDepCollector>(
627-
Service, std::move(Opts), ScanInstance, Consumer, Controller, Inv,
628-
std::move(PrebuiltModulesASTMap), StableDirs);
625+
Service, std::move(DepOutputOpts), ScanInstance, Consumer, Controller,
626+
Inv, std::move(PrebuiltModulesASTMap), StableDirs);
629627
ScanInstance.addDependencyCollector(MDC);
630628
break;
631629
}
@@ -676,11 +674,12 @@ bool DependencyScanningAction::runInvocation(
676674
if (!MaybePrebuiltModulesASTMap)
677675
return false;
678676

679-
auto DepOutputOpts = getDependencyOutputOptions(ScanInstance);
677+
auto DepOutputOpts = takeDependencyOutputOptionsFrom(ScanInstance);
680678

681679
MDC = initializeScanInstanceDependencyCollector(
682-
ScanInstance, *DepOutputOpts, WorkingDirectory, Consumer, Service,
683-
OriginalInvocation, Controller, *MaybePrebuiltModulesASTMap, StableDirs);
680+
ScanInstance, std::move(DepOutputOpts), WorkingDirectory, Consumer,
681+
Service, OriginalInvocation, Controller, *MaybePrebuiltModulesASTMap,
682+
StableDirs);
684683

685684
std::unique_ptr<FrontendAction> Action;
686685

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
136136
SmallVector<StringRef> &StableDirs);
137137

138138
std::unique_ptr<DependencyOutputOptions>
139-
getDependencyOutputOptions(CompilerInstance &ScanInstance);
139+
takeDependencyOutputOptionsFrom(CompilerInstance &ScanInstance);
140140

141+
/// Create the dependency collector that will collect the produced
142+
/// dependencies. May return the created ModuleDepCollector depending
143+
/// on the scanning format.
141144
std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
142145
CompilerInstance &ScanInstance,
143-
const DependencyOutputOptions &DepOutputOpts, StringRef WorkingDirectory,
144-
DependencyConsumer &Consumer, DependencyScanningService &Service,
145-
CompilerInvocation &Inv, DependencyActionController &Controller,
146+
std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
147+
StringRef WorkingDirectory, DependencyConsumer &Consumer,
148+
DependencyScanningService &Service, CompilerInvocation &Inv,
149+
DependencyActionController &Controller,
146150
PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
147151
llvm::SmallVector<StringRef> &StableDirs);
148152
} // namespace dependencies

0 commit comments

Comments
 (0)