Skip to content

Commit e107c94

Browse files
authored
[clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (#69551)
Close #69439. This patch tries to reuse the codes to generate make style dependencies information with P1689 format directly.
1 parent 3351097 commit e107c94

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,24 @@ static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path,
666666
}
667667

668668
void ModuleDepCollector::addFileDep(StringRef Path) {
669+
if (IsStdModuleP1689Format) {
670+
// Within P1689 format, we don't want all the paths to be absolute path
671+
// since it may violate the tranditional make style dependencies info.
672+
FileDeps.push_back(std::string(Path));
673+
return;
674+
}
675+
669676
llvm::SmallString<256> Storage;
670677
Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
671678
FileDeps.push_back(std::string(Path));
672679
}
673680

674681
void ModuleDepCollector::addFileDep(ModuleDeps &MD, StringRef Path) {
682+
if (IsStdModuleP1689Format) {
683+
MD.FileDeps.insert(Path);
684+
return;
685+
}
686+
675687
llvm::SmallString<256> Storage;
676688
Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage);
677689
MD.FileDeps.insert(Path);

clang/test/ClangScanDeps/P1689.cppm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
// RUN: clang-scan-deps -format=p1689 \
4343
// RUN: -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \
4444
// RUN: | FileCheck %t/impl_part.cppm -DPREFIX=%/t
45+
//
46+
// Check the path in the make style dependencies are generated in relative path form
47+
// RUN: cd %t
48+
// RUN: clang-scan-deps -format=p1689 \
49+
// RUN: -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t impl_part.cppm -o impl_part.o \
50+
// RUN: -MT impl_part.o.ddi -MD -MF impl_part.dep
51+
// RUN: cat impl_part.dep | FileCheck impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE-RELATIVE
52+
4553

4654
//--- P1689.json.in
4755
[
@@ -168,6 +176,8 @@ void World() {
168176
// CHECK-MAKE: [[PREFIX]]/impl_part.cppm
169177
// CHECK-MAKE: [[PREFIX]]/header.mock
170178

179+
// CHECK-MAKE-RELATIVE: impl_part.o.ddi: impl_part.cppm header.mock
180+
171181
//--- interface_part.cppm
172182
export module M:interface_part;
173183
export void World();

0 commit comments

Comments
 (0)