Skip to content

Conversation

hjyamauchi
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

@llvm/pr-subscribers-clang

Author: Hiroshi Yamauchi (hjyamauchi)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/155908.diff

1 Files Affected:

  • (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+23-8)
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f10b73278381b..44d99a5b2e6f7 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));

Copy link

github-actions bot commented Aug 28, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jansvoboda11
Copy link
Contributor

Is the motivation mainly testing? If so, I'd suggest either hiding this behavior behind a flag, and then enabling the flag in tests and keeping the paths unmodified by default in production. Another way of doing test checks in a cross-platform way is the sed 's:\\\\\?:/:g' dance on the scanner output that we do in clang/test/ClangScanDeps.

@hjyamauchi
Copy link
Contributor Author

Is the motivation mainly testing? If so, I'd suggest either hiding this behavior behind a flag, and then enabling the flag in tests and keeping the paths unmodified by default in production. Another way of doing test checks in a cross-platform way is the sed 's:\\\\\?:/:g' dance on the scanner output that we do in clang/test/ClangScanDeps.

This started mainly from a testing concern about fragility of using sed, but there was also a general concern about ClangScanDeps potentially emitting mixed-slash paths on Windows in our discussion (here). Because of this, we used PathSanitizingFileCheck from Swift to handle non-canonical paths to be a bit more precise than sed in this PR. This PR aims to canonicalize paths when paths are emitted by ClangScanDeps to avoid potential mixed-slash issues for Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants