@@ -28,16 +28,82 @@ namespace dependencies {
28
28
29
29
class DependencyConsumer ;
30
30
31
+ // / This is used to refer to a specific module.
32
+ // /
33
+ // / See \c ModuleDeps for details about what these members mean.
34
+ struct ClangModuleDep {
35
+ std::string ModuleName;
36
+ std::string ContextHash;
37
+ };
38
+
31
39
struct ModuleDeps {
40
+ // / The name of the module. This may include `:` for C++20 module partitons,
41
+ // / or a header-name for C++20 header units.
32
42
std::string ModuleName;
33
- std::string ClangModuleMapFile;
34
- std::string ModulePCMPath;
43
+
44
+ // / The context hash of a module represents the set of compiler options that
45
+ // / may make one version of a module incompatible with another. This includes
46
+ // / things like language mode, predefined macros, header search paths, etc...
47
+ // /
48
+ // / Modules with the same name but a different \c ContextHash should be
49
+ // / treated as separate modules for the purpose of a build.
35
50
std::string ContextHash;
51
+
52
+ // / The path to the modulemap file which defines this module.
53
+ // /
54
+ // / This can be used to explicitly build this module. This file will
55
+ // / additionally appear in \c FileDeps as a dependency.
56
+ std::string ClangModuleMapFile;
57
+
58
+ // / The path to where an implicit build would put the PCM for this module.
59
+ std::string ImplicitModulePCMPath;
60
+
61
+ // / A collection of absolute paths to files that this module directly depends
62
+ // / on, not including transitive dependencies.
36
63
llvm::StringSet<> FileDeps;
37
- llvm::StringSet<> ClangModuleDeps;
64
+
65
+ // / A list of modules this module directly depends on, not including
66
+ // / transitive dependencies.
67
+ // /
68
+ // / This may include modules with a different context hash when it can be
69
+ // / determined that the differences are benign for this compilation.
70
+ std::vector<ClangModuleDep> ClangModuleDeps;
71
+
72
+ // / A partial command line that can be used to build this module.
73
+ // /
74
+ // / Call \c getFullCommandLine() to get a command line suitable for passing to
75
+ // / clang.
76
+ std::vector<std::string> NonPathCommandLine;
77
+
78
+ // Used to track which modules that were discovered were directly imported by
79
+ // the primary TU.
38
80
bool ImportedByMainFile = false ;
81
+
82
+ // / Gets the full command line suitable for passing to clang.
83
+ // /
84
+ // / \param LookupPCMPath this function is called to fill in `-fmodule-file=`
85
+ // / flags and for the `-o` flag. It needs to return a
86
+ // / path for where the PCM for the given module is to
87
+ // / be located.
88
+ // / \param LookupModuleDeps this fucntion is called to collect the full
89
+ // / transitive set of dependencies for this
90
+ // / compilation.
91
+ std::vector<std::string> getFullCommandLine (
92
+ std::function<StringRef(ClangModuleDep)> LookupPCMPath,
93
+ std::function<const ModuleDeps &(ClangModuleDep)> LookupModuleDeps) const ;
39
94
};
40
95
96
+ namespace detail {
97
+ // / Append the `-fmodule-file=` and `-fmodule-map-file=` arguments for the
98
+ // / modules in \c Modules transitively, along with other needed arguments to
99
+ // / use explicitly built modules.
100
+ void appendCommonModuleArguments (
101
+ llvm::ArrayRef<ClangModuleDep> Modules,
102
+ std::function<StringRef(ClangModuleDep)> LookupPCMPath,
103
+ std::function<const ModuleDeps &(ClangModuleDep)> LookupModuleDeps,
104
+ std::vector<std::string> &Result);
105
+ } // namespace detail
106
+
41
107
class ModuleDepCollector ;
42
108
43
109
class ModuleDepCollectorPP final : public PPCallbacks {
@@ -54,6 +120,8 @@ class ModuleDepCollectorPP final : public PPCallbacks {
54
120
StringRef SearchPath, StringRef RelativePath,
55
121
const Module *Imported,
56
122
SrcMgr::CharacteristicKind FileType) override ;
123
+ void moduleImport (SourceLocation ImportLoc, ModuleIdPath Path,
124
+ const Module *Imported) override ;
57
125
58
126
void EndOfMainFile () override ;
59
127
@@ -62,16 +130,18 @@ class ModuleDepCollectorPP final : public PPCallbacks {
62
130
ModuleDepCollector &MDC;
63
131
llvm::DenseSet<const Module *> DirectDeps;
64
132
133
+ void handleImport (const Module *Imported);
65
134
void handleTopLevelModule (const Module *M);
66
- void addAllSubmoduleDeps (const Module *M, ModuleDeps &MD);
67
- void addModuleDep ( const Module *M, ModuleDeps &MD );
68
-
69
- void addDirectDependencies ( const Module *Mod );
135
+ void addAllSubmoduleDeps (const Module *M, ModuleDeps &MD,
136
+ llvm::DenseSet< const Module *> &AddedModules );
137
+ void addModuleDep ( const Module *M, ModuleDeps &MD,
138
+ llvm::DenseSet< const Module *> &AddedModules );
70
139
};
71
140
72
141
class ModuleDepCollector final : public DependencyCollector {
73
142
public:
74
- ModuleDepCollector (CompilerInstance &I, DependencyConsumer &C);
143
+ ModuleDepCollector (std::unique_ptr<DependencyOutputOptions> Opts,
144
+ CompilerInstance &I, DependencyConsumer &C);
75
145
76
146
void attachToPreprocessor (Preprocessor &PP) override ;
77
147
void attachToASTReader (ASTReader &R) override ;
@@ -85,6 +155,7 @@ class ModuleDepCollector final : public DependencyCollector {
85
155
std::string ContextHash;
86
156
std::vector<std::string> MainDeps;
87
157
std::unordered_map<std::string, ModuleDeps> Deps;
158
+ std::unique_ptr<DependencyOutputOptions> Opts;
88
159
};
89
160
90
161
} // end namespace dependencies
0 commit comments