clang 24.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
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/ADT/MapVector.h"
18#include <string>
19#include <vector>
20
21namespace clang {
22namespace dependencies {
24public:
25 FullDependencyConsumer(const llvm::DenseSet<ModuleID> &AlreadySeen)
26 : AlreadySeen(AlreadySeen) {}
27
28 void handleBuildCommand(Command Cmd) override {
29 Commands.push_back(std::move(Cmd));
30 }
31
33
34 void handleFileDependency(StringRef File) override {
35 Dependencies.push_back(std::string(File));
36 }
37
39 PrebuiltModuleDeps.emplace_back(std::move(PMD));
40 }
41
43 ClangModuleDeps[MD.ID] = std::move(MD);
44 }
45
47 DirectModuleDeps.push_back(ID);
48 }
49
50 void handleVisibleModule(std::string ModuleName) override {
51 VisibleModules.push_back(ModuleName);
52 }
53
54 void handleContextHash(std::string Hash) override {
55 ContextHash = std::move(Hash);
56 }
57
59 std::optional<P1689ModuleInfo> Provided,
60 std::vector<P1689ModuleInfo> Requires) override {
61 ModuleName = Provided ? Provided->ModuleName : "";
62 llvm::transform(Requires, std::back_inserter(NamedModuleDeps),
63 [](const auto &Module) { return Module.ModuleName; });
64 }
65
67
68private:
69 std::vector<std::string> Dependencies;
70 std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
71 llvm::MapVector<ModuleID, ModuleDeps> ClangModuleDeps;
72 std::string ModuleName;
73 std::vector<std::string> NamedModuleDeps;
74 std::vector<ModuleID> DirectModuleDeps;
75 std::vector<std::string> VisibleModules;
76 std::vector<Command> Commands;
77 std::string ContextHash;
78 const llvm::DenseSet<ModuleID> &AlreadySeen;
79};
80
81/// A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
83 llvm::function_ref<std::string(const ModuleDeps &, ModuleOutputKind)>;
84
85/// A simple dependency action controller that uses a callback. If no callback
86/// is provided, it is assumed that looking up module outputs is unreachable.
88public:
90
91 static std::string lookupUnreachableModuleOutput(const ModuleDeps &MD,
92 ModuleOutputKind Kind) {
93 llvm::report_fatal_error("unexpected call to lookupModuleOutput");
94 };
95
102
103 std::unique_ptr<DependencyActionController> clone() const override {
104 return std::make_unique<CallbackActionController>(LookupModuleOutput);
105 }
106
107 std::string lookupModuleOutput(const ModuleDeps &MD,
108 ModuleOutputKind Kind) override {
109 return LookupModuleOutput(MD, Kind);
110 }
111
112protected:
114};
115
116} // end namespace dependencies
117} // end namespace clang
118
119#endif // LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGUTILS_H
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Describes a module or submodule.
Definition Module.h:340
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.