[clang] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (PR #69551)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 19:08:38 PDT 2023
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/69551
Close https://github.com/llvm/llvm-project/issues/69439.
This patch tries to reuse the codes to generate make style dependencies information with P1689 format directly.
>From 17b84659fa91d8a92a3d41aad8fbc3fa587a89b9 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <yedeng.yd at linux.alibaba.com>
Date: Thu, 19 Oct 2023 10:04:25 +0800
Subject: [PATCH] [clang-scan-deps] [P1689] Keep consistent behavior for make
dependencies with clang
Close https://github.com/llvm/llvm-project/issues/69439.
This patch tries to reuse the codes to generate make style dependencies
information with P1689 format directly.
---
.../DependencyScanning/DependencyScanningWorker.cpp | 8 ++++++--
.../DependencyScanning/ModuleDepCollector.cpp | 12 +++++++++---
clang/test/ClangScanDeps/P1689.cppm | 10 ++++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 29df0c3a0afdb5c..b7911f9844a3554 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -231,12 +231,16 @@ class DependencyScanningAction : public tooling::ToolAction {
Opts->IncludeSystemHeaders = true;
switch (Format) {
+ case ScanningOutputFormat::P1689:
case ScanningOutputFormat::Make:
ScanInstance.addDependencyCollector(
std::make_shared<DependencyConsumerForwarder>(
std::move(Opts), WorkingDirectory, Consumer));
- break;
- case ScanningOutputFormat::P1689:
+
+ if (Format == ScanningOutputFormat::Make)
+ break;
+
+ [[fallthrough]];
case ScanningOutputFormat::Full:
MDC = std::make_shared<ModuleDepCollector>(
std::move(Opts), ScanInstance, Consumer, Controller,
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 40115b7b5ae25b3..ea42923f9545d97 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -436,7 +436,10 @@ void ModuleDepCollectorPP::EndOfMainFile() {
for (const Module *M : MDC.DirectModularDeps)
handleTopLevelModule(M);
- MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
+ // With P1689 format, we get the output options from
+ // DependencyConsumerForwarder.
+ if (!MDC.IsStdModuleP1689Format)
+ MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
if (MDC.IsStdModuleP1689Format)
MDC.Consumer.handleProvidedAndRequiredStdCXXModules(
@@ -452,8 +455,11 @@ void ModuleDepCollectorPP::EndOfMainFile() {
MDC.Consumer.handleDirectModuleDependency(MDC.ModularDeps[M]->ID);
}
- for (auto &&I : MDC.FileDeps)
- MDC.Consumer.handleFileDependency(I);
+ // With P1689 format, we collect the file dependencies from make's dep
+ // collector.
+ if (!MDC.IsStdModuleP1689Format)
+ for (auto &&I : MDC.FileDeps)
+ MDC.Consumer.handleFileDependency(I);
for (auto &&I : MDC.DirectPrebuiltModularDeps)
MDC.Consumer.handlePrebuiltModuleDependency(I.second);
diff --git a/clang/test/ClangScanDeps/P1689.cppm b/clang/test/ClangScanDeps/P1689.cppm
index dffb16974a3e4e4..b992502a5179c15 100644
--- a/clang/test/ClangScanDeps/P1689.cppm
+++ b/clang/test/ClangScanDeps/P1689.cppm
@@ -42,6 +42,14 @@
// RUN: clang-scan-deps -format=p1689 \
// RUN: -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
// RUN: | FileCheck %t/impl_part.cppm -DPREFIX=%/t
+//
+// Check the path in the make style dependencies are generated in relative path form
+// RUN: cd %t
+// RUN: clang-scan-deps -format=p1689 \
+// RUN: -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t impl_part.cppm -o impl_part.o \
+// RUN: -MT impl_part.o.ddi -MD -MF impl_part.dep
+// RUN: cat impl_part.dep | FileCheck impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE-RELATIVE
+
//--- P1689.json.in
[
@@ -168,6 +176,8 @@ void World() {
// CHECK-MAKE: [[PREFIX]]/impl_part.cppm
// CHECK-MAKE: [[PREFIX]]/header.mock
+// CHECK-MAKE-RELATIVE: impl_part.o.ddi: ./impl_part.cppm ./header.mock
+
//--- interface_part.cppm
export module M:interface_part;
export void World();
More information about the cfe-commits
mailing list