@@ -161,48 +161,17 @@ static void sanitizeDiagOpts(DiagnosticOptions &DiagOpts) {
161
161
DiagOpts.IgnoreWarnings = true ;
162
162
}
163
163
164
- struct IncludeTreePPCallbacks : public PPCallbacks {
165
- DependencyActionController &Controller;
166
- Preprocessor &PP;
167
-
168
- public:
169
- IncludeTreePPCallbacks (DependencyActionController &Controller,
170
- Preprocessor &PP)
171
- : Controller(Controller), PP(PP) {}
172
-
173
- void LexedFileChanged (FileID FID, LexedFileChangeReason Reason,
174
- SrcMgr::CharacteristicKind FileType, FileID PrevFID,
175
- SourceLocation Loc) override {
176
- switch (Reason) {
177
- case LexedFileChangeReason::EnterFile:
178
- Controller.enteredInclude (PP, FID);
179
- break ;
180
- case LexedFileChangeReason::ExitFile: {
181
- Controller.exitedInclude (PP, FID, PrevFID, Loc);
182
- break ;
183
- }
184
- }
185
- }
186
-
187
- void HasInclude (SourceLocation Loc, StringRef FileName, bool IsAngled,
188
- Optional<FileEntryRef> File,
189
- SrcMgr::CharacteristicKind FileType) override {
190
- Controller.handleHasIncludeCheck (PP, File.has_value ());
191
- }
192
- };
193
-
194
- class IncludeTreeCollector : public DependencyFileGenerator {
195
- DependencyActionController &Controller;
196
- std::unique_ptr<DependencyOutputOptions> Opts;
197
- bool EmitDependencyFile = false ;
164
+ // / Builds a dependency file after reversing prefix mappings. This allows
165
+ // / emitting a .d file that has real paths where they would otherwise be
166
+ // / canonicalized.
167
+ class ReversePrefixMappingDependencyFileGenerator
168
+ : public DependencyFileGenerator {
198
169
llvm::PrefixMapper ReverseMapper;
199
170
200
171
public:
201
- IncludeTreeCollector (DependencyActionController &Controller,
202
- std::unique_ptr<DependencyOutputOptions> Opts,
203
- bool EmitDependencyFile)
204
- : DependencyFileGenerator(*Opts), Controller(Controller),
205
- Opts (std::move(Opts)), EmitDependencyFile(EmitDependencyFile) {}
172
+ ReversePrefixMappingDependencyFileGenerator (
173
+ const DependencyOutputOptions &Opts)
174
+ : DependencyFileGenerator(Opts) {}
206
175
207
176
Error initialize (const CompilerInvocation &CI,
208
177
const DepscanPrefixMapping &PrefixMapping) {
@@ -217,11 +186,6 @@ class IncludeTreeCollector : public DependencyFileGenerator {
217
186
return Error::success ();
218
187
}
219
188
220
- void attachToPreprocessor (Preprocessor &PP) override {
221
- PP.addPPCallbacks (std::make_unique<IncludeTreePPCallbacks>(Controller, PP));
222
- DependencyFileGenerator::attachToPreprocessor (PP);
223
- }
224
-
225
189
void maybeAddDependency (StringRef Filename, bool FromModule, bool IsSystem,
226
190
bool IsModuleFile, bool IsMissing) override {
227
191
if (ReverseMapper.empty ())
@@ -235,11 +199,6 @@ class IncludeTreeCollector : public DependencyFileGenerator {
235
199
return DependencyFileGenerator::maybeAddDependency (
236
200
New, FromModule, IsSystem, IsModuleFile, IsMissing);
237
201
}
238
-
239
- void finishedMainFile (DiagnosticsEngine &Diags) override {
240
- if (EmitDependencyFile)
241
- DependencyFileGenerator::finishedMainFile (Diags);
242
- }
243
202
};
244
203
245
204
// / See \c WrapScanModuleBuildAction.
@@ -455,17 +414,19 @@ class DependencyScanningAction : public tooling::ToolAction {
455
414
std::make_shared<DependencyConsumerForwarder>(
456
415
std::move (Opts), WorkingDirectory, Consumer, EmitDependencyFile));
457
416
break ;
458
- case ScanningOutputFormat::IncludeTree: {
459
- auto IncTreeCollector = std::make_shared<IncludeTreeCollector>(
460
- Controller, std::move (Opts), EmitDependencyFile);
461
- if (Error E = IncTreeCollector->initialize (
462
- ScanInstance.getInvocation (), *Controller.getPrefixMapping ()))
463
- return reportError (std::move (E));
464
- ScanInstance.addDependencyCollector (std::move (IncTreeCollector));
465
- break ;
466
- }
417
+ case ScanningOutputFormat::IncludeTree:
467
418
case ScanningOutputFormat::Full:
468
419
case ScanningOutputFormat::FullTree:
420
+ if (EmitDependencyFile) {
421
+ auto DFG =
422
+ std::make_shared<ReversePrefixMappingDependencyFileGenerator>(
423
+ *Opts);
424
+ if (auto *Mapping = Controller.getPrefixMapping ())
425
+ if (auto E = DFG->initialize (ScanInstance.getInvocation (), *Mapping))
426
+ return reportError (std::move (E));
427
+ ScanInstance.addDependencyCollector (std::move (DFG));
428
+ }
429
+
469
430
MDC = std::make_shared<ModuleDepCollector>(
470
431
std::move (Opts), ScanInstance, Consumer, Controller,
471
432
OriginalInvocation, OptimizeArgs, EagerLoadModules);
0 commit comments