clang  14.0.0git
DependencyScanningTool.h
Go to the documentation of this file.
1 //===- DependencyScanningTool.h - clang-scan-deps service -----------------===//
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_DEPENDENCY_SCANNING_TOOL_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_TOOL_H
11 
16 #include "llvm/ADT/StringSet.h"
17 #include <string>
18 
19 namespace clang{
20 namespace tooling{
21 namespace dependencies{
22 
23 /// The full dependencies and module graph for a specific input.
25  /// The identifier of the C++20 module this translation unit exports.
26  ///
27  /// If the translation unit is not a module then \c ID.ModuleName is empty.
29 
30  /// A collection of absolute paths to files that this translation unit
31  /// directly depends on, not including transitive dependencies.
32  std::vector<std::string> FileDeps;
33 
34  /// A collection of prebuilt modules this translation unit directly depends
35  /// on, not including transitive dependencies.
36  std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
37 
38  /// A list of modules this translation unit directly depends on, not including
39  /// transitive dependencies.
40  ///
41  /// This may include modules with a different context hash when it can be
42  /// determined that the differences are benign for this compilation.
43  std::vector<ModuleID> ClangModuleDeps;
44 
45  /// Get additional arguments suitable for appending to the original Clang
46  /// command line.
47  ///
48  /// \param LookupPCMPath This function is called to fill in "-fmodule-file="
49  /// arguments and the "-o" argument. It needs to return
50  /// a path for where the PCM for the given module is to
51  /// be located.
52  /// \param LookupModuleDeps This function is called to collect the full
53  /// transitive set of dependencies for this
54  /// compilation and fill in "-fmodule-map-file="
55  /// arguments.
56  std::vector<std::string> getAdditionalArgs(
57  std::function<StringRef(ModuleID)> LookupPCMPath,
58  std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps) const;
59 
60  /// Get additional arguments suitable for appending to the original Clang
61  /// command line, excluding arguments containing modules-related paths:
62  /// "-fmodule-file=", "-fmodule-map-file=".
63  std::vector<std::string> getAdditionalArgsWithoutModulePaths() const;
64 };
65 
68  std::vector<ModuleDeps> DiscoveredModules;
69 };
70 
71 /// The high-level implementation of the dependency discovery tool that runs on
72 /// an individual worker thread.
74 public:
75  /// Construct a dependency scanning tool.
77 
78  /// Print out the dependency information into a string using the dependency
79  /// file format that is specified in the options (-MD is the default) and
80  /// return it. If \p ModuleName isn't empty, this function returns the
81  /// dependency information of module \p ModuleName.
82  ///
83  /// \returns A \c StringError with the diagnostic output if clang errors
84  /// occurred, dependency file contents otherwise.
86  getDependencyFile(const std::vector<std::string> &CommandLine, StringRef CWD,
87  llvm::Optional<StringRef> ModuleName = None);
88 
89  /// Collect the full module dependency graph for the input, ignoring any
90  /// modules which have already been seen. If \p ModuleName isn't empty, this
91  /// function returns the full dependency information of module \p ModuleName.
92  ///
93  /// \param AlreadySeen This stores modules which have previously been
94  /// reported. Use the same instance for all calls to this
95  /// function for a single \c DependencyScanningTool in a
96  /// single build. Use a different one for different tools,
97  /// and clear it between builds.
98  ///
99  /// \returns a \c StringError with the diagnostic output if clang errors
100  /// occurred, \c FullDependencies otherwise.
102  getFullDependencies(const std::vector<std::string> &CommandLine,
103  StringRef CWD, const llvm::StringSet<> &AlreadySeen,
104  llvm::Optional<StringRef> ModuleName = None);
105 
106 private:
108 };
109 
110 } // end namespace dependencies
111 } // end namespace tooling
112 } // end namespace clang
113 
114 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_TOOL_H
DependencyScanningService.h
clang::tooling::dependencies::FullDependencies
The full dependencies and module graph for a specific input.
Definition: DependencyScanningTool.h:24
clang::tooling::dependencies::FullDependencies::getAdditionalArgs
std::vector< std::string > getAdditionalArgs(std::function< StringRef(ModuleID)> LookupPCMPath, std::function< const ModuleDeps &(ModuleID)> LookupModuleDeps) const
Get additional arguments suitable for appending to the original Clang command line.
Definition: DependencyScanningTool.cpp:16
clang::tooling::dependencies::FullDependenciesResult
Definition: DependencyScanningTool.h:66
clang::tooling::dependencies::DependencyScanningTool::DependencyScanningTool
DependencyScanningTool(DependencyScanningService &Service)
Construct a dependency scanning tool.
Definition: DependencyScanningTool.cpp:48
clang::tooling::dependencies::DependencyScanningTool::getFullDependencies
llvm::Expected< FullDependenciesResult > getFullDependencies(const std::vector< std::string > &CommandLine, StringRef CWD, const llvm::StringSet<> &AlreadySeen, llvm::Optional< StringRef > ModuleName=None)
Collect the full module dependency graph for the input, ignoring any modules which have already been ...
Definition: DependencyScanningTool.cpp:117
clang::tooling::dependencies::FullDependencies::ID
ModuleID ID
The identifier of the C++20 module this translation unit exports.
Definition: DependencyScanningTool.h:28
llvm::Optional
Definition: LLVM.h:40
llvm::Expected
Definition: LLVM.h:41
clang::tooling::dependencies::FullDependenciesResult::DiscoveredModules
std::vector< ModuleDeps > DiscoveredModules
Definition: DependencyScanningTool.h:68
clang::tooling::dependencies::DependencyScanningTool::getDependencyFile
llvm::Expected< std::string > getDependencyFile(const std::vector< std::string > &CommandLine, StringRef CWD, llvm::Optional< StringRef > ModuleName=None)
Print out the dependency information into a string using the dependency file format that is specified...
Definition: DependencyScanningTool.cpp:52
JSONCompilationDatabase.h
clang::tooling::dependencies::FullDependencies::FileDeps
std::vector< std::string > FileDeps
A collection of absolute paths to files that this translation unit directly depends on,...
Definition: DependencyScanningTool.h:32
DependencyScanningWorker.h
clang::tooling::dependencies::DependencyScanningTool
The high-level implementation of the dependency discovery tool that runs on an individual worker thre...
Definition: DependencyScanningTool.h:73
ModuleDepCollector.h
clang::tooling::dependencies::FullDependencies::getAdditionalArgsWithoutModulePaths
std::vector< std::string > getAdditionalArgsWithoutModulePaths() const
Get additional arguments suitable for appending to the original Clang command line,...
Definition: DependencyScanningTool.cpp:34
clang::tooling::dependencies::FullDependencies::ClangModuleDeps
std::vector< ModuleID > ClangModuleDeps
A list of modules this translation unit directly depends on, not including transitive dependencies.
Definition: DependencyScanningTool.h:43
clang::tooling::dependencies::DependencyScanningWorker
An individual dependency scanning worker that is able to run on its own thread.
Definition: DependencyScanningWorker.h:54
clang::tooling::dependencies::ModuleDeps
Definition: ModuleDepCollector.h:68
clang::tooling::dependencies::DependencyScanningService
The dependency scanning service contains the shared state that is used by the invidual dependency sca...
Definition: DependencyScanningService.h:47
clang::tooling::dependencies::FullDependenciesResult::FullDeps
FullDependencies FullDeps
Definition: DependencyScanningTool.h:67
clang
Definition: CalledOnceCheck.h:17
clang::tooling::dependencies::FullDependencies::PrebuiltModuleDeps
std::vector< PrebuiltModuleDep > PrebuiltModuleDeps
A collection of prebuilt modules this translation unit directly depends on, not including transitive ...
Definition: DependencyScanningTool.h:36
clang::tooling::dependencies::ModuleID
This is used to identify a specific module.
Definition: ModuleDepCollector.h:44