]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve handling of ignore_header_paths matching
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 7 Jun 2024 14:24:21 +0000 (16:24 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 Jun 2024 15:18:51 +0000 (17:18 +0200)
src/ccache/ccache.cpp

index 627c6d3de2c26d16a25a2cfd95afd530d21e7601..33efd3f32f9af0bf5f671bc6051f35d720a295bf 100644 (file)
@@ -335,10 +335,9 @@ remember_include_file(Context& ctx,
     return {};
   }
 
-  std::string path_str = util::pstr(path);
-
-  if (path_str.length() >= 2 && path_str[0] == '<'
-      && path_str[path_str.length() - 1] == '>') {
+  util::PathString path_str(path);
+  if (path_str.str().length() >= 2 && path_str.str()[0] == '<'
+      && path_str.str()[path_str.str().length() - 1] == '>') {
     // Typically <built-in> or <command-line>.
     return {};
   }
@@ -349,11 +348,6 @@ remember_include_file(Context& ctx,
     return {};
   }
 
-  // Canonicalize path for comparison; Clang uses ./header.h.
-  if (util::starts_with(path_str, "./")) {
-    path_str.erase(0, 2);
-  }
-
   if (ctx.included_files.find(path_str) != ctx.included_files.end()) {
     // Already known include file.
     return {};
@@ -389,9 +383,16 @@ remember_include_file(Context& ctx,
     return tl::unexpected(Statistic::bad_input_file);
   }
 
-  for (const auto& ignore_header_path : ctx.ignore_header_paths) {
-    if (file_path_matches_dir_prefix_or_file(ignore_header_path, path_str)) {
-      return {};
+  if (!ctx.ignore_header_paths.empty()) {
+    // Canonicalize path for comparison; Clang uses ./header.h.
+    const std::string& canonical_path_str =
+      util::starts_with(path_str.str(), "./") ? path_str.str().substr(2)
+                                              : path_str;
+    for (const auto& ignore_header_path : ctx.ignore_header_paths) {
+      if (file_path_matches_dir_prefix_or_file(ignore_header_path,
+                                               canonical_path_str)) {
+        return {};
+      }
     }
   }