Skip to content

Commit 048182f

Browse files
committed
Canonicalize clang-scan-deps input-file/file-deps paths for Windows
1 parent d879710 commit 048182f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,20 @@ static bool useCAS() {
601601
}
602602

603603
template <typename Container>
604-
static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) {
605-
return [&JOS, Strings = std::forward<Container>(Strings)] {
604+
static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings,
605+
bool ArePaths = false) {
606+
return [&JOS, Strings = std::forward<Container>(Strings), ArePaths] {
606607
for (StringRef Str : Strings)
607608
// Not reporting SDKSettings.json so that test checks can remain (mostly)
608609
// platform-agnostic.
609610
if (!Str.ends_with("SDKSettings.json"))
610-
JOS.value(Str);
611+
if (ArePaths) {
612+
llvm::SmallString<261> Path = Str;
613+
llvm::sys::path::make_preferred(Path);
614+
JOS.value(Path.str());
615+
} else {
616+
JOS.value(Str);
617+
}
611618
};
612619
}
613620

@@ -810,8 +817,11 @@ class FullDeps {
810817
toJSONStrings(JOS, Cmd.Arguments));
811818
JOS.attribute("executable", StringRef(Cmd.Executable));
812819
JOS.attributeArray("file-deps",
813-
toJSONStrings(JOS, I.FileDeps));
814-
JOS.attribute("input-file", StringRef(I.FileName));
820+
toJSONStrings(JOS, I.FileDeps,
821+
/*ArePaths*/true));
822+
llvm::SmallString<261> InputFile = StringRef(I.FileName);
823+
llvm::sys::path::make_preferred(InputFile);
824+
JOS.attribute("input-file", InputFile.str());
815825
if (EmitVisibleModules)
816826
JOS.attributeArray("visible-clang-modules",
817827
toJSONSorted(JOS, I.VisibleModules));
@@ -840,8 +850,11 @@ class FullDeps {
840850
toJSONStrings(JOS, I.DriverCommandLine));
841851
JOS.attribute("executable", "clang");
842852
JOS.attributeArray("file-deps",
843-
toJSONStrings(JOS, I.FileDeps));
844-
JOS.attribute("input-file", StringRef(I.FileName));
853+
toJSONStrings(JOS, I.FileDeps,
854+
/*ArePaths*/true));
855+
llvm::SmallString<261> InputFile = StringRef(I.FileName);
856+
llvm::sys::path::make_preferred(InputFile);
857+
JOS.attribute("input-file", InputFile.str());
845858
if (EmitVisibleModules)
846859
JOS.attributeArray("visible-clang-modules",
847860
toJSONSorted(JOS, I.VisibleModules));

0 commit comments

Comments
 (0)