1 //===- DependencyScanningWorker.h - clang-scan-deps worker ===---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H
12 #include "clang/Basic/DiagnosticOptions.h"
13 #include "clang/Basic/FileManager.h"
14 #include "clang/Basic/LLVM.h"
15 #include "clang/Frontend/PCHContainerOperations.h"
16 #include "clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h"
17 #include "clang/Tooling/CompilationDatabase.h"
18 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
19 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
20 #include "llvm/Support/Error.h"
21 #include "llvm/Support/FileSystem.h"
26 class DependencyOutputOptions;
29 namespace dependencies {
31 class DependencyScanningWorkerFilesystem;
33 class DependencyConsumer {
35 virtual ~DependencyConsumer() {}
37 virtual void handleFileDependency(const DependencyOutputOptions &Opts,
38 StringRef Filename) = 0;
40 virtual void handleModuleDependency(ModuleDeps MD) = 0;
42 virtual void handleContextHash(std::string Hash) = 0;
45 /// An individual dependency scanning worker that is able to run on its own
48 /// The worker computes the dependencies for the input files by preprocessing
49 /// sources either using a fast mode where the source files are minimized, or
50 /// using the regular processing run.
51 class DependencyScanningWorker {
53 DependencyScanningWorker(DependencyScanningService &Service);
55 /// Run the dependency scanning tool for a given clang driver invocation (as
56 /// specified for the given Input in the CDB), and report the discovered
57 /// dependencies to the provided consumer.
59 /// \returns A \c StringError with the diagnostic output if clang errors
60 /// occurred, success otherwise.
61 llvm::Error computeDependencies(const std::string &Input,
62 StringRef WorkingDirectory,
63 const CompilationDatabase &CDB,
64 DependencyConsumer &Consumer);
67 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
68 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
69 std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
71 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS;
72 /// The file system that is used by each worker when scanning for
73 /// dependencies. This filesystem persists accross multiple compiler
75 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
76 /// The file manager that is reused accross multiple invocations by this
77 /// worker. If null, the file manager will not be reused.
78 llvm::IntrusiveRefCntPtr<FileManager> Files;
79 ScanningOutputFormat Format;
82 } // end namespace dependencies
83 } // end namespace tooling
84 } // end namespace clang
86 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H