Skip to content

Commit 52fbefb

Browse files
authored
[clang][clang-scan-deps] Add named modules to format 'experimental-full' (#145221)
1 parent 87ce754 commit 52fbefb

File tree

5 files changed

+391
-7
lines changed

5 files changed

+391
-7
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "clang/Tooling/JSONCompilationDatabase.h"
1616
#include "llvm/ADT/DenseSet.h"
1717
#include "llvm/ADT/MapVector.h"
18+
#include "llvm/ADT/STLExtras.h"
1819
#include <functional>
1920
#include <optional>
2021
#include <string>
@@ -56,6 +57,9 @@ struct TranslationUnitDeps {
5657
/// determined that the differences are benign for this compilation.
5758
std::vector<ModuleID> ClangModuleDeps;
5859

60+
/// A list of the C++20 named modules this translation unit depends on.
61+
std::vector<std::string> NamedModuleDeps;
62+
5963
/// The sequence of commands required to build the translation unit. Commands
6064
/// should be executed in order.
6165
///
@@ -188,13 +192,23 @@ class FullDependencyConsumer : public DependencyConsumer {
188192
ContextHash = std::move(Hash);
189193
}
190194

195+
void handleProvidedAndRequiredStdCXXModules(
196+
std::optional<P1689ModuleInfo> Provided,
197+
std::vector<P1689ModuleInfo> Requires) override {
198+
ModuleName = Provided ? Provided->ModuleName : "";
199+
llvm::transform(Requires, std::back_inserter(NamedModuleDeps),
200+
[](const auto &Module) { return Module.ModuleName; });
201+
}
202+
191203
TranslationUnitDeps takeTranslationUnitDeps();
192204
ModuleDepsGraph takeModuleGraphDeps();
193205

194206
private:
195207
std::vector<std::string> Dependencies;
196208
std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
197209
llvm::MapVector<ModuleID, ModuleDeps> ClangModuleDeps;
210+
std::string ModuleName;
211+
std::vector<std::string> NamedModuleDeps;
198212
std::vector<ModuleID> DirectModuleDeps;
199213
std::vector<Command> Commands;
200214
std::string ContextHash;

clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ TranslationUnitDeps FullDependencyConsumer::takeTranslationUnitDeps() {
171171
TranslationUnitDeps TU;
172172

173173
TU.ID.ContextHash = std::move(ContextHash);
174+
TU.ID.ModuleName = std::move(ModuleName);
175+
TU.NamedModuleDeps = std::move(NamedModuleDeps);
174176
TU.FileDeps = std::move(Dependencies);
175177
TU.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
176178
TU.Commands = std::move(Commands);

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,8 @@ void ModuleDepCollectorPP::EndOfMainFile() {
714714

715715
MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
716716

717-
if (MDC.Service.getFormat() == ScanningOutputFormat::P1689)
718-
MDC.Consumer.handleProvidedAndRequiredStdCXXModules(
719-
MDC.ProvidedStdCXXModule, MDC.RequiredStdCXXModules);
717+
MDC.Consumer.handleProvidedAndRequiredStdCXXModules(
718+
MDC.ProvidedStdCXXModule, MDC.RequiredStdCXXModules);
720719

721720
for (auto &&I : MDC.ModularDeps)
722721
MDC.Consumer.handleModuleDependency(*I.second);

0 commit comments

Comments
 (0)