20 using namespace clang;
21 using namespace tooling;
22 using namespace dependencies;
29 DependencyConsumerForwarder(std::unique_ptr<DependencyOutputOptions> Opts,
35 for (
const auto &File : getDependencies()) {
37 llvm::sys::path::remove_dots(CanonPath,
true);
38 C.handleFileDependency(*Opts, CanonPath);
43 std::unique_ptr<DependencyOutputOptions> Opts;
51 ProxyFileSystemWithoutChdir(
55 llvm::ErrorOr<std::string> getCurrentWorkingDirectory()
const override {
56 assert(!CWD.empty() &&
"empty CWD");
60 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override {
73 DependencyScanningAction(
78 : WorkingDirectory(WorkingDirectory), Consumer(Consumer),
79 DepFS(
std::move(DepFS)), PPSkipMappings(PPSkipMappings),
82 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
84 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
88 Compiler.setInvocation(std::move(Invocation));
91 Compiler.getDiagnosticOpts().ShowCarets =
false;
93 Compiler.createDiagnostics(DiagConsumer,
false);
94 if (!Compiler.hasDiagnostics())
103 DepFS->IgnoredFiles.clear();
105 DepFS->IgnoredFiles.insert(Entry.Path);
107 DepFS->IgnoredFiles.insert(Entry);
112 CI, Compiler.getDiagnostics(), DepFS));
117 Compiler.getPreprocessorOpts()
118 .ExcludedConditionalDirectiveSkipMappings = PPSkipMappings;
122 Compiler.setFileManager(FileMgr);
123 Compiler.createSourceManager(*FileMgr);
132 auto Opts = std::make_unique<DependencyOutputOptions>(
133 std::move(Compiler.getInvocation().getDependencyOutputOpts()));
135 if (Opts->Targets.empty())
136 Opts->Targets = {
"clang-scan-deps dependency"};
140 Compiler.addDependencyCollector(
141 std::make_shared<DependencyConsumerForwarder>(std::move(Opts),
145 Compiler.addDependencyCollector(
146 std::make_shared<ModuleDepCollector>(Compiler, Consumer));
150 Consumer.handleContextHash(Compiler.getInvocation().getModuleHash());
152 auto Action = std::make_unique<PreprocessOnlyAction>();
153 const bool Result = Compiler.ExecuteAction(*Action);
160 StringRef WorkingDirectory;
171 : Format(Service.getFormat()) {
173 PCHContainerOps = std::make_shared<PCHContainerOperations>();
174 RealFS =
new ProxyFileSystemWithoutChdir(llvm::vfs::getRealFileSystem());
177 std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
190 std::string DiagnosticOutput;
191 llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
194 if (BodyShouldSucceed(DiagPrinter))
195 return llvm::Error::success();
196 return llvm::make_error<llvm::StringError>(DiagnosticsOS.str(),
197 llvm::inconvertibleErrorCode());
201 const std::string &Input, StringRef WorkingDirectory,
203 RealFS->setCurrentWorkingDirectory(WorkingDirectory);
213 DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
214 PPSkipMappings.get(), Format);
215 return !Tool.
run(&Action);
HeaderSearchOptions & getHeaderSearchOpts()
Implements support for file system lookup, file system caching, and directory search management...
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Concrete class used by the front-end to report problems and issues.
Builds a dependency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
static llvm::Error runWithDiags(DiagnosticOptions *DiagOpts, llvm::function_ref< bool(DiagnosticConsumer &DC)> BodyShouldSucceed)
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Options for controlling the compiler diagnostics engine.
void setVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Dataflow Directional Tag Classes.
void clearStatCache()
Removes the FileSystemStatCache object from the manager.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
Helper class for holding the data necessary to invoke the compiler.
Keeps track of options that affect how file operations are performed.
llvm::DenseMap< const llvm::MemoryBuffer *, const PreprocessorSkippedRangeMapping * > ExcludedPreprocessorDirectiveSkipMapping
The datastructure that holds the mapping between the active memory buffers and the individual skip ma...