Skip to content

Commit 8fe547b

Browse files
committed
[clang][cas] Update after upstream DependencyActionController change
Move cas-fs and include-tree to override DependencyActionController instead of DependencyConsumer. (cherry picked from commit b6ef080)
1 parent b00c5ca commit 8fe547b

File tree

5 files changed

+160
-197
lines changed

5 files changed

+160
-197
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct TranslationUnitDeps {
6969
std::vector<ModuleID> ClangModuleDeps;
7070

7171
/// The CASID for input file dependency tree.
72-
llvm::Optional<llvm::cas::CASID> CASFileSystemRootID;
72+
llvm::Optional<std::string> CASFileSystemRootID;
7373

7474
/// The sequence of commands required to build the translation unit. Commands
7575
/// should be executed in order.
@@ -180,6 +180,16 @@ class DependencyScanningTool {
180180
return Worker.getOrCreateFileManager();
181181
}
182182

183+
static std::unique_ptr<DependencyActionController>
184+
createActionController(DependencyScanningWorker &Worker,
185+
LookupModuleOutputCallback LookupModuleOutput,
186+
DepscanPrefixMapping PrefixMapping);
187+
188+
private:
189+
std::unique_ptr<DependencyActionController>
190+
createActionController(LookupModuleOutputCallback LookupModuleOutput,
191+
DepscanPrefixMapping PrefixMapping);
192+
183193
private:
184194
DependencyScanningWorker Worker;
185195
};
@@ -255,6 +265,30 @@ class CallbackActionController : public DependencyActionController {
255265
LookupModuleOutputCallback LookupModuleOutput;
256266
};
257267

268+
class CASFSActionController : public CallbackActionController {
269+
public:
270+
CASFSActionController(LookupModuleOutputCallback LookupModuleOutput,
271+
llvm::cas::CachingOnDiskFileSystem &CacheFS,
272+
DepscanPrefixMapping PrefixMapping);
273+
274+
llvm::Error initialize(CompilerInstance &ScanInstance,
275+
CompilerInvocation &NewInvocation) override;
276+
llvm::Error finalize(CompilerInstance &ScanInstance,
277+
CompilerInvocation &NewInvocation) override;
278+
llvm::Error
279+
initializeModuleBuild(CompilerInstance &ModuleScanInstance) override;
280+
llvm::Error
281+
finalizeModuleBuild(CompilerInstance &ModuleScanInstance) override;
282+
llvm::Error finalizeModuleInvocation(CompilerInvocation &CI,
283+
const ModuleDeps &MD) override;
284+
285+
private:
286+
llvm::cas::CachingOnDiskFileSystem &CacheFS;
287+
DepscanPrefixMapping PrefixMapping;
288+
std::optional<llvm::TreePathPrefixMapper> Mapper;
289+
CASOptions CASOpts;
290+
};
291+
258292
} // end namespace dependencies
259293
} // end namespace tooling
260294
} // end namespace clang

clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ class DependencyConsumer {
4545
public:
4646
virtual ~DependencyConsumer() {}
4747

48+
virtual void handleBuildCommand(Command Cmd) {}
49+
50+
virtual void
51+
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
52+
53+
virtual void handleFileDependency(StringRef Filename) = 0;
54+
55+
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0;
56+
57+
virtual void handleModuleDependency(ModuleDeps MD) = 0;
58+
59+
virtual void handleContextHash(std::string Hash) = 0;
60+
61+
virtual void handleCASFileSystemRootID(std::string ID) {}
62+
};
63+
64+
/// Dependency scanner callbacks that are used during scanning to influence the
65+
/// behaviour of the scan - for example, to customize the scanned invocations.
66+
class DependencyActionController {
67+
public:
68+
virtual ~DependencyActionController();
69+
70+
virtual std::string lookupModuleOutput(const ModuleID &ID,
71+
ModuleOutputKind Kind) = 0;
72+
4873
virtual llvm::Error initialize(CompilerInstance &ScanInstance,
4974
CompilerInvocation &NewInvocation) {
5075
return llvm::Error::success();
@@ -70,72 +95,18 @@ class DependencyConsumer {
7095
return llvm::Error::success();
7196
}
7297

73-
virtual void handleBuildCommand(Command Cmd) = 0;
74-
75-
virtual void
76-
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
77-
78-
virtual void handleFileDependency(StringRef Filename) = 0;
79-
80-
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0;
81-
82-
virtual void handleModuleDependency(ModuleDeps MD) = 0;
83-
84-
virtual void handleContextHash(std::string Hash) = 0;
85-
86-
virtual void handleCASFileSystemRootID(cas::CASID ID) = 0;
87-
};
88-
89-
/// Dependency scanner callbacks that are used during scanning to influence the
90-
/// behaviour of the scan - for example, to customize the scanned invocations.
91-
class DependencyActionController {
92-
public:
93-
virtual ~DependencyActionController();
94-
95-
virtual std::string lookupModuleOutput(const ModuleID &ID,
96-
ModuleOutputKind Kind) = 0;
97-
};
98-
99-
// FIXME: This may need to merge with \p DependencyConsumer in order to support
100-
// clang modules for the include-tree.
101-
class PPIncludeActionsConsumer : public DependencyConsumer {
102-
public:
103-
virtual void enteredInclude(Preprocessor &PP, FileID FID) = 0;
98+
virtual void enteredInclude(Preprocessor &PP, FileID FID) {}
10499

105100
virtual void exitedInclude(Preprocessor &PP, FileID IncludedBy,
106-
FileID Include, SourceLocation ExitLoc) = 0;
101+
FileID Include, SourceLocation ExitLoc) {}
107102

108-
virtual void handleHasIncludeCheck(Preprocessor &PP, bool Result) = 0;
103+
virtual void handleHasIncludeCheck(Preprocessor &PP, bool Result) {}
109104

110105
/// FIXME: This is temporary until we eliminate the split between consumers in
111106
/// \p DependencyScanningTool and collectors in \p DependencyScanningWorker
112107
/// and have them both in the same file. see FIXME in \p
113108
/// DependencyScanningAction::runInvocation.
114-
virtual const DepscanPrefixMapping &getPrefixMapping() = 0;
115-
116-
protected:
117-
void handleBuildCommand(Command) override {}
118-
void handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
119-
llvm::report_fatal_error("unexpected callback for include-tree");
120-
}
121-
void handleFileDependency(StringRef Filename) override {
122-
llvm::report_fatal_error("unexpected callback for include-tree");
123-
}
124-
void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
125-
llvm::report_fatal_error("unexpected callback for include-tree");
126-
}
127-
void handleModuleDependency(ModuleDeps MD) override {
128-
llvm::report_fatal_error("unexpected callback for include-tree");
129-
}
130-
void handleContextHash(std::string Hash) override {
131-
llvm::report_fatal_error("unexpected callback for include-tree");
132-
}
133-
void handleCASFileSystemRootID(cas::CASID ID) override {
134-
llvm::report_fatal_error("unexpected callback for include-tree");
135-
}
136-
std::string lookupModuleOutput(const ModuleID &, ModuleOutputKind) override {
137-
llvm::report_fatal_error("unexpected callback for include-tree");
138-
}
109+
virtual const DepscanPrefixMapping *getPrefixMapping() { return nullptr; }
139110
};
140111

141112
/// An individual dependency scanning worker that is able to run on its own
@@ -177,8 +148,8 @@ class DependencyScanningWorker {
177148
void computeDependenciesFromCompilerInvocation(
178149
std::shared_ptr<CompilerInvocation> Invocation,
179150
StringRef WorkingDirectory, DependencyConsumer &Consumer,
180-
DiagnosticConsumer &DiagsConsumer, raw_ostream *VerboseOS,
181-
bool DiagGenerationAsCompilation);
151+
DependencyActionController &Controller, DiagnosticConsumer &DiagsConsumer,
152+
raw_ostream *VerboseOS, bool DiagGenerationAsCompilation);
182153

183154
ScanningOutputFormat getScanningFormat() const { return Format; }
184155

0 commit comments

Comments
 (0)