Skip to content

Commit c003d85

Browse files
authored
[clang][DependencyScanner] Remove unused -fmodule-map-file arguments (#80090)
Since we already add a `-fmodule-map-file=` argument for every used modulemap, we can remove all `ModuleMapFiles` entries before adding them. This reduces the number of module variants when `-fmodule-map-file=` appears on the original command line.
1 parent 742f88e commit c003d85

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
211211
ScanInstance.getFileManager().getFile(Deps.ClangModuleMapFile);
212212
assert(CurrentModuleMapEntry && "module map file entry not found");
213213

214+
// Remove directly passed modulemap files. They will get added back if they
215+
// were actually used.
216+
CI.getMutFrontendOpts().ModuleMapFiles.clear();
217+
214218
auto DepModuleMapFiles = collectModuleMapFiles(Deps.ClangModuleDeps);
215219
for (StringRef ModuleMapFile : Deps.ModuleMapFileDeps) {
216220
// TODO: Track these as `FileEntryRef` to simplify the equality check below.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Check that unused directly passed -fmodule-map-file options get dropped.
2+
3+
// RUN: rm -rf %t && split-file %s %t
4+
// RUN: sed -e "s|DIR|%/t|g" %t/build/cdb.json.in > %t/build/cdb.json
5+
// RUN: clang-scan-deps -compilation-database %t/build/cdb.json \
6+
// RUN: -format experimental-full > %t/deps.json
7+
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
8+
9+
// CHECK: {
10+
// CHECK-NEXT: "modules": [
11+
// CHECK-NEXT: {
12+
// CHECK-NEXT: "clang-module-deps": [
13+
// CHECK-NEXT: {
14+
// CHECK-NEXT: "context-hash": "{{.*}}",
15+
// CHECK-NEXT: "module-name": "B"
16+
// CHECK-NEXT: }
17+
// CHECK-NEXT: ],
18+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/A/module.modulemap",
19+
// CHECK-NEXT: "command-line": [
20+
// CHECK-NOT: "-fmodule-map-file=[[PREFIX]]/modules/A/module.modulemap"
21+
// CHECK: "-fmodule-map-file=[[PREFIX]]/modules/B/module.modulemap"
22+
// CHECK-NOT: "-fmodule-map-file=[[PREFIX]]/modules/A/module.modulemap"
23+
// CHECK: ],
24+
// CHECK-NEXT: "context-hash": "{{.*}}",
25+
// CHECK-NEXT: "file-deps": [
26+
// CHECK: ],
27+
// CHECK-NEXT: "name": "A"
28+
// CHECK-NEXT: },
29+
// CHECK-NEXT: {
30+
// CHECK-NEXT: "clang-module-deps": [],
31+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/B/module.modulemap",
32+
// CHECK-NEXT: "command-line": [
33+
// CHECK-NOT: "-fmodule-map-file=
34+
// CHECK: ],
35+
// CHECK-NEXT: "context-hash": "{{.*}}",
36+
// CHECK-NEXT: "file-deps": [
37+
// CHECK: ],
38+
// CHECK-NEXT: "name": "B"
39+
// CHECK-NEXT: }
40+
// CHECK-NEXT: ],
41+
// CHECK-NEXT: "translation-units": [
42+
// CHECK: ]
43+
// CHECK: }
44+
45+
//--- build/cdb.json.in
46+
[{
47+
"directory": "DIR",
48+
"command": "clang -c DIR/tu.m -I DIR/modules/B -fmodule-map-file=DIR/modules/A/module.modulemap -fmodules -fmodules-cache-path=DIR/cache -fimplicit-module-maps",
49+
"file": "DIR/tu.m"
50+
}]
51+
52+
//--- build/vfs.yaml.in
53+
54+
//--- tu.m
55+
@import A;
56+
57+
//--- modules/A/module.modulemap
58+
module A { header "A.h" }
59+
60+
//--- modules/A/A.h
61+
#include <B.h>
62+
63+
//--- modules/B/module.modulemap
64+
module B { header "B.h" }
65+
66+
//--- modules/B/B.h

0 commit comments

Comments
 (0)