clang 20.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 <optional>
21#include <string>
22
23namespace clang {
24
25class DependencyOutputOptions;
26
27namespace tooling {
28namespace dependencies {
29
30class DependencyScanningWorkerFilesystem;
31
32/// A command-line tool invocation that is part of building a TU.
33///
34/// \see TranslationUnitDeps::Commands.
35struct Command {
36 std::string Executable;
37 std::vector<std::string> Arguments;
38};
39
41public:
43
45 std::optional<P1689ModuleInfo> Provided,
46 std::vector<P1689ModuleInfo> Requires) {}
47
49
50 virtual void
52
53 virtual void handleFileDependency(StringRef Filename) = 0;
54
56
57 virtual void handleModuleDependency(ModuleDeps MD) = 0;
58
60
61 virtual void handleContextHash(std::string Hash) = 0;
62};
63
64/// Dependency scanner callbacks that are used during scanning to influence the
65/// behaviour of the scan - for example, to customize the scanned invocations.
67public:
69
70 virtual std::string lookupModuleOutput(const ModuleID &ID,
72};
73
74/// An individual dependency scanning worker that is able to run on its own
75/// thread.
76///
77/// The worker computes the dependencies for the input files by preprocessing
78/// sources either using a fast mode where the source files are minimized, or
79/// using the regular processing run.
81public:
84
85 /// 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.
89 ///
90 /// \returns false if clang errors occurred (with diagnostics reported to
91 /// \c DiagConsumer), true otherwise.
92 bool computeDependencies(StringRef WorkingDirectory,
93 const std::vector<std::string> &CommandLine,
94 DependencyConsumer &DepConsumer,
96 DiagnosticConsumer &DiagConsumer,
97 std::optional<StringRef> ModuleName = std::nullopt);
98 /// \returns A \c StringError with the diagnostic output if clang errors
99 /// occurred, success otherwise.
100 llvm::Error computeDependencies(
101 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
102 DependencyConsumer &Consumer, DependencyActionController &Controller,
103 std::optional<StringRef> ModuleName = std::nullopt);
104
105 bool shouldEagerLoadModules() const { return EagerLoadModules; }
106
107 llvm::vfs::FileSystem &getVFS() const { return *BaseFS; }
108
109private:
110 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
111 /// The file system to be used during the scan.
112 /// This is either \c FS passed in the constructor (when performing canonical
113 /// preprocessing), or \c DepFS (when performing dependency directives scan).
115 /// When performing dependency directives scan, this is the caching (and
116 /// dependency-directives-extracting) filesystem overlaid on top of \c FS
117 /// (passed in the constructor).
120 /// Whether to optimize the modules' command-line arguments.
121 ScanningOptimizations OptimizeArgs;
122 /// Whether to set up command-lines to load PCM files eagerly.
123 bool EagerLoadModules;
124};
125
126} // end namespace dependencies
127} // end namespace tooling
128} // end namespace clang
129
130#endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
static char ID
Definition: Arena.cpp:183
enum clang::sema::@1726::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::FileManager interface and associated types.
StringRef Filename
Definition: Format.cpp:3053
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:1684
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
virtual std::string lookupModuleOutput(const ModuleID &ID, ModuleOutputKind Kind)=0