1717#include " clang/Tooling/DependencyScanning/ModuleDepCollector.h"
1818#include " llvm/Support/Error.h"
1919#include " llvm/Support/FileSystem.h"
20+ #include " llvm/Support/MemoryBufferRef.h"
2021#include < optional>
2122#include < string>
2223
@@ -83,9 +84,21 @@ class DependencyScanningWorker {
8384 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
8485
8586 // / Run the dependency scanning tool for a given clang driver command-line,
86- // / and report the discovered dependencies to the provided consumer. If \p
87- // / ModuleName isn't empty, this function reports the dependencies of module
88- // / \p ModuleName.
87+ // / and report the discovered dependencies to the provided consumer. If
88+ // / TUBuffer is not nullopt, it is used as TU input for the dependency
89+ // / scanning. Otherwise, the input should be included as part of the
90+ // / command-line.
91+ // /
92+ // / \returns false if clang errors occurred (with diagnostics reported to
93+ // / \c DiagConsumer), true otherwise.
94+ bool computeDependencies (
95+ StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
96+ DependencyConsumer &DepConsumer, DependencyActionController &Controller,
97+ DiagnosticConsumer &DiagConsumer,
98+ std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt );
99+
100+ // / Run the dependency scanning tool for a given clang driver command-line
101+ // / for a specific module.
89102 // /
90103 // / \returns false if clang errors occurred (with diagnostics reported to
91104 // / \c DiagConsumer), true otherwise.
@@ -94,13 +107,28 @@ class DependencyScanningWorker {
94107 DependencyConsumer &DepConsumer,
95108 DependencyActionController &Controller,
96109 DiagnosticConsumer &DiagConsumer,
97- std::optional<StringRef> ModuleName = std::nullopt );
110+ StringRef ModuleName);
111+
112+ // / Run the dependency scanning tool for a given clang driver command-line
113+ // / for a specific translation unit via file system or memory buffer.
114+ // /
98115 // / \returns A \c StringError with the diagnostic output if clang errors
99116 // / occurred, success otherwise.
100117 llvm::Error computeDependencies (
101118 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
102119 DependencyConsumer &Consumer, DependencyActionController &Controller,
103- std::optional<StringRef> ModuleName = std::nullopt );
120+ std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt );
121+
122+ // / Run the dependency scanning tool for a given clang driver command-line
123+ // / for a specific module.
124+ // /
125+ // / \returns A \c StringError with the diagnostic output if clang errors
126+ // / occurred, success otherwise.
127+ llvm::Error computeDependencies (StringRef WorkingDirectory,
128+ const std::vector<std::string> &CommandLine,
129+ DependencyConsumer &Consumer,
130+ DependencyActionController &Controller,
131+ StringRef ModuleName);
104132
105133 bool shouldEagerLoadModules () const { return EagerLoadModules; }
106134
@@ -121,6 +149,15 @@ class DependencyScanningWorker {
121149 ScanningOptimizations OptimizeArgs;
122150 // / Whether to set up command-lines to load PCM files eagerly.
123151 bool EagerLoadModules;
152+
153+ // / Private helper functions.
154+ bool scanDependencies (StringRef WorkingDirectory,
155+ const std::vector<std::string> &CommandLine,
156+ DependencyConsumer &Consumer,
157+ DependencyActionController &Controller,
158+ DiagnosticConsumer &DC,
159+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
160+ std::optional<StringRef> ModuleName);
124161};
125162
126163} // end namespace dependencies
0 commit comments