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_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_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/DependencyScanning/DependencyScanningService.h"
18 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/FileSystem.h"
25 class DependencyOutputOptions;
28 namespace dependencies {
30 class DependencyScanningWorkerFilesystem;
32 class DependencyConsumer {
34 virtual ~DependencyConsumer() {}
37 handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
39 virtual void handleFileDependency(StringRef Filename) = 0;
41 virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0;
43 virtual void handleModuleDependency(ModuleDeps MD) = 0;
45 virtual void handleContextHash(std::string Hash) = 0;
48 /// An individual dependency scanning worker that is able to run on its own
51 /// The worker computes the dependencies for the input files by preprocessing
52 /// sources either using a fast mode where the source files are minimized, or
53 /// using the regular processing run.
54 class DependencyScanningWorker {
56 DependencyScanningWorker(DependencyScanningService &Service);
58 /// Run the dependency scanning tool for a given clang driver command-line,
59 /// and report the discovered dependencies to the provided consumer. If \p
60 /// ModuleName isn't empty, this function reports the dependencies of module
63 /// \returns A \c StringError with the diagnostic output if clang errors
64 /// occurred, success otherwise.
65 llvm::Error computeDependencies(StringRef WorkingDirectory,
66 const std::vector<std::string> &CommandLine,
67 DependencyConsumer &Consumer,
68 llvm::Optional<StringRef> ModuleName = None);
71 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
72 std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
74 /// The physical filesystem overlaid by `InMemoryFS`.
75 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS;
76 /// The in-memory filesystem laid on top the physical filesystem in `RealFS`.
77 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFS;
78 /// The file system that is used by each worker when scanning for
79 /// dependencies. This filesystem persists across multiple compiler
81 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
82 /// The file manager that is reused across multiple invocations by this
83 /// worker. If null, the file manager will not be reused.
84 llvm::IntrusiveRefCntPtr<FileManager> Files;
85 ScanningOutputFormat Format;
86 /// Whether to optimize the modules' command-line arguments.
90 } // end namespace dependencies
91 } // end namespace tooling
92 } // end namespace clang
94 #endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H