[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.
This commit is contained in:
Volodymyr Sapsai 2025-11-19 20:17:43 -08:00 committed by GitHub
parent 13ed14f47e
commit b39a9db3ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 72 additions and 4 deletions

View File

@ -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))

View File

@ -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;
}

View File

@ -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: }

View File

@ -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: }

View File

@ -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: }

View File

@ -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: }