@@ -28,16 +28,82 @@ namespace dependencies {
2828
2929class DependencyConsumer ;
3030
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+
3139struct 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.
3242 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.
3550 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.
3663 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.
3880 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 ;
3994};
4095
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+
41107class ModuleDepCollector ;
42108
43109class ModuleDepCollectorPP final : public PPCallbacks {
@@ -54,6 +120,8 @@ class ModuleDepCollectorPP final : public PPCallbacks {
54120 StringRef SearchPath, StringRef RelativePath,
55121 const Module *Imported,
56122 SrcMgr::CharacteristicKind FileType) override ;
123+ void moduleImport (SourceLocation ImportLoc, ModuleIdPath Path,
124+ const Module *Imported) override ;
57125
58126 void EndOfMainFile () override ;
59127
@@ -62,16 +130,18 @@ class ModuleDepCollectorPP final : public PPCallbacks {
62130 ModuleDepCollector &MDC;
63131 llvm::DenseSet<const Module *> DirectDeps;
64132
133+ void handleImport (const Module *Imported);
65134 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 );
70139};
71140
72141class ModuleDepCollector final : public DependencyCollector {
73142public:
74- ModuleDepCollector (CompilerInstance &I, DependencyConsumer &C);
143+ ModuleDepCollector (std::unique_ptr<DependencyOutputOptions> Opts,
144+ CompilerInstance &I, DependencyConsumer &C);
75145
76146 void attachToPreprocessor (Preprocessor &PP) override ;
77147 void attachToASTReader (ASTReader &R) override ;
@@ -85,6 +155,7 @@ class ModuleDepCollector final : public DependencyCollector {
85155 std::string ContextHash;
86156 std::vector<std::string> MainDeps;
87157 std::unordered_map<std::string, ModuleDeps> Deps;
158+ std::unique_ptr<DependencyOutputOptions> Opts;
88159};
89160
90161} // end namespace dependencies
0 commit comments