clang 22.0.0git
DependencyScanningWorker.h
Go to the documentation of this file.
1//===- DependencyScanningWorker.h - clang-scan-deps worker ===---*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
10#define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
11
14#include "clang/Basic/LLVM.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/FileSystem.h"
20#include "llvm/Support/MemoryBufferRef.h"
21#include <optional>
22#include <string>
23
24namespace clang {
25
26class DependencyOutputOptions;
27
28namespace tooling {
29namespace dependencies {
30
31class DependencyScanningWorkerFilesystem;
32
33/// A command-line tool invocation that is part of building a TU.
34///
35/// \see TranslationUnitDeps::Commands.
36struct Command {
37 std::string Executable;
38 std::vector<std::string> Arguments;
39};
40
42public:
44
46 std::optional<P1689ModuleInfo> Provided,
47 std::vector<P1689ModuleInfo> Requires) {}
48
50
51 virtual void
53
54 virtual void handleFileDependency(StringRef Filename) = 0;
55
57
58 virtual void handleModuleDependency(ModuleDeps MD) = 0;
59
61
62 virtual void handleVisibleModule(std::string ModuleName) = 0;
63
64 virtual void handleContextHash(std::string Hash) = 0;
65};
66
67/// Dependency scanner callbacks that are used during scanning to influence the
68/// behaviour of the scan - for example, to customize the scanned invocations.
70public:
72
73 virtual std::string lookupModuleOutput(const ModuleDeps &MD,
75};
76
77/// An individual dependency scanning worker that is able to run on its own
78/// thread.
79///
80/// The worker computes the dependencies for the input files by preprocessing
81/// sources either using a fast mode where the source files are minimized, or
82/// using the regular processing run.
84public:
85 /// Construct a dependency scanning worker.
86 ///
87 /// @param Service The parent service. Must outlive the worker.
88 /// @param FS The filesystem for the worker to use.
91
92 /// Run the dependency scanning tool for a given clang driver command-line,
93 /// and report the discovered dependencies to the provided consumer. If
94 /// TUBuffer is not nullopt, it is used as TU input for the dependency
95 /// scanning. Otherwise, the input should be included as part of the
96 /// command-line.
97 ///
98 /// \returns false if clang errors occurred (with diagnostics reported to
99 /// \c DiagConsumer), true otherwise.
101 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
102 DependencyConsumer &DepConsumer, DependencyActionController &Controller,
103 DiagnosticConsumer &DiagConsumer,
104 std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt);
105
106 /// Run the dependency scanning tool for a given clang driver command-line
107 /// for a specific module.
108 ///
109 /// \returns false if clang errors occurred (with diagnostics reported to
110 /// \c DiagConsumer), true otherwise.
111 bool computeDependencies(StringRef WorkingDirectory,
112 const std::vector<std::string> &CommandLine,
113 DependencyConsumer &DepConsumer,
114 DependencyActionController &Controller,
115 DiagnosticConsumer &DiagConsumer,
116 StringRef ModuleName);
117
118 /// Run the dependency scanning tool for a given clang driver command-line
119 /// for a specific translation unit via file system or memory buffer.
120 ///
121 /// \returns A \c StringError with the diagnostic output if clang errors
122 /// occurred, success otherwise.
123 llvm::Error computeDependencies(
124 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
125 DependencyConsumer &Consumer, DependencyActionController &Controller,
126 std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt);
127
128 /// Run the dependency scanning tool for a given clang driver command-line
129 /// for a specific module.
130 ///
131 /// \returns A \c StringError with the diagnostic output if clang errors
132 /// occurred, success otherwise.
133 llvm::Error computeDependencies(StringRef WorkingDirectory,
134 const std::vector<std::string> &CommandLine,
135 DependencyConsumer &Consumer,
136 DependencyActionController &Controller,
137 StringRef ModuleName);
138
139 llvm::vfs::FileSystem &getVFS() const { return *BaseFS; }
140
141private:
142 /// The parent dependency scanning service.
144 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
145 /// The file system to be used during the scan.
146 /// This is either \c FS passed in the constructor (when performing canonical
147 /// preprocessing), or \c DepFS (when performing dependency directives scan).
149 /// When performing dependency directives scan, this is the caching (and
150 /// dependency-directives-extracting) filesystem overlaid on top of \c FS
151 /// (passed in the constructor).
153
154 /// Private helper functions.
155 bool scanDependencies(StringRef WorkingDirectory,
156 const std::vector<std::string> &CommandLine,
157 DependencyConsumer &Consumer,
158 DependencyActionController &Controller,
161 std::optional<StringRef> ModuleName);
162};
163
164} // end namespace dependencies
165} // end namespace tooling
166} // end namespace clang
167
168#endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::FileManager interface and associated types.
StringRef Filename
Definition: Format.cpp:3177
CompileCommand Cmd
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1722
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
virtual std::string lookupModuleOutput(const ModuleDeps &MD, ModuleOutputKind Kind)=0
virtual void handleModuleDependency(ModuleDeps MD)=0
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD)=0
virtual void handleDependencyOutputOpts(const DependencyOutputOptions &Opts)=0
virtual void handleProvidedAndRequiredStdCXXModules(std::optional< P1689ModuleInfo > Provided, std::vector< P1689ModuleInfo > Requires)
virtual void handleDirectModuleDependency(ModuleID MD)=0
virtual void handleVisibleModule(std::string ModuleName)=0
virtual void handleFileDependency(StringRef Filename)=0
virtual void handleContextHash(std::string Hash)=0
The dependency scanning service contains shared configuration and state that is used by the individua...
An individual dependency scanning worker that is able to run on its own thread.
bool computeDependencies(StringRef WorkingDirectory, const std::vector< std::string > &CommandLine, DependencyConsumer &DepConsumer, DependencyActionController &Controller, DiagnosticConsumer &DiagConsumer, std::optional< llvm::MemoryBufferRef > TUBuffer=std::nullopt)
Run the dependency scanning tool for a given clang driver command-line, and report the discovered dep...
ModuleOutputKind
An output from a module compilation, such as the path of the module file.
The JSON file list parser is used to communicate input to InstallAPI.
A command-line tool invocation that is part of building a TU.
This is used to identify a specific module.
Modular dependency that has already been built prior to the dependency scan.