[clang] Canonicalize clang-scan-deps input-file/file-deps paths for Windows (PR #155908)

Hiroshi Yamauchi via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 28 12:47:31 PDT 2025


https://github.com/hjyamauchi updated https://github.com/llvm/llvm-project/pull/155908

>From 6d46a4e65274f96816a13e64a3c8b686d0a4a4b8 Mon Sep 17 00:00:00 2001
From: Hiroshi Yamauchi <hjyamauchi at gmail.com>
Date: Thu, 28 Aug 2025 12:17:24 -0700
Subject: [PATCH] Canonicalize clang-scan-deps input-file/file-deps paths for
 Windows

---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 31 ++++++++++++++-----
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f10b73278381b..1176893cf90da 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -346,13 +346,22 @@ handleMakeDependencyToolResult(const std::string &Input,
 }
 
 template <typename Container>
-static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) {
-  return [&JOS, Strings = std::forward<Container>(Strings)] {
-    for (StringRef Str : Strings)
+static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings,
+                          bool Paths = false) {
+  return [&JOS, Strings = std::forward<Container>(Strings), Paths] {
+    for (StringRef Str : Strings) {
       // Not reporting SDKSettings.json so that test checks can remain (mostly)
       // platform-agnostic.
-      if (!Str.ends_with("SDKSettings.json"))
+      if (Str.ends_with("SDKSettings.json"))
+        continue;
+      if (Paths) {
+        llvm::SmallString<261> Path{Str};
+        llvm::sys::path::make_preferred(Path);
+        JOS.value(Path.str());
+      } else {
         JOS.value(Str);
+      }
+    }
   };
 }
 
@@ -535,8 +544,11 @@ class FullDeps {
                                        toJSONStrings(JOS, Cmd.Arguments));
                     JOS.attribute("executable", StringRef(Cmd.Executable));
                     JOS.attributeArray("file-deps",
-                                       toJSONStrings(JOS, I.FileDeps));
-                    JOS.attribute("input-file", StringRef(I.FileName));
+                                       toJSONStrings(JOS, I.FileDeps,
+                                                     /*Paths*/ true));
+                    llvm::SmallString<261> InputFile = StringRef(I.FileName);
+                    llvm::sys::path::make_preferred(InputFile);
+                    JOS.attribute("input-file", InputFile.str());
                     if (EmitVisibleModules)
                       JOS.attributeArray("visible-clang-modules",
                                          toJSONSorted(JOS, I.VisibleModules));
@@ -558,8 +570,11 @@ class FullDeps {
                                      toJSONStrings(JOS, I.DriverCommandLine));
                   JOS.attribute("executable", "clang");
                   JOS.attributeArray("file-deps",
-                                     toJSONStrings(JOS, I.FileDeps));
-                  JOS.attribute("input-file", StringRef(I.FileName));
+                                     toJSONStrings(JOS, I.FileDeps,
+                                                   /*Paths*/ true));
+                  llvm::SmallString<261> InputFile = StringRef(I.FileName);
+                  llvm::sys::path::make_preferred(InputFile);
+                  JOS.attribute("input-file", InputFile.str());
                   if (EmitVisibleModules)
                     JOS.attributeArray("visible-clang-modules",
                                        toJSONSorted(JOS, I.VisibleModules));



More information about the cfe-commits mailing list