]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify Context::ignore_headers
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 18 Apr 2020 16:32:57 +0000 (18:32 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 18 Apr 2020 16:32:57 +0000 (18:32 +0200)
src/Context.cpp
src/Context.hpp
src/ccache.cpp

index 9401c37d9831ab6cfd7eb10ef4f8264b93981617..078f04f5b3138417c822a6dd37f84b4577461060 100644 (file)
@@ -30,9 +30,4 @@ Context::Context()
 Context::~Context()
 {
   free(result_name);
-
-  for (size_t i = 0; i < ignore_headers_len; i++) {
-    free(ignore_headers[i]);
-  }
-  free(ignore_headers);
 }
index d492d58af3c25a37aa2df759dde837f1c267d2b1..6ab909003f9472e6e976b6fcf65dcd6f611cf6ac 100644 (file)
@@ -27,7 +27,9 @@
 #include "ccache.hpp"
 #include "hash.hpp"
 
+#include <string>
 #include <unordered_map>
+#include <vector>
 
 struct Context : NonCopyable
 {
@@ -85,9 +87,8 @@ struct Context : NonCopyable
   // The .gch/.pch/.pth file used for compilation.
   std::string included_pch_file;
 
-  // List of headers to ignore.
-  char** ignore_headers = nullptr;
-  size_t ignore_headers_len = 0;
+  // Headers (or directories with headers) to ignore in manifest mode.
+  std::vector<std::string> ignore_header_paths;
 
   // Full path to the statistics file in the subdirectory where the cached
   // result belongs (<cache_dir>/<x>/stats).
index bda0c084fa02df43fb3869dcd1511ac417012ff3..a3ebf606ce29f4d7023f8d2fe9bfe0886b58f272 100644 (file)
@@ -443,6 +443,11 @@ do_remember_include_file(Context& ctx,
     return true;
   }
 
+  // Canonicalize path for comparison; Clang uses ./header.h.
+  if (Util::starts_with(path, "./")) {
+    path.erase(0, 2);
+  }
+
 #ifdef _WIN32
   {
     // stat fails on directories on win32.
@@ -468,27 +473,9 @@ do_remember_include_file(Context& ctx,
     return false;
   }
 
-  // Canonicalize path for comparison; clang uses ./header.h.
-  {
-    const char* canonical = path.c_str();
-    size_t canonical_len = path.length();
-    if (canonical[0] == '.' && canonical[1] == '/') {
-      canonical += 2;
-      canonical_len -= 2;
-    }
-
-    for (size_t i = 0; i < ctx.ignore_headers_len; i++) {
-      char* ignore = ctx.ignore_headers[i];
-      size_t ignore_len = strlen(ignore);
-      if (ignore_len > canonical_len) {
-        continue;
-      }
-      if (strncmp(canonical, ignore, ignore_len) == 0
-          && (ignore[ignore_len - 1] == DIR_DELIM_CH
-              || canonical[ignore_len] == DIR_DELIM_CH
-              || canonical[ignore_len] == '\0')) {
-        return true;
-      }
+  for (const auto& ignore_header_path : ctx.ignore_header_paths) {
+    if (Util::matches_dir_prefix_or_file(ignore_header_path, path)) {
+      return true;
     }
   }
 
@@ -677,18 +664,6 @@ process_preprocessed_file(Context& ctx,
     return false;
   }
 
-  ctx.ignore_headers = nullptr;
-  ctx.ignore_headers_len = 0;
-
-  if (!ctx.config.ignore_headers_in_manifest().empty()) {
-    for (const std::string& header : Util::split_into_strings(
-           ctx.config.ignore_headers_in_manifest(), PATH_DELIM)) {
-      ctx.ignore_headers = static_cast<char**>(x_realloc(
-        ctx.ignore_headers, (ctx.ignore_headers_len + 1) * sizeof(char*)));
-      ctx.ignore_headers[ctx.ignore_headers_len++] = x_strdup(header.c_str());
-    }
-  }
-
   // Bytes between p and q are pending to be hashed.
   char* p = data;
   char* q = data;
@@ -3346,6 +3321,8 @@ static void
 set_up_context(Context& ctx, int argc, const char* const* argv)
 {
   ctx.orig_args = args_init(argc, argv);
+  ctx.ignore_header_paths = Util::split_into_strings(
+    ctx.config.ignore_headers_in_manifest(), PATH_DELIM);
 }
 
 // Initialize ccache, must be called once before anything else is run.