diff options
| author | Volodymyr Sapsai <vsapsai@apple.com> | 2025-11-19 20:17:43 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-19 20:17:43 -0800 |
| commit | b39a9db3abc7abfa033a728ef29b5e5d3beb1cb5 (patch) | |
| tree | cbcf37b394c873b5d1f02eafa93b3e33e6599129 /clang | |
| parent | 13ed14f47eb3995942b2e4bba4ab37851b2751f9 (diff) | |
[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.
Diffstat (limited to 'clang')
6 files changed, 72 insertions, 4 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 80d242a477a3..3a99f8c882b8 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -619,6 +619,13 @@ void ModuleDepCollectorPP::EndOfMainFile() { for (StringRef VFS : MDC.ScanInstance.getHeaderSearchOpts().VFSOverlayFiles) MDC.addFileDep(VFS); + if (Module *CurrentModule = PP.getCurrentModuleImplementation()) { + if (OptionalFileEntryRef CurrentModuleMap = + PP.getHeaderSearchInfo().getModuleMap().getModuleMapFileForUniquing( + CurrentModule)) + MDC.addFileDep(CurrentModuleMap->getName()); + } + for (const Module *M : MDC.ScanInstance.getPreprocessor().getAffectingClangModules()) if (!MDC.isPrebuiltModule(M)) diff --git a/clang/test/ClangScanDeps/modules-current-modulemap-file-dep.c b/clang/test/ClangScanDeps/modules-current-modulemap-file-dep.c new file mode 100644 index 000000000000..e34bc876057d --- /dev/null +++ b/clang/test/ClangScanDeps/modules-current-modulemap-file-dep.c @@ -0,0 +1,57 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: sed -e "s|DIR|%/t|g" %t/vfs.yaml.in > %t/vfs.yaml + +// RUN: clang-scan-deps -format experimental-full -j 1 -- \ +// RUN: %clang -ivfsoverlay %t/vfs.yaml -fmodules -fimplicit-module-maps \ +// RUN: -fmodules-cache-path=%t/cache -fmodule-name=ModuleName \ +// RUN: -I %/t/remapped -c %t/header-impl.c -o %t/header-impl.o \ +// RUN: | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t + +// CHECK: "command-line": [ +// CHECK: "-fmodule-map-file=[[PREFIX]]/remapped/module.modulemap" +// CHECK: "file-deps": [ +// CHECK: "[[PREFIX]]/original/module.modulemap" + +// Verify that "file-deps" references actual on-disk module map and not using the virtual path. + +//--- vfs.yaml.in +{ + "version": 0, + "case-sensitive": "false", + "roots": [ + { + "name": "DIR/remapped", + "type": "directory", + "contents": [ + { + "name": "module.modulemap", + "type": "file", + "external-contents": "DIR/original/module.modulemap" + }, + { + "name": "header.h", + "type": "file", + "external-contents": "DIR/original/header.h" + } + ] + } + ] +} + +//--- original/module.modulemap +module ModuleName { + header "header.h" + export * +} + +//--- original/header.h +int foo_function(void); + +//--- header-impl.c +#include <header.h> + +int foo_function(void) { + return 0; +} diff --git a/clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m b/clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m index cfe29c2bf7cd..f7edb011ad32 100644 --- a/clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m +++ b/clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m @@ -46,7 +46,8 @@ // CHECK: "file-deps": [ // CHECK-NEXT: "[[PREFIX]]/modules-fmodule-name-no-module-built.m", // CHECK-NEXT: "[[PREFIX]]/Inputs/header3.h", -// CHECK-NEXT: "[[PREFIX]]/Inputs/header.h" +// CHECK-NEXT: "[[PREFIX]]/Inputs/header.h", +// CHECK-NEXT: "[[PREFIX]]/Inputs/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "input-file": "[[PREFIX]]/modules-fmodule-name-no-module-built.m" // CHECK-NEXT: } diff --git a/clang/test/ClangScanDeps/modules-header-sharing.m b/clang/test/ClangScanDeps/modules-header-sharing.m index 9bba43518872..c40c2891786c 100644 --- a/clang/test/ClangScanDeps/modules-header-sharing.m +++ b/clang/test/ClangScanDeps/modules-header-sharing.m @@ -80,7 +80,8 @@ framework module B_Private { umbrella header "B_Private.h" } // CHECK: "file-deps": [ // CHECK-NEXT: "[[PREFIX]]/tu.m", // CHECK-NEXT: "[[PREFIX]]/shared/H.h", -// CHECK-NEXT: "[[PREFIX]]/overlay.json" +// CHECK-NEXT: "[[PREFIX]]/overlay.json", +// CHECK-NEXT: "[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m" // CHECK-NEXT: } diff --git a/clang/test/ClangScanDeps/modules-implementation-module-map.c b/clang/test/ClangScanDeps/modules-implementation-module-map.c index b7637d0c9143..a7170aab2448 100644 --- a/clang/test/ClangScanDeps/modules-implementation-module-map.c +++ b/clang/test/ClangScanDeps/modules-implementation-module-map.c @@ -28,7 +28,8 @@ framework module FWPrivate { header "private.h" } // CHECK: "-fmodule-name=FWPrivate", // CHECK: ], // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/tu.m" +// CHECK-NEXT: "[[PREFIX]]/tu.m", +// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m" // CHECK-NEXT: } diff --git a/clang/test/ClangScanDeps/modules-implementation-private.m b/clang/test/ClangScanDeps/modules-implementation-private.m index b376073f4b9e..210fbfb424ac 100644 --- a/clang/test/ClangScanDeps/modules-implementation-private.m +++ b/clang/test/ClangScanDeps/modules-implementation-private.m @@ -65,7 +65,8 @@ framework module FW_Private { umbrella header "FW_Private.h" } // CHECK: "file-deps": [ // CHECK-NEXT: "[[PREFIX]]/tu.m", // CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/Missed.h", -// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h" +// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h", +// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.m" // CHECK-NEXT: } |
