Skip to content

Commit 981742e

Browse files
committed
[clang][clang-scan-deps] Add named modules to format 'experimental-full'
This adds standard C++ named modules to the scanning output format 'experimental-full'. This is motivated by an effort to provide native support for explicit module builds from the Clang driver. The driver support for explicit module builds is planned to support combined usage of Clang modules and C++ named modules. With this, only a single scan is required to capture dependencies for both module types.
1 parent d8e8ab7 commit 981742e

29 files changed

+431
-50
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ void ModuleDepCollectorPP::EndOfMainFile() {
714714

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

717-
if (MDC.Service.getFormat() == ScanningOutputFormat::P1689)
717+
if (const auto Format = MDC.Service.getFormat();
718+
Format == ScanningOutputFormat::P1689 ||
719+
Format == ScanningOutputFormat::Full)
718720
MDC.Consumer.handleProvidedAndRequiredStdCXXModules(
719721
MDC.ProvidedStdCXXModule, MDC.RequiredStdCXXModules);
720722

clang/test/ClangScanDeps/diagnostics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module mod { header "mod.h" }
4444
// CHECK-NEXT: "translation-units": [
4545
// CHECK-NEXT: {
4646
// CHECK: "clang-context-hash": "[[HASH_TU:.*]],
47-
// CHECK-NEXT: "clang-module-deps": [
47+
// CHECK: "clang-module-deps": [
4848
// CHECK-NEXT: {
4949
// CHECK-NEXT: "context-hash": "[[HASH_MOD]]",
5050
// CHECK-NEXT: "module-name": "mod"

clang/test/ClangScanDeps/header-search-pruning-transitive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module X { header "X.h" }
9898
// CHECK-NEXT: "translation-units": [
9999
// CHECK-NEXT: {
100100
// CHECK: "clang-context-hash": "{{.*}}",
101-
// CHECK-NEXT: "clang-module-deps": [
101+
// CHECK: "clang-module-deps": [
102102
// CHECK-NEXT: {
103103
// CHECK-NEXT: "context-hash": "[[HASH_X]]",
104104
// CHECK-NEXT: "module-name": "X"
@@ -153,7 +153,7 @@ module X { header "X.h" }
153153
// CHECK-NEXT: "translation-units": [
154154
// CHECK-NEXT: {
155155
// CHECK: "clang-context-hash": "{{.*}}",
156-
// CHECK-NEXT: "clang-module-deps": [
156+
// CHECK: "clang-module-deps": [
157157
// CHECK-NEXT: {
158158
// CHECK-NEXT: "context-hash": "{{.*}}",
159159
// CHECK-NEXT: "module-name": "X"

clang/test/ClangScanDeps/modules-context-hash-cwd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ module mod {
7575
// CHECK: {
7676
// CHECK-NEXT: "modules": [
7777
// CHECK-NEXT: {
78-
// CHECK-NEXT: "clang-module-deps": [],
78+
// CHECK: "clang-module-deps": [],
7979
// CHECK: "context-hash": "[[HASH:.*]]",
8080
// CHECK: }
8181
// CHECK: "translation-units": [
8282
// CHECK: {
8383
// CHECK: "commands": [
8484
// CHECK: {
8585
// CHECK-NEXT: "clang-context-hash": "{{.*}}",
86-
// CHECK-NEXT: "clang-module-deps": [
86+
// CHECK: "clang-module-deps": [
8787
// CHECK-NEXT: {
8888
// CHECK-NEXT: "context-hash": "[[HASH]]",
8989
// CHECK-NEXT: "module-name": "mod"
@@ -100,7 +100,7 @@ module mod {
100100
// CHECK: "commands": [
101101
// CHECK: {
102102
// CHECK-NEXT: "clang-context-hash": "{{.*}}",
103-
// CHECK-NEXT: "clang-module-deps": [
103+
// CHECK: "clang-module-deps": [
104104
// CHECK-NEXT: {
105105
// CHECK-NEXT: "context-hash": "[[HASH]]",
106106
// CHECK-NEXT: "module-name": "mod"
@@ -112,15 +112,15 @@ module mod {
112112
// SKIPOPT: {
113113
// SKIPOPT-NEXT: "modules": [
114114
// SKIPOPT-NEXT: {
115-
// SKIPOPT-NEXT: "clang-module-deps": [],
115+
// SKIPOPT: "clang-module-deps": [],
116116
// SKIPOPT: "context-hash": "[[HASH0:.*]]",
117117
// SKIPOPT: }
118118
// SKIPOPT: "translation-units": [
119119
// SKIPOPT: {
120120
// SKIPOPT: "commands": [
121121
// SKIPOPT: {
122122
// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}",
123-
// SKIPOPT-NEXT: "clang-module-deps": [
123+
// SKIPOPT: "clang-module-deps": [
124124
// SKIPOPT-NEXT: {
125125
// SKIPOPT-NEXT: "context-hash": "[[HASH0]]",
126126
// SKIPOPT-NEXT: "module-name": "mod"
@@ -129,7 +129,7 @@ module mod {
129129
// SKIPOPT: {
130130
// SKIPOPT-NEXT: "modules": [
131131
// SKIPOPT-NEXT: {
132-
// SKIPOPT-NEXT: "clang-module-deps": [],
132+
// SKIPOPT: "clang-module-deps": [],
133133
// SKIPOPT-NOT: "context-hash": "[[HASH0]]",
134134
// SKIPOPT: "context-hash": "[[HASH2:.*]]",
135135
// SKIPOPT: }
@@ -138,7 +138,7 @@ module mod {
138138
// SKIPOPT: "commands": [
139139
// SKIPOPT: {
140140
// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}",
141-
// SKIPOPT-NEXT: "clang-module-deps": [
141+
// SKIPOPT: "clang-module-deps": [
142142
// SKIPOPT-NEXT: {
143143
// SKIPOPT-NOT: "context-hash": "[[HASH0]]",
144144
// SKIPOPT-NEXT: "context-hash": "[[HASH2]]"
@@ -160,7 +160,7 @@ module mod {
160160
// RELPATH: "commands": [
161161
// RELPATH: {
162162
// RELPATH-NEXT: "clang-context-hash": "{{.*}}",
163-
// RELPATH-NEXT: "clang-module-deps": [
163+
// RELPATH: "clang-module-deps": [
164164
// RELPATH-NEXT: {
165165
// RELPATH-NEXT: "context-hash": "[[HASH3]]",
166166
// RELPATH-NEXT: "module-name": "mod"
@@ -178,7 +178,7 @@ module mod {
178178
// RELPATH: "commands": [
179179
// RELPATH: {
180180
// RELPATH-NEXT: "clang-context-hash": "{{.*}}",
181-
// RELPATH-NEXT: "clang-module-deps": [
181+
// RELPATH: "clang-module-deps": [
182182
// RELPATH-NEXT: {
183183
// RELPATH-NOT: "context-hash": "[[HASH3]]",
184184
// RELPATH-NEXT: "context-hash": "[[HASH4]]"

clang/test/ClangScanDeps/modules-context-hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
// CHECK-NEXT: "translation-units": [
4646
// CHECK-NEXT: {
4747
// CHECK: "clang-context-hash": "{{.*}}",
48-
// CHECK-NEXT: "clang-module-deps": [
48+
// CHECK: "clang-module-deps": [
4949
// CHECK-NEXT: {
5050
// CHECK-NEXT: "context-hash": "[[HASH_MOD_A]]",
5151
// CHECK-NEXT: "module-name": "mod"
@@ -83,7 +83,7 @@
8383
// CHECK-NEXT: "translation-units": [
8484
// CHECK-NEXT: {
8585
// CHECK: "clang-context-hash": "{{.*}}",
86-
// CHECK-NEXT: "clang-module-deps": [
86+
// CHECK: "clang-module-deps": [
8787
// CHECK-NEXT: {
8888
// CHECK-NOT: "context-hash": "[[HASH_MOD_A]]",
8989
// CHECK: "module-name": "mod"

clang/test/ClangScanDeps/modules-dep-args.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module Direct { header "direct.h" }
8181
// CHECK-NEXT: "translation-units": [
8282
// CHECK-NEXT: {
8383
// CHECK: "clang-context-hash": "{{.*}}",
84-
// CHECK-NEXT: "clang-module-deps": [
84+
// CHECK: "clang-module-deps": [
8585
// CHECK-NEXT: {
8686
// CHECK-NEXT: "context-hash": "{{.*}}",
8787
// CHECK-NEXT: "module-name": "Direct"

clang/test/ClangScanDeps/modules-extern-submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module third {}
101101
// CHECK-NEXT: "commands": [
102102
// CHECK-NEXT: {
103103
// CHECK-NEXT: "clang-context-hash": "{{.*}}",
104-
// CHECK-NEXT: "clang-module-deps": [
104+
// CHECK: "clang-module-deps": [
105105
// CHECK-NEXT: {
106106
// CHECK-NEXT: "context-hash": "{{.*}}",
107107
// CHECK-NEXT: "module-name": "first"

clang/test/ClangScanDeps/modules-extern-unrelated.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
// CHECK-NEXT: "commands": [
108108
// CHECK-NEXT: {
109109
// CHECK-NEXT: "clang-context-hash": "{{.*}}",
110-
// CHECK-NEXT: "clang-module-deps": [
110+
// CHECK: "clang-module-deps": [
111111
// CHECK-NEXT: {
112112
// CHECK-NEXT: "context-hash": "{{.*}}",
113113
// CHECK-NEXT: "module-name": "zeroth"

0 commit comments

Comments
 (0)