diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index d2791565775ba..5849e9ab2644c 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -601,13 +601,22 @@ static bool useCAS() { } template -static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) { - return [&JOS, Strings = std::forward(Strings)] { - for (StringRef Str : Strings) +static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings, + bool Paths = false) { + return [&JOS, Strings = std::forward(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); + } + } }; } @@ -810,8 +819,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)); @@ -840,8 +852,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));