]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Context: move included_pch_file and convert to std::string
authorThomas Otto <thomas.otto@pdv-fs.de>
Sun, 26 Jan 2020 20:16:58 +0000 (21:16 +0100)
committerThomas Otto <thomas.otto@pdv-fs.de>
Mon, 17 Feb 2020 21:06:17 +0000 (22:06 +0100)
src/Context.hpp
src/ccache.cpp
src/legacy_globals.cpp
src/legacy_globals.hpp

index 19098a6e8ba92a845eba7eb9012843702e7a9dfc..56358cf2cb29b597c4c37b9e7d573ac96c015571 100644 (file)
@@ -86,4 +86,7 @@ struct Context : NonCopyable
   // Compiler guessing is currently only based on the compiler name, so nothing
   // should hard-depend on it if possible.
   GuessedCompiler guessed_compiler = GuessedCompiler::unknown;
+
+  // The .gch/.pch/.pth file used for compilation.
+  std::string included_pch_file;
 };
index e4181f5f8fc90eb01cc8ad70e0883e24b79544ed..d93d7cf6ce3e0e84063cb3cb9fb7a8f42346da32 100644 (file)
@@ -518,7 +518,7 @@ do_remember_include_file(Context& ctx,
 
   is_pch = is_precompiled_header(path.c_str());
   if (is_pch) {
-    if (!included_pch_file) {
+    if (ctx.included_pch_file.empty()) {
       cc_log("Detected use of precompiled header: %s", path.c_str());
     }
     bool using_pch_sum = false;
@@ -868,8 +868,9 @@ process_preprocessed_file(Context& ctx,
 
   // Explicitly check the .gch/.pch/.pth file as Clang does not include any
   // mention of it in the preprocessed output.
-  if (included_pch_file) {
-    std::string pch_path = make_relative_path(ctx, included_pch_file);
+  if (!ctx.included_pch_file.empty()) {
+    std::string pch_path =
+      make_relative_path(ctx, ctx.included_pch_file.c_str());
     hash_string(hash, pch_path);
     remember_include_file(ctx, pch_path, hash, false, NULL);
   }
@@ -1006,8 +1007,9 @@ result_name_from_depfile(Context& ctx, struct hash* hash)
 
   // Explicitly check the .gch/.pch/.pth file as it may not be mentioned in the
   // dependencies output.
-  if (included_pch_file) {
-    std::string pch_path = make_relative_path(ctx, included_pch_file);
+  if (!ctx.included_pch_file.empty()) {
+    std::string pch_path =
+      make_relative_path(ctx, ctx.included_pch_file.c_str());
     hash_string(hash, pch_path);
     remember_include_file(ctx, pch_path, hash, false, NULL);
   }
@@ -2172,7 +2174,7 @@ color_output_possible(void)
 }
 
 static bool
-detect_pch(const char* option, const char* arg, bool* found_pch)
+detect_pch(Context& ctx, const char* option, const char* arg, bool* found_pch)
 {
   // Try to be smart about detecting precompiled headers.
   char* pch_file = NULL;
@@ -2206,14 +2208,14 @@ detect_pch(const char* option, const char* arg, bool* found_pch)
   }
 
   if (pch_file) {
-    if (included_pch_file) {
+    if (!ctx.included_pch_file.empty()) {
       cc_log("Multiple precompiled headers used: %s and %s\n",
-             included_pch_file,
+             ctx.included_pch_file.c_str(),
              pch_file);
       stats_update(STATS_ARGS);
       return false;
     }
-    included_pch_file = pch_file;
+    ctx.included_pch_file = pch_file;
     *found_pch = true;
   }
   return true;
@@ -2883,7 +2885,7 @@ cc_process_args(Context& ctx,
         return false;
       }
 
-      if (!detect_pch(argv[i], argv[i + 1], &found_pch)) {
+      if (!detect_pch(ctx, argv[i], argv[i + 1], &found_pch)) {
         return false;
       }
 
@@ -3530,7 +3532,6 @@ free_and_nullify(T*& ptr)
 void
 cc_reset()
 {
-  free_and_nullify(included_pch_file);
   for (size_t i = 0; i < ignore_headers_len; i++) {
     free_and_nullify(ignore_headers[i]);
   }
index 19375da7f38bc5e50ff0b4fdcf02e5eea1d294a6..1bac9882a9161b246ff0cde6f9fa23be4dbce423 100644 (file)
@@ -24,8 +24,5 @@ char** ignore_headers;
 // Size of headers to ignore list.
 size_t ignore_headers_len;
 
-// The .gch/.pch/.pth file used for compilation.
-char* included_pch_file = nullptr;
-
 // How long (in microseconds) to wait before breaking a stale lock.
 unsigned lock_staleness_limit = 2000000;
index 5f5e9a350a35e31fcca5a40a596b8c52b3050bdd..bb083fc7ef79a840e5fa7d2c739307572bb3a83a 100644 (file)
@@ -33,5 +33,3 @@ extern unsigned lock_staleness_limit;
 extern char** ignore_headers;
 
 extern size_t ignore_headers_len;
-
-extern char* included_pch_file;