]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Option absolute_paths_in_stderr also rewrites relative paths in MSVC diagnostic... 1504/head
authorhuangqinjin <huangqinjin@gmail.com>
Mon, 26 Aug 2024 15:18:42 +0000 (23:18 +0800)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 10 Sep 2024 18:06:12 +0000 (20:06 +0200)
src/ccache/core/common.cpp
src/ccache/core/common.hpp
unittest/test_core_common.cpp

index 7072f83eb835e57ac7fdf3e8f44f461c4d56ba68..a177296a444971b3070000c5c348982e89228785 100644 (file)
@@ -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));
index 1265609ecc2106d044816c9f9906cf3cebca75e3..ff7c1ff36e4fbd5d646d8f3727cde640007d52af 100644 (file)
@@ -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<path>[:1:2]X: ...
 //     In file included from X<path>[:1:2]X:
+//     X<path>(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
index ad2bbc7f8beda08381f1ce4b3350ed4474c4bb4b..ec628f73b0aeb501dd3ec0933dfb73dd48ba7a63 100644 (file)
@@ -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"