-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Canonicalize clang-scan-deps input-file/file-deps paths for Windows #155908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang Author: Hiroshi Yamauchi (hjyamauchi) ChangesFull diff: https://github.com/llvm/llvm-project/pull/155908.diff 1 Files Affected:
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));
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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 |
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 |
No description provided.