https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/182069

This patch essentially reverts 62fec3d2 which was an NFC, and replaces the 
remaining check for the output format with more generic scanning service option 
that controls whether we report absolute or relative file paths. Along with 
#182063 this makes the scanner implementation entirely independent of the 
desired output format.

>From 942d1a15b72e8f5d61c352749d2b0328260c9347 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Wed, 18 Feb 2026 09:15:29 -0800
Subject: [PATCH] [clang][deps] Don't treat the 'P1689' output format specially

---
 .../DependencyScanning/DependencyScanningService.h     |  2 ++
 clang/lib/DependencyScanning/DependencyScannerImpl.cpp | 10 ++--------
 clang/lib/DependencyScanning/ModuleDepCollector.cpp    |  4 +---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp          |  3 +++
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/DependencyScanning/DependencyScanningService.h
index 20ba86bd097b0..0575dbc7cca9a 100644
--- a/clang/include/clang/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/DependencyScanning/DependencyScanningService.h
@@ -91,6 +91,8 @@ struct DependencyScanningServiceOptions {
   ScanningOutputFormat Format = ScanningOutputFormat::Full;
   /// How to optimize resulting explicit module command lines.
   ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default;
+  /// Whether to make reported file paths absolute.
+  bool ReportAbsolutePaths = true;
   /// Whether the resulting command lines should load explicit PCMs eagerly.
   bool EagerLoadModules = false;
   /// Whether to trace VFS accesses during the scan.
diff --git a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp 
b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
index 861e6e0042265..5e1d12e95c162 100644
--- a/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
+++ b/clang/lib/DependencyScanning/DependencyScannerImpl.cpp
@@ -794,17 +794,11 @@ bool DependencyScanningAction::runInvocation(
       Service, *OriginalInvocation, Controller, *MaybePrebuiltModulesASTMap,
       StableDirs);
 
-  std::unique_ptr<FrontendAction> Action;
-
-  if (Service.getOpts().Format == ScanningOutputFormat::P1689)
-    Action = std::make_unique<PreprocessOnlyAction>();
-  else
-    Action = std::make_unique<ReadPCHAndPreprocessAction>();
-
   if (ScanInstance.getDiagnostics().hasErrorOccurred())
     return false;
 
-  const bool Result = ScanInstance.ExecuteAction(*Action);
+  ReadPCHAndPreprocessAction Action;
+  const bool Result = ScanInstance.ExecuteAction(Action);
 
   // ExecuteAction is responsible for calling finish.
   DiagConsumerFinished = true;
diff --git a/clang/lib/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/DependencyScanning/ModuleDepCollector.cpp
index 46a0f79bfd38e..2cc36e88eb8f1 100644
--- a/clang/lib/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/DependencyScanning/ModuleDepCollector.cpp
@@ -960,9 +960,7 @@ static StringRef makeAbsoluteAndPreferred(CompilerInstance 
&CI, StringRef Path,
 }
 
 void ModuleDepCollector::addFileDep(StringRef Path) {
-  if (Service.getOpts().Format == ScanningOutputFormat::P1689) {
-    // Within P1689 format, we don't want all the paths to be absolute path
-    // since it may violate the traditional make style dependencies info.
+  if (!Service.getOpts().ReportAbsolutePaths) {
     FileDeps.emplace_back(Path);
     return;
   }
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 30fb8d47f8d5d..cba0915f4a050 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -1142,6 +1142,9 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   Opts.Mode = ScanMode;
   Opts.Format = Format;
   Opts.OptimizeArgs = OptimizeArgs;
+  // Within P1689 format, we don't want all the paths to be absolute path
+  // since it may violate the traditional make style dependencies info.
+  Opts.ReportAbsolutePaths = Format != ScanningOutputFormat::P1689;
   Opts.EagerLoadModules = EagerLoadModules;
   Opts.TraceVFS = Verbose;
   Opts.AsyncScanModules = AsyncScanModules;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to