clang 17.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
44 virtual void handleBuildCommand(Command Cmd) = 0;
45
46 virtual void
48
49 virtual void handleFileDependency(StringRef Filename) = 0;
50
52
53 virtual void handleModuleDependency(ModuleDeps MD) = 0;
54
55 virtual void handleContextHash(std::string Hash) = 0;
56
57 virtual std::string lookupModuleOutput(const ModuleID &ID,
58 ModuleOutputKind Kind) = 0;
59};
60
61/// An individual dependency scanning worker that is able to run on its own
62/// thread.
63///
64/// The worker computes the dependencies for the input files by preprocessing
65/// sources either using a fast mode where the source files are minimized, or
66/// using the regular processing run.
68public:
71
72 /// Run the dependency scanning tool for a given clang driver command-line,
73 /// and report the discovered dependencies to the provided consumer. If \p
74 /// ModuleName isn't empty, this function reports the dependencies of module
75 /// \p ModuleName.
76 ///
77 /// \returns false if clang errors occurred (with diagnostics reported to
78 /// \c DiagConsumer), true otherwise.
79 bool computeDependencies(StringRef WorkingDirectory,
80 const std::vector<std::string> &CommandLine,
81 DependencyConsumer &DepConsumer,
82 DiagnosticConsumer &DiagConsumer,
83 std::optional<StringRef> ModuleName = std::nullopt);
84 /// \returns A \c StringError with the diagnostic output if clang errors
85 /// occurred, success otherwise.
86 llvm::Error
87 computeDependencies(StringRef WorkingDirectory,
88 const std::vector<std::string> &CommandLine,
89 DependencyConsumer &Consumer,
90 std::optional<StringRef> ModuleName = std::nullopt);
91
92 bool shouldEagerLoadModules() const { return EagerLoadModules; }
93
94private:
95 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
96 /// The file system to be used during the scan.
97 /// This is either \c FS passed in the constructor (when performing canonical
98 /// preprocessing), or \c DepFS (when performing dependency directives scan).
100 /// When performing dependency directives scan, this is the caching (and
101 /// dependency-directives-extracting) filesystem overlaid on top of \c FS
102 /// (passed in the constructor).
105 /// Whether to optimize the modules' command-line arguments.
106 bool OptimizeArgs;
107 /// Whether to set up command-lines to load PCM files eagerly.
108 bool EagerLoadModules;
109};
110
111} // end namespace dependencies
112} // end namespace tooling
113} // end namespace clang
114
115#endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
Defines the clang::FileManager interface and associated types.
StringRef Filename
Definition: Format.cpp:2772
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:1740
virtual void handleModuleDependency(ModuleDeps MD)=0
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD)=0
virtual void handleDependencyOutputOpts(const DependencyOutputOptions &Opts)=0
virtual void handleBuildCommand(Command Cmd)=0
virtual std::string lookupModuleOutput(const ModuleID &ID, ModuleOutputKind Kind)=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, DiagnosticConsumer &DiagConsumer, std::optional< StringRef > ModuleName=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.
ScanningOutputFormat
The format that is output by the dependency scanner.
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.