]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Rewrite more paths with absolute_paths_in_stderr (#1539)
authorgitmodimo <g.modimo@gmail.com>
Mon, 30 Dec 2024 13:11:25 +0000 (14:11 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Dec 2024 13:11:25 +0000 (14:11 +0100)
src/ccache/core/common.cpp
unittest/test_core_common.cpp

index f95937331f2f1a1a6ee9525da9f787c770759592..df81f8d4d926821f2e020dfee9076e5c2b7a61b5 100644 (file)
@@ -93,7 +93,17 @@ make_relative_path(const Context& ctx, const fs::path& path)
 std::string
 rewrite_stderr_to_absolute_paths(std::string_view text)
 {
-  const std::string_view in_file_included_from = "In file included from ";
+  // Line prefixes from gcc compiler plus extra space at the end
+  // https://gcc.gnu.org/git?p=gcc.git;a=blob;f=gcc/diagnostic-format-text.cc;h=856d25e8482cd0bff39bd8076e6e529e184362cc;hb=HEAD#l676
+  const std::string_view in_file_included_from_msgs[] = {
+    "                 from ",
+    "In file included from ",
+    "        included from ",
+    "In module imported at ", // longer message first to match in full
+    "In module ",
+    "of module ",
+    "imported at ",
+  };
 
   std::string result;
   using util::Tokenizer;
@@ -101,9 +111,12 @@ rewrite_stderr_to_absolute_paths(std::string_view text)
                              "\n",
                              Tokenizer::Mode::include_empty,
                              Tokenizer::IncludeDelimiter::yes)) {
-    if (util::starts_with(line, in_file_included_from)) {
-      result += in_file_included_from;
-      line = line.substr(in_file_included_from.length());
+    for (auto& in_file_included_from : in_file_included_from_msgs) {
+      if (util::starts_with(line, in_file_included_from)) {
+        result += in_file_included_from;
+        line = line.substr(in_file_included_from.length());
+        break;
+      }
     }
     while (!line.empty() && line[0] == 0x1b) {
       auto csi_seq = find_first_ansi_csi_seq(line);
index ec628f73b0aeb501dd3ec0933dfb73dd48ba7a63..43c2a084e841da09f0e78c3a4395448d0c2b70ef 100644 (file)
@@ -68,7 +68,19 @@ TEST_CASE("core::rewrite_stderr_to_absolute_paths")
     "\x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
     "\x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
     "In file included from \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
-    "In file included from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n";
+    "In file included from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "                 from \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "                 from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "        included from \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "        included from \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "In module \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "In module \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "of module \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "of module \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "In module imported at \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "In module imported at \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n"
+    "imported at \x1b[01m\x1b[Kexisting:\x1b[m\x1b[K: foo\n"
+    "imported at \x1b[01m\x1b[Kexisting:47:11:\x1b[m\x1b[K: foo\n";
   std::string expected = FMT(
     "a:1:2\n"
     "a(3):\n"
@@ -85,7 +97,19 @@ TEST_CASE("core::rewrite_stderr_to_absolute_paths")
     "\x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
     "\x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
     "In file included from \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
-    "In file included from \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n",
+    "In file included from \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "                 from \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "                 from \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "        included from \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "        included from \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "In module \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "In module \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "of module \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "of module \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "In module imported at \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "In module imported at \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n"
+    "imported at \x1b[01m\x1b[K{0}:\x1b[m\x1b[K: foo\n"
+    "imported at \x1b[01m\x1b[K{0}:47:11:\x1b[m\x1b[K: foo\n",
     *fs::canonical("existing"));
   CHECK(core::rewrite_stderr_to_absolute_paths(input) == expected);
 }