Skip to content

Commit b39a9db

Browse files
authored
[clang][deps] Add module map describing compiled module to file dependencies. (#160226)
When we add the module map describing the compiled module to the command line, add it to the file dependencies as well. Discovered while working on reproducers where a command line input was missing in the captured files as it wasn't considered a dependency.
1 parent 13ed14f commit b39a9db

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ void ModuleDepCollectorPP::EndOfMainFile() {
619619
for (StringRef VFS : MDC.ScanInstance.getHeaderSearchOpts().VFSOverlayFiles)
620620
MDC.addFileDep(VFS);
621621

622+
if (Module *CurrentModule = PP.getCurrentModuleImplementation()) {
623+
if (OptionalFileEntryRef CurrentModuleMap =
624+
PP.getHeaderSearchInfo().getModuleMap().getModuleMapFileForUniquing(
625+
CurrentModule))
626+
MDC.addFileDep(CurrentModuleMap->getName());
627+
}
628+
622629
for (const Module *M :
623630
MDC.ScanInstance.getPreprocessor().getAffectingClangModules())
624631
if (!MDC.isPrebuiltModule(M))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
// RUN: sed -e "s|DIR|%/t|g" %t/vfs.yaml.in > %t/vfs.yaml
5+
6+
// RUN: clang-scan-deps -format experimental-full -j 1 -- \
7+
// RUN: %clang -ivfsoverlay %t/vfs.yaml -fmodules -fimplicit-module-maps \
8+
// RUN: -fmodules-cache-path=%t/cache -fmodule-name=ModuleName \
9+
// RUN: -I %/t/remapped -c %t/header-impl.c -o %t/header-impl.o \
10+
// RUN: | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
11+
12+
// CHECK: "command-line": [
13+
// CHECK: "-fmodule-map-file=[[PREFIX]]/remapped/module.modulemap"
14+
// CHECK: "file-deps": [
15+
// CHECK: "[[PREFIX]]/original/module.modulemap"
16+
17+
// Verify that "file-deps" references actual on-disk module map and not using the virtual path.
18+
19+
//--- vfs.yaml.in
20+
{
21+
"version": 0,
22+
"case-sensitive": "false",
23+
"roots": [
24+
{
25+
"name": "DIR/remapped",
26+
"type": "directory",
27+
"contents": [
28+
{
29+
"name": "module.modulemap",
30+
"type": "file",
31+
"external-contents": "DIR/original/module.modulemap"
32+
},
33+
{
34+
"name": "header.h",
35+
"type": "file",
36+
"external-contents": "DIR/original/header.h"
37+
}
38+
]
39+
}
40+
]
41+
}
42+
43+
//--- original/module.modulemap
44+
module ModuleName {
45+
header "header.h"
46+
export *
47+
}
48+
49+
//--- original/header.h
50+
int foo_function(void);
51+
52+
//--- header-impl.c
53+
#include <header.h>
54+
55+
int foo_function(void) {
56+
return 0;
57+
}

clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
// CHECK: "file-deps": [
4747
// CHECK-NEXT: "[[PREFIX]]/modules-fmodule-name-no-module-built.m",
4848
// CHECK-NEXT: "[[PREFIX]]/Inputs/header3.h",
49-
// CHECK-NEXT: "[[PREFIX]]/Inputs/header.h"
49+
// CHECK-NEXT: "[[PREFIX]]/Inputs/header.h",
50+
// CHECK-NEXT: "[[PREFIX]]/Inputs/module.modulemap"
5051
// CHECK-NEXT: ],
5152
// CHECK-NEXT: "input-file": "[[PREFIX]]/modules-fmodule-name-no-module-built.m"
5253
// CHECK-NEXT: }

clang/test/ClangScanDeps/modules-header-sharing.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
// CHECK: "file-deps": [
8181
// CHECK-NEXT: "[[PREFIX]]/tu.m",
8282
// CHECK-NEXT: "[[PREFIX]]/shared/H.h",
83-
// CHECK-NEXT: "[[PREFIX]]/overlay.json"
83+
// CHECK-NEXT: "[[PREFIX]]/overlay.json",
84+
// CHECK-NEXT: "[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap"
8485
// CHECK-NEXT: ],
8586
// CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m"
8687
// CHECK-NEXT: }

clang/test/ClangScanDeps/modules-implementation-module-map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ framework module FWPrivate { header "private.h" }
2828
// CHECK: "-fmodule-name=FWPrivate",
2929
// CHECK: ],
3030
// CHECK: "file-deps": [
31-
// CHECK-NEXT: "[[PREFIX]]/tu.m"
31+
// CHECK-NEXT: "[[PREFIX]]/tu.m",
32+
// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap"
3233
// CHECK-NEXT: ],
3334
// CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m"
3435
// CHECK-NEXT: }

clang/test/ClangScanDeps/modules-implementation-private.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
// CHECK: "file-deps": [
6666
// CHECK-NEXT: "[[PREFIX]]/tu.m",
6767
// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/Missed.h",
68-
// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h"
68+
// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h",
69+
// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap"
6970
// CHECK-NEXT: ],
7071
// CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m"
7172
// CHECK-NEXT: }

0 commit comments

Comments
 (0)