[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 updated
https://github.com/llvm/llvm-project/pull/182063
>From a7a5e00996eb5f1c784a27d3b6747e83db19e09c Mon Sep 17 00:00:00 2001
From: Jan Svoboda
Date: Tue, 17 Feb 2026 21:21:35 -0800
Subject: [PATCH 1/5] [clang][deps] Don't treat the 'make' output format
specially
---
.../DependencyScannerImpl.h | 12
.../DependencyScanning/ModuleDepCollector.h | 3 +
.../clang/Tooling/DependencyScanningTool.h| 1 +
.../DependencyScannerImpl.cpp | 64 ---
.../DependencyScanning/ModuleDepCollector.cpp | 7 ++
clang/lib/Tooling/DependencyScanningTool.cpp | 26 +---
clang/test/ClangScanDeps/modules-cc1.cpp | 2 +-
.../modules-has-include-umbrella-header.c | 3 +-
clang/tools/clang-scan-deps/ClangScanDeps.cpp | 4 +-
.../Tooling/DependencyScannerTest.cpp | 10 +--
10 files changed, 52 insertions(+), 80 deletions(-)
diff --git a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
index 55dcbd6fe0e9f..3a27a041755b3 100644
--- a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
+++ b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
@@ -114,18 +114,6 @@ getInitialStableDirs(const CompilerInstance &ScanInstance);
std::optional
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
SmallVector &StableDirs);
-
-/// Create the dependency collector that will collect the produced
-/// dependencies. May return the created ModuleDepCollector depending
-/// on the scanning format.
-std::shared_ptr initializeScanInstanceDependencyCollector(
-CompilerInstance &ScanInstance,
-std::unique_ptr DepOutputOpts,
-StringRef WorkingDirectory, DependencyConsumer &Consumer,
-DependencyScanningService &Service, CompilerInvocation &Inv,
-DependencyActionController &Controller,
-PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
-llvm::SmallVector &StableDirs);
} // namespace dependencies
} // namespace clang
diff --git a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
index e7dd907a00381..108127fbbe523 100644
--- a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
@@ -228,6 +228,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
SrcMgr::CharacteristicKind FileType, FileID PrevFID,
SourceLocation Loc) override;
+ void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
+ OptionalFileEntryRef File,
+ SrcMgr::CharacteristicKind FileType) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
diff --git a/clang/include/clang/Tooling/DependencyScanningTool.h
b/clang/include/clang/Tooling/DependencyScanningTool.h
index c845e212ce153..c368e93fa6286 100644
--- a/clang/include/clang/Tooling/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanningTool.h
@@ -47,6 +47,7 @@ class DependencyScanningTool {
/// dependency file contents otherwise.
std::optional
getDependencyFile(ArrayRef CommandLine, StringRef CWD,
+dependencies::LookupModuleOutputCallback
LookupModuleOutput,
DiagnosticConsumer &DiagConsumer);
/// Collect the module dependency in P1689 format for C++20 named modules.
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 40a7d1b908a6c..f0d91a7d61c73 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -27,32 +27,6 @@
using namespace clang;
using namespace dependencies;
-namespace {
-/// Forwards the gatherered dependencies to the consumer.
-class DependencyConsumerForwarder : public DependencyFileGenerator {
-public:
- DependencyConsumerForwarder(std::unique_ptr Opts,
- StringRef WorkingDirectory, DependencyConsumer
&C)
- : DependencyFileGenerator(*Opts), WorkingDirectory(WorkingDirectory),
-Opts(std::move(Opts)), C(C) {}
-
- void finishedMainFile(DiagnosticsEngine &Diags) override {
-C.handleDependencyOutputOpts(*Opts);
-llvm::SmallString<256> CanonPath;
-for (const auto &File : getDependencies()) {
- CanonPath = File;
- llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true);
- llvm::sys::path::make_absolute(WorkingDirectory, CanonPath);
- C.handleFileDependency(CanonPath);
-}
- }
-
-private:
- StringRef WorkingDirectory;
- std::unique_ptr Opts;
- DependencyConsu
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 closed https://github.com/llvm/llvm-project/pull/182063 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
github-actions[bot] wrote: # :penguin: Linux x64 Test Results * 86986 tests passed * 1326 tests skipped * 1 test failed ## Failed Tests (click on a test name to see its output) ### Clang Clang.ClangScanDeps/subframework_header_dir_symlink.m ``` Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 rm -rf /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir # executed command: rm -rf /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir # note: command had no output on stdout or stderr # RUN: at line 3 rm -rf /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.cdb # executed command: rm -rf /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.cdb # note: command had no output on stdout or stderr # RUN: at line 4 mkdir -p /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir # executed command: mkdir -p /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir # note: command had no output on stdout or stderr # RUN: at line 5 cp /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/subframework_header_dir_symlink.m /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/subframework_header_dir_symlink_input.m # executed command: cp /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/subframework_header_dir_symlink.m /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/subframework_header_dir_symlink_input.m # note: command had no output on stdout or stderr # RUN: at line 6 cp /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/subframework_header_dir_symlink.m /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/subframework_header_dir_symlink_input2.m # executed command: cp /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/subframework_header_dir_symlink.m /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/subframework_header_dir_symlink_input2.m # note: command had no output on stdout or stderr # RUN: at line 7 mkdir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs # executed command: mkdir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs # note: command had no output on stdout or stderr # RUN: at line 8 cp -R /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/Inputs/frameworks /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks # executed command: cp -R /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/Inputs/frameworks /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks # note: command had no output on stdout or stderr # RUN: at line 9 ln -s /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks_symlink # executed command: ln -s /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir/Inputs/frameworks_symlink # note: command had no output on stdout or stderr # RUN: at line 10 sed -e "s|DIR|/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/ClangScanDeps/Output/subframework_header_dir_symlink.m.tmp.dir|g" /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/ClangScanDeps/Inputs/subframework_header_dir_symlink_cdb.json > /home/gha/actions-runner/_wor
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/qiongsiwu approved this pull request. LGTM. I don't have anything to add here other than what @Bigcheese already mentioned. https://github.com/llvm/llvm-project/pull/182063 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -950,12 +957,9 @@ void ModuleDepCollector::addVisibleModules() {
static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path,
SmallVectorImpl &Storage) {
- if (llvm::sys::path::is_absolute(Path) &&
- !llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
-return Path;
jansvoboda11 wrote:
This is just an optimization to not re allocate the path if it's absolute and
doesn't need separator canonicalization. Now that that I need to call
`remove_dots()`
(https://github.com/llvm/llvm-project/pull/182063#discussion_r2823411756), I'd
need to check that this path doesn't contain dot components to see if it's safe
to skip the code below. So I decided to just drop the optimization entirely.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -950,12 +957,9 @@ void ModuleDepCollector::addVisibleModules() {
static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path,
SmallVectorImpl &Storage) {
- if (llvm::sys::path::is_absolute(Path) &&
- !llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
-return Path;
Bigcheese wrote:
Why is this part changed? It looks like this was to fix a Windows test a while
ago, does `remove_dots` end up being a better way to handle things?
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -40,7 +40,11 @@ class MakeDependencyPrinterConsumer : public
DependencyConsumer {
// set of deps, and handleFileDependency handles enough for implicitly
// built modules to work.
void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {}
- void handleModuleDependency(ModuleDeps MD) override {}
+ void handleModuleDependency(ModuleDeps MD) override {
+MD.forEachFileDep([this](StringRef File) {
+ ModuleDependencies.push_back(std::string(File));
+});
+ }
Bigcheese wrote:
The name `ModuleDependencies` is a bit confusing, as these are the file
dependencies of the imported modules.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 updated
https://github.com/llvm/llvm-project/pull/182063
>From a4bd1e4234e3c2ef81d1fe01ac78ba7163ec4e8b Mon Sep 17 00:00:00 2001
From: Jan Svoboda
Date: Tue, 17 Feb 2026 21:21:35 -0800
Subject: [PATCH 1/2] [clang][deps] Don't treat the 'make' output format
specially
---
.../DependencyScannerImpl.h | 12
.../DependencyScanning/ModuleDepCollector.h | 3 +
.../clang/Tooling/DependencyScanningTool.h| 1 +
.../DependencyScannerImpl.cpp | 66 ---
.../DependencyScanning/ModuleDepCollector.cpp | 12 ++--
clang/lib/Tooling/DependencyScanningTool.cpp | 26 +---
clang/test/ClangScanDeps/modules-cc1.cpp | 2 +-
.../modules-has-include-umbrella-header.c | 3 +-
clang/tools/clang-scan-deps/ClangScanDeps.cpp | 4 +-
.../Tooling/DependencyScannerTest.cpp | 10 +--
10 files changed, 54 insertions(+), 85 deletions(-)
diff --git a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
index d50371512667d..3d55759d60d83 100644
--- a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
+++ b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
@@ -106,18 +106,6 @@ std::optional
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
SmallVector &StableDirs);
-/// Create the dependency collector that will collect the produced
-/// dependencies. May return the created ModuleDepCollector depending
-/// on the scanning format.
-std::shared_ptr initializeScanInstanceDependencyCollector(
-CompilerInstance &ScanInstance,
-std::unique_ptr DepOutputOpts,
-StringRef WorkingDirectory, DependencyConsumer &Consumer,
-DependencyScanningService &Service, CompilerInvocation &Inv,
-DependencyActionController &Controller,
-PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
-llvm::SmallVector &StableDirs);
-
class CompilerInstanceWithContext {
// Context
DependencyScanningWorker &Worker;
diff --git a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
index 8f665daf03c69..2a581d72274f1 100644
--- a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
@@ -225,6 +225,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
SrcMgr::CharacteristicKind FileType, FileID PrevFID,
SourceLocation Loc) override;
+ void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
+ OptionalFileEntryRef File,
+ SrcMgr::CharacteristicKind FileType) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
diff --git a/clang/include/clang/Tooling/DependencyScanningTool.h
b/clang/include/clang/Tooling/DependencyScanningTool.h
index 96d21866dd7f9..5a94025191513 100644
--- a/clang/include/clang/Tooling/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanningTool.h
@@ -47,6 +47,7 @@ class DependencyScanningTool {
/// dependency file contents otherwise.
std::optional
getDependencyFile(ArrayRef CommandLine, StringRef CWD,
+dependencies::LookupModuleOutputCallback
LookupModuleOutput,
DiagnosticConsumer &DiagConsumer);
/// Collect the module dependency in P1689 format for C++20 named modules.
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 861e6e0042265..8d580012aae78 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -27,32 +27,6 @@
using namespace clang;
using namespace dependencies;
-namespace {
-/// Forwards the gatherered dependencies to the consumer.
-class DependencyConsumerForwarder : public DependencyFileGenerator {
-public:
- DependencyConsumerForwarder(std::unique_ptr Opts,
- StringRef WorkingDirectory, DependencyConsumer
&C)
- : DependencyFileGenerator(*Opts), WorkingDirectory(WorkingDirectory),
-Opts(std::move(Opts)), C(C) {}
-
- void finishedMainFile(DiagnosticsEngine &Diags) override {
-C.handleDependencyOutputOpts(*Opts);
-llvm::SmallString<256> CanonPath;
-for (const auto &File : getDependencies()) {
- CanonPath = File;
- llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true);
- llvm::sys::path::make_absolute(WorkingDirectory, CanonPath);
- C.handleFileDependency(CanonPath);
-}
- }
-
-private:
- StringRef WorkingDirectory;
- std::unique_ptr Opts;
- DependencyConsumer &C;
-};
-
static
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -950,12 +957,9 @@ void ModuleDepCollector::addVisibleModules() {
static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path,
SmallVectorImpl &Storage) {
- if (llvm::sys::path::is_absolute(Path) &&
- !llvm::sys::path::is_style_windows(llvm::sys::path::Style::native))
-return Path;
Storage.assign(Path.begin(), Path.end());
CI.getFileManager().makeAbsolutePath(Storage);
- llvm::sys::path::make_preferred(Storage);
+ llvm::sys::path::remove_dots(Storage, /*remove_dot_dot=*/true);
jansvoboda11 wrote:
This was added to keep
`clang/test/ClangScanDeps/subframework_header_dir_symlink.m` passing. Note that
`remove_dots` also changes the separators to the preferred ones.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -65,7 +65,8 @@ module Dependency { header "dependency.h" }
// CHECK-NEXT: "command-line": [
// CHECK:],
// CHECK:"file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/tu.c"
+// CHECK-NEXT: "[[PREFIX]]/tu.c",
+// CHECK-NEXT:
"[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/B.h"
jansvoboda11 wrote:
This was added because we now recognize `#if __has_include()` in the main TU.
Note that we still don't recognize this in modules, because dependency
collection there works on the `SourceManager` level, so it will only pick up
files that were actually fully `#include`d. This is known pre-existing behavior.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -40,7 +40,11 @@ class MakeDependencyPrinterConsumer : public
DependencyConsumer {
// set of deps, and handleFileDependency handles enough for implicitly
// built modules to work.
void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {}
- void handleModuleDependency(ModuleDeps MD) override {}
+ void handleModuleDependency(ModuleDeps MD) override {
+MD.forEachFileDep([this](StringRef File) {
+ ModuleDependencies.push_back(std::string(File));
+});
+ }
jansvoboda11 wrote:
This was added to propagate keep the modules' file dependencies into the Make
output. These would normally be picked up due to `compileModuleImpl()` passing
the dependency collector along to module compiles, or by hooking into the
`ASTReader`.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -549,6 +549,13 @@ void ModuleDepCollectorPP::LexedFileChanged(FileID FID,
MDC.addFileDep(llvm::sys::path::remove_leading_dotslash(*Filename));
}
+void ModuleDepCollectorPP::HasInclude(SourceLocation Loc, StringRef FileName,
+ bool IsAngled, OptionalFileEntryRef File,
+ SrcMgr::CharacteristicKind FileType) {
+ if (File)
+MDC.addFileDep(File->getName());
+}
jansvoboda11 wrote:
This was added to keep `clang/test/ClangScanDeps/has_include_if_elif.cpp`
passing.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 edited https://github.com/llvm/llvm-project/pull/182063 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 commented: Left a couple of explanations in-line. https://github.com/llvm/llvm-project/pull/182063 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
@@ -16,7 +16,7 @@ module header1 { header "header.h" }
[{
"file": "DIR/modules_cc1.cpp",
"directory": "DIR",
- "command": "clang -cc1 DIR/modules_cc1.cpp -fimplicit-module-maps -o
modules_cc1.o"
+ "command": "clang -cc1 DIR/modules_cc1.cpp -fmodules
-fmodules-cache-path=DIR/cache -fimplicit-module-maps -o modules_cc1.o"
jansvoboda11 wrote:
This was added to actually run a modular build. Without it, the new
implementation would not report the `[[PREFIX]]/module.modulemap` dependency
below. The old implementation would report it because we'd automatically parse
the module map and invoke the collector callback, even when not building with
`-fmodules`.
https://github.com/llvm/llvm-project/pull/182063
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Jan Svoboda (jansvoboda11)
Changes
The dependency scanner works significantly differently depending on what kind
of output it's asked to produce. The Make output format has been using the
regular Clang dependency collection mechanism since it was first implemented.
This means the implementation works very differently to the rest of the scanner
and isn't able to turn implicit module command lines into Makefiles using
explicit modules.
This PR unifies the two implementations, using `ModuleDepCollector` even for
Make output. Emitting explicit module builds into Makefiles will come in a
later PR.
---
Full diff: https://github.com/llvm/llvm-project/pull/182063.diff
10 Files Affected:
- (modified) clang/include/clang/DependencyScanning/DependencyScannerImpl.h
(-12)
- (modified) clang/include/clang/DependencyScanning/ModuleDepCollector.h (+3)
- (modified) clang/include/clang/Tooling/DependencyScanningTool.h (+1)
- (modified) clang/lib/DependencyScanning/DependencyScannerImpl.cpp (+14-52)
- (modified) clang/lib/DependencyScanning/ModuleDepCollector.cpp (+8-4)
- (modified) clang/lib/Tooling/DependencyScanningTool.cpp (+17-9)
- (modified) clang/test/ClangScanDeps/modules-cc1.cpp (+1-1)
- (modified) clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
(+2-1)
- (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+2-2)
- (modified) clang/unittests/Tooling/DependencyScannerTest.cpp (+6-4)
``diff
diff --git a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
index d50371512667d..3d55759d60d83 100644
--- a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
+++ b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
@@ -106,18 +106,6 @@ std::optional
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
SmallVector &StableDirs);
-/// Create the dependency collector that will collect the produced
-/// dependencies. May return the created ModuleDepCollector depending
-/// on the scanning format.
-std::shared_ptr initializeScanInstanceDependencyCollector(
-CompilerInstance &ScanInstance,
-std::unique_ptr DepOutputOpts,
-StringRef WorkingDirectory, DependencyConsumer &Consumer,
-DependencyScanningService &Service, CompilerInvocation &Inv,
-DependencyActionController &Controller,
-PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
-llvm::SmallVector &StableDirs);
-
class CompilerInstanceWithContext {
// Context
DependencyScanningWorker &Worker;
diff --git a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
index 8f665daf03c69..2a581d72274f1 100644
--- a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
@@ -225,6 +225,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
SrcMgr::CharacteristicKind FileType, FileID PrevFID,
SourceLocation Loc) override;
+ void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
+ OptionalFileEntryRef File,
+ SrcMgr::CharacteristicKind FileType) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
diff --git a/clang/include/clang/Tooling/DependencyScanningTool.h
b/clang/include/clang/Tooling/DependencyScanningTool.h
index 96d21866dd7f9..5a94025191513 100644
--- a/clang/include/clang/Tooling/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanningTool.h
@@ -47,6 +47,7 @@ class DependencyScanningTool {
/// dependency file contents otherwise.
std::optional
getDependencyFile(ArrayRef CommandLine, StringRef CWD,
+dependencies::LookupModuleOutputCallback
LookupModuleOutput,
DiagnosticConsumer &DiagConsumer);
/// Collect the module dependency in P1689 format for C++20 named modules.
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 861e6e0042265..8d580012aae78 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -27,32 +27,6 @@
using namespace clang;
using namespace dependencies;
-namespace {
-/// Forwards the gatherered dependencies to the consumer.
-class DependencyConsumerForwarder : public DependencyFileGenerator {
-public:
- DependencyConsumerForwarder(std::unique_ptr Opts,
- StringRef WorkingDirectory, DependencyConsumer
&C)
- : DependencyFileGenerator(*Opts), WorkingDirectory(Working
[clang] [clang][deps] Use `ModuleDepCollector` for Make output (PR #182063)
https://github.com/jansvoboda11 created
https://github.com/llvm/llvm-project/pull/182063
The dependency scanner works significantly differently depending on what kind
of output it's asked to produce. The Make output format has been using the
regular Clang dependency collection mechanism since it was first implemented.
This means the implementation works very differently to the rest of the scanner
and isn't able to turn implicit module command lines into Makefiles using
explicit modules.
This PR unifies the two implementations, using `ModuleDepCollector` even for
Make output. Emitting explicit module builds into Makefiles will come in a
later PR.
>From a4bd1e4234e3c2ef81d1fe01ac78ba7163ec4e8b Mon Sep 17 00:00:00 2001
From: Jan Svoboda
Date: Tue, 17 Feb 2026 21:21:35 -0800
Subject: [PATCH] [clang][deps] Don't treat the 'make' output format specially
---
.../DependencyScannerImpl.h | 12
.../DependencyScanning/ModuleDepCollector.h | 3 +
.../clang/Tooling/DependencyScanningTool.h| 1 +
.../DependencyScannerImpl.cpp | 66 ---
.../DependencyScanning/ModuleDepCollector.cpp | 12 ++--
clang/lib/Tooling/DependencyScanningTool.cpp | 26 +---
clang/test/ClangScanDeps/modules-cc1.cpp | 2 +-
.../modules-has-include-umbrella-header.c | 3 +-
clang/tools/clang-scan-deps/ClangScanDeps.cpp | 4 +-
.../Tooling/DependencyScannerTest.cpp | 10 +--
10 files changed, 54 insertions(+), 85 deletions(-)
diff --git a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
index d50371512667d..3d55759d60d83 100644
--- a/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
+++ b/clang/include/clang/DependencyScanning/DependencyScannerImpl.h
@@ -106,18 +106,6 @@ std::optional
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
SmallVector &StableDirs);
-/// Create the dependency collector that will collect the produced
-/// dependencies. May return the created ModuleDepCollector depending
-/// on the scanning format.
-std::shared_ptr initializeScanInstanceDependencyCollector(
-CompilerInstance &ScanInstance,
-std::unique_ptr DepOutputOpts,
-StringRef WorkingDirectory, DependencyConsumer &Consumer,
-DependencyScanningService &Service, CompilerInvocation &Inv,
-DependencyActionController &Controller,
-PrebuiltModulesAttrsMap PrebuiltModulesASTMap,
-llvm::SmallVector &StableDirs);
-
class CompilerInstanceWithContext {
// Context
DependencyScanningWorker &Worker;
diff --git a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
index 8f665daf03c69..2a581d72274f1 100644
--- a/clang/include/clang/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/DependencyScanning/ModuleDepCollector.h
@@ -225,6 +225,9 @@ class ModuleDepCollectorPP final : public PPCallbacks {
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
SrcMgr::CharacteristicKind FileType, FileID PrevFID,
SourceLocation Loc) override;
+ void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
+ OptionalFileEntryRef File,
+ SrcMgr::CharacteristicKind FileType) override;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
diff --git a/clang/include/clang/Tooling/DependencyScanningTool.h
b/clang/include/clang/Tooling/DependencyScanningTool.h
index 96d21866dd7f9..5a94025191513 100644
--- a/clang/include/clang/Tooling/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanningTool.h
@@ -47,6 +47,7 @@ class DependencyScanningTool {
/// dependency file contents otherwise.
std::optional
getDependencyFile(ArrayRef CommandLine, StringRef CWD,
+dependencies::LookupModuleOutputCallback
LookupModuleOutput,
DiagnosticConsumer &DiagConsumer);
/// Collect the module dependency in P1689 format for C++20 named modules.
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 861e6e0042265..8d580012aae78 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -27,32 +27,6 @@
using namespace clang;
using namespace dependencies;
-namespace {
-/// Forwards the gatherered dependencies to the consumer.
-class DependencyConsumerForwarder : public DependencyFileGenerator {
-public:
- DependencyConsumerForwarder(std::unique_ptr Opts,
- StringRef WorkingDirectory, DependencyConsumer
&C)
- : DependencyFileGenerator(*Opts), WorkingDirectory(WorkingDirect
