Skip to content

Commit 5453e27

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

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,19 @@ 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 CanonicalizePath = false) {
606+
return [&JOS, Strings = std::forward<Container>(Strings), CanonicalizePath] {
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 (CanonicalizePath) {
612+
llvm::SmallString<261> Path = Str;
613+
llvm::sys::path::make_preferred(Path);
614+
JOS.value(Path.str());
615+
} else
616+
JOS.value(Str);
611617
};
612618
}
613619

@@ -810,8 +816,11 @@ class FullDeps {
810816
toJSONStrings(JOS, Cmd.Arguments));
811817
JOS.attribute("executable", StringRef(Cmd.Executable));
812818
JOS.attributeArray("file-deps",
813-
toJSONStrings(JOS, I.FileDeps));
814-
JOS.attribute("input-file", StringRef(I.FileName));
819+
toJSONStrings(JOS, I.FileDeps,
820+
/*CanonicalizePath*/true));
821+
llvm::SmallString<261> InputFile = StringRef(I.FileName);
822+
llvm::sys::path::make_preferred(InputFile);
823+
JOS.attribute("input-file", InputFile.str());
815824
if (EmitVisibleModules)
816825
JOS.attributeArray("visible-clang-modules",
817826
toJSONSorted(JOS, I.VisibleModules));
@@ -840,8 +849,11 @@ class FullDeps {
840849
toJSONStrings(JOS, I.DriverCommandLine));
841850
JOS.attribute("executable", "clang");
842851
JOS.attributeArray("file-deps",
843-
toJSONStrings(JOS, I.FileDeps));
844-
JOS.attribute("input-file", StringRef(I.FileName));
852+
toJSONStrings(JOS, I.FileDeps,
853+
/*CanonicalizePath*/true));
854+
llvm::SmallString<261> InputFile = StringRef(I.FileName);
855+
llvm::sys::path::make_preferred(InputFile);
856+
JOS.attribute("input-file", InputFile.str());
845857
if (EmitVisibleModules)
846858
JOS.attributeArray("visible-clang-modules",
847859
toJSONSorted(JOS, I.VisibleModules));

0 commit comments

Comments
 (0)