clang 23.0.0git
DependencyScanningUtils.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_DEPENDENCYSCANNING_DEPENDENCYSCANNINGUTILS_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGUTILS_H
11
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/MapVector.h"
19#include <string>
20#include <vector>
21
22namespace clang {
23namespace dependencies {
25public:
26 FullDependencyConsumer(const llvm::DenseSet<ModuleID> &AlreadySeen)
27 : AlreadySeen(AlreadySeen) {}
28
29 void handleBuildCommand(Command Cmd) override {
30 Commands.push_back(std::move(Cmd));
31 }
32
34
35 void handleFileDependency(StringRef File) override {
36 Dependencies.push_back(std::string(File));
37 }
38
40 PrebuiltModuleDeps.emplace_back(std::move(PMD));
41 }
42
44 ClangModuleDeps[MD.ID] = std::move(MD);
45 }
46
48 DirectModuleDeps.push_back(ID);
49 }
50
51 void handleVisibleModule(std::string ModuleName) override {
52 VisibleModules.push_back(ModuleName);
53 }
54
55 void handleContextHash(std::string Hash) override {
56 ContextHash = std::move(Hash);
57 }
58
60 std::optional<P1689ModuleInfo> Provided,
61 std::vector<P1689ModuleInfo> Requires) override {
62 ModuleName = Provided ? Provided->ModuleName : "";
63 llvm::transform(Requires, std::back_inserter(NamedModuleDeps),
64 [](const auto &Module) { return Module.ModuleName; });
65 }
66
68
69private:
70 std::vector<std::string> Dependencies;
71 std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
72 llvm::MapVector<ModuleID, ModuleDeps> ClangModuleDeps;
73 std::string ModuleName;
74 std::vector<std::string> NamedModuleDeps;
75 std::vector<ModuleID> DirectModuleDeps;
76 std::vector<std::string> VisibleModules;
77 std::vector<Command> Commands;
78 std::string ContextHash;
79 const llvm::DenseSet<ModuleID> &AlreadySeen;
80};
81
82/// A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
84 llvm::function_ref<std::string(const ModuleDeps &, ModuleOutputKind)>;
85
86/// A simple dependency action controller that uses a callback. If no callback
87/// is provided, it is assumed that looking up module outputs is unreachable.
89public:
91
92 static std::string lookupUnreachableModuleOutput(const ModuleDeps &MD,
93 ModuleOutputKind Kind) {
94 llvm::report_fatal_error("unexpected call to lookupModuleOutput");
95 };
96
103
104 std::unique_ptr<DependencyActionController> clone() const override {
105 return std::make_unique<CallbackActionController>(LookupModuleOutput);
106 }
107
108 std::string lookupModuleOutput(const ModuleDeps &MD,
109 ModuleOutputKind Kind) override {
110 return LookupModuleOutput(MD, Kind);
111 }
112
113protected:
115};
116
117} // end namespace dependencies
118} // end namespace clang
119
120#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGUTILS_H
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Describes a module or submodule.
Definition Module.h:301
static std::string lookupUnreachableModuleOutput(const ModuleDeps &MD, ModuleOutputKind Kind)
CallbackActionController(LookupModuleOutputCallback LMO)
std::unique_ptr< DependencyActionController > clone() const override
Creates a copy of the controller. The result must be both thread-safe.
std::string lookupModuleOutput(const ModuleDeps &MD, ModuleOutputKind Kind) override
Provides output path for a given module dependency. Must be thread-safe.
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
void handleDependencyOutputOpts(const DependencyOutputOptions &) override
void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override
void handleContextHash(std::string Hash) override
FullDependencyConsumer(const llvm::DenseSet< ModuleID > &AlreadySeen)
void handleProvidedAndRequiredStdCXXModules(std::optional< P1689ModuleInfo > Provided, std::vector< P1689ModuleInfo > Requires) override
void handleVisibleModule(std::string ModuleName) override
llvm::function_ref< std::string(const ModuleDeps &, ModuleOutputKind)> LookupModuleOutputCallback
A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
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.
ModuleID ID
The identifier of the module.
This is used to identify a specific module.
Modular dependency that has already been built prior to the dependency scan.
The full dependencies and module graph for a specific input.