From: huangqinjin Date: Mon, 26 Aug 2024 15:18:42 +0000 (+0800) Subject: feat: Option absolute_paths_in_stderr also rewrites relative paths in MSVC diagnostic... X-Git-Tag: v4.11~82^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1504%2Fhead;p=thirdparty%2Fccache.git feat: Option absolute_paths_in_stderr also rewrites relative paths in MSVC diagnostics messages --- diff --git a/src/ccache/core/common.cpp b/src/ccache/core/common.cpp index 7072f83e..a177296a 100644 --- a/src/ccache/core/common.cpp +++ b/src/ccache/core/common.cpp @@ -110,8 +110,8 @@ rewrite_stderr_to_absolute_paths(std::string_view text) result.append(csi_seq.data(), csi_seq.length()); line = line.substr(csi_seq.length()); } - size_t path_end = line.find(':'); - if (path_end == std::string_view::npos) { + size_t path_end = get_diagnostics_path_length(line); + if (path_end == 0) { result.append(line.data(), line.length()); } else { fs::path path(line.substr(0, path_end)); diff --git a/src/ccache/core/common.hpp b/src/ccache/core/common.hpp index 1265609e..ff7c1ff3 100644 --- a/src/ccache/core/common.hpp +++ b/src/ccache/core/common.hpp @@ -33,11 +33,14 @@ void ensure_dir_exists(const std::filesystem::path& dir); std::filesystem::path make_relative_path(const Context& ctx, const std::filesystem::path& path); -// Rewrite path to absolute path in `text` in the following two cases, where X +// Rewrite path to absolute path in `text` in the following cases, where X // may be optional ANSI CSI sequences: // // X[:1:2]X: ... // In file included from X[:1:2]X: +// X(line[,column])[ ]: ... +// +// See get_diagnostics_path_length(). std::string rewrite_stderr_to_absolute_paths(std::string_view text); // Send `text` to file descriptor `fd` (typically stdout or stderr, which diff --git a/unittest/test_core_common.cpp b/unittest/test_core_common.cpp index ad2bbc7f..ec628f73 100644 --- a/unittest/test_core_common.cpp +++ b/unittest/test_core_common.cpp @@ -54,7 +54,16 @@ TEST_CASE("core::rewrite_stderr_to_absolute_paths") std::string input = "a:1:2\n" + "a(3):\n" + "a(3) :\n" + "a(3,4):\n" + "a(3,4) :\n" + "existing\n" "existing:3:4\n" + "existing(3):\n" + "existing(3) :\n" + "existing(3,4):\n" + "existing(3,4) :\n" "c:5:6\n" "\x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n" "\x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n" @@ -62,7 +71,16 @@ TEST_CASE("core::rewrite_stderr_to_absolute_paths") "In file included from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"; std::string expected = FMT( "a:1:2\n" + "a(3):\n" + "a(3) :\n" + "a(3,4):\n" + "a(3,4) :\n" + "existing\n" "{0}:3:4\n" + "{0}(3):\n" + "{0}(3) :\n" + "{0}(3,4):\n" + "{0}(3,4) :\n" "c:5:6\n" "\x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n" "\x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"