]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Context: move (cached_)result_name/result_path
authorThomas Otto <thomas.otto@pdv-fs.de>
Sat, 25 Jan 2020 09:44:12 +0000 (10:44 +0100)
committerThomas Otto <thomas.otto@pdv-fs.de>
Mon, 17 Feb 2020 20:39:02 +0000 (21:39 +0100)
Also convert result_path to std::string.

src/Context.cpp
src/Context.hpp
src/ccache.cpp
src/legacy_globals.cpp
src/legacy_globals.hpp

index cf670878f9ea31d8c684ee42afa42c0ca9b0cb92..699bb2308b24b00167e13778ba61e9ef3ebfd87b 100644 (file)
@@ -30,4 +30,6 @@ Context::Context()
 Context::~Context()
 {
   args_free(orig_args);
+
+  free(result_name);
 }
index 15c86944084c11a4a0b4b2190c0d8f10240e9c91..1e7727f0e81aebdeb45a5763292284c8a925a48f 100644 (file)
@@ -25,6 +25,7 @@
 #include "NonCopyable.hpp"
 
 struct args;
+struct digest;
 
 struct Context : NonCopyable
 {
@@ -46,4 +47,12 @@ struct Context : NonCopyable
 
   // The original argument list.
   struct args* orig_args = nullptr;
+
+  // Name (represented as a struct digest) of the file containing the cached
+  // result.
+  struct digest* result_name = nullptr;
+
+  // Full path to the file containing the result
+  // (cachedir/a/b/cdef[...]-size.result).
+  std::string result_path;
 };
index 3b01c1875f0c074cffb7d39330e8b7920a84a897..8f9cbe998ab8217f1b17056c48d52e2947948346 100644 (file)
@@ -1053,7 +1053,7 @@ update_manifest_file(Context& ctx)
   cc_log("Adding result name to %s", manifest_path);
   if (!manifest_put(ctx.config,
                     manifest_path,
-                    *cached_result_name,
+                    *ctx.result_name,
                     g_included_files,
                     save_timestamp)) {
     cc_log("Failed to add result name to %s", manifest_path);
@@ -1072,13 +1072,11 @@ update_cached_result_globals(Context& ctx, struct digest* result_name)
 {
   char result_name_string[DIGEST_STRING_BUFFER_SIZE];
   digest_as_string(result_name, result_name_string);
-  cached_result_name = result_name;
-  cached_result_path =
-    x_strdup(Util::get_path_in_cache(ctx.config.cache_dir(),
-                                     ctx.config.cache_dir_levels(),
-                                     result_name_string,
-                                     ".result")
-               .c_str());
+  ctx.result_name = result_name;
+  ctx.result_path = Util::get_path_in_cache(ctx.config.cache_dir(),
+                                            ctx.config.cache_dir_levels(),
+                                            result_name_string,
+                                            ".result");
   ctx.stats_file =
     fmt::format("{}/{}/stats", ctx.config.cache_dir(), result_name_string[0]);
 }
@@ -1340,12 +1338,12 @@ to_cache(Context& ctx,
     result_file_map.emplace(FileType::dwarf_object, ctx.args_info.output_dwo);
   }
 
-  auto orig_dest_stat = Stat::stat(cached_result_path);
-  result_put(ctx, cached_result_path, result_file_map);
+  auto orig_dest_stat = Stat::stat(ctx.result_path);
+  result_put(ctx, ctx.result_path, result_file_map);
 
-  cc_log("Stored in cache: %s", cached_result_path);
+  cc_log("Stored in cache: %s", ctx.result_path.c_str());
 
-  auto new_dest_stat = Stat::stat(cached_result_path, Stat::OnError::log);
+  auto new_dest_stat = Stat::stat(ctx.result_path, Stat::OnError::log);
   if (!new_dest_stat) {
     stats_update(STATS_ERROR);
     failed();
@@ -2079,7 +2077,7 @@ from_cache(Context& ctx,
   if (ctx.args_info.generating_diagnostics) {
     result_file_map.emplace(FileType::diagnostic, ctx.args_info.output_dia);
   }
-  bool ok = result_get(ctx, cached_result_path, result_file_map);
+  bool ok = result_get(ctx, ctx.result_path, result_file_map);
   if (!ok) {
     cc_log("Failed to get result from cache");
     tmp_unlink(tmp_stderr);
@@ -3529,8 +3527,6 @@ void
 cc_reset()
 {
   free_and_nullify(included_pch_file);
-  free_and_nullify(cached_result_name);
-  free_and_nullify(cached_result_path);
   free_and_nullify(manifest_path);
   time_of_compilation = 0;
   for (size_t i = 0; i < ignore_headers_len; i++) {
index 51088f4a2580e7e13e07976577785eaea04bc40c..aba2231d1489f3dd32b7197e0fea60036dbf0e1f 100644 (file)
 
 #include "legacy_globals.hpp"
 
-// Name (represented as a struct digest) of the file containing the cached
-// result.
-struct digest* cached_result_name;
-
-// Full path to the file containing the result
-// (cachedir/a/b/cdef[...]-size.result).
-char* cached_result_path;
-
 // Full path to the file containing the manifest
 // (cachedir/a/b/cdef[...]-size.manifest).
 char* manifest_path;
index bc51d2249bd7ca6b258684b876f667595e73db2f..0ee048d47ae1539d6672b6dafd0d9cda543ef843 100644 (file)
 
 extern unsigned lock_staleness_limit;
 
-extern struct digest* cached_result_name;
-
-extern char* cached_result_path;
-
 extern char* manifest_path;
 
 extern time_t time_of_compilation;