]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Context: move time_of_compilation, adapt manifest
authorThomas Otto <thomas.otto@pdv-fs.de>
Sat, 25 Jan 2020 09:49:49 +0000 (10:49 +0100)
committerThomas Otto <thomas.otto@pdv-fs.de>
Mon, 17 Feb 2020 20:51:07 +0000 (21:51 +0100)
src/Context.hpp
src/ccache.cpp
src/ccache.hpp
src/legacy_globals.cpp
src/legacy_globals.hpp
src/manifest.cpp
src/manifest.hpp

index 617a09a7c195d431b5014c01f992a44975a0fc4b..9335e80abefc8565369df6e1e8791ce8a6a10e48 100644 (file)
@@ -59,4 +59,8 @@ struct Context : NonCopyable
   // Full path to the file containing the manifest
   // (cachedir/a/b/cdef[...]-size.manifest).
   std::string manifest_path;
+
+  // Time of compilation. Used to see if include files have changed after
+  // compilation.
+  time_t time_of_compilation = 0;
 };
index c9c015a19276a7d6956af4d1d3205671775f05aa..ed8ba7440292c2de70f1a126b8307dec43b1792c 100644 (file)
@@ -499,14 +499,14 @@ do_remember_include_file(Context& ctx,
   // starting compilation and writing the include file. See also the notes
   // under "Performance" in doc/MANUAL.adoc.
   if (!(ctx.config.sloppiness() & SLOPPY_INCLUDE_FILE_MTIME)
-      && st.mtime() >= time_of_compilation) {
+      && st.mtime() >= ctx.time_of_compilation) {
     cc_log("Include file %s too new", path.c_str());
     return false;
   }
 
   // The same >= logic as above applies to the change time of the file.
   if (!(ctx.config.sloppiness() & SLOPPY_INCLUDE_FILE_CTIME)
-      && st.ctime() >= time_of_compilation) {
+      && st.ctime() >= ctx.time_of_compilation) {
     cc_log("Include file %s ctime too new", path.c_str());
     return false;
   }
@@ -1055,6 +1055,7 @@ update_manifest_file(Context& ctx)
                     ctx.manifest_path,
                     *ctx.result_name,
                     g_included_files,
+                    ctx.time_of_compilation,
                     save_timestamp)) {
     cc_log("Failed to add result name to %s", ctx.manifest_path.c_str());
   } else {
@@ -1192,7 +1193,7 @@ to_cache(Context& ctx,
     }
     add_prefix(ctx, depend_mode_args, ctx.config.prefix_command().c_str());
 
-    time_of_compilation = time(NULL);
+    ctx.time_of_compilation = time(NULL);
     status = execute(
       depend_mode_args->argv, tmp_stdout_fd, tmp_stderr_fd, &compiler_pid);
     args_free(depend_mode_args);
@@ -1393,7 +1394,7 @@ to_cache(Context& ctx,
 static struct digest*
 get_result_name_from_cpp(Context& ctx, struct args* args, struct hash* hash)
 {
-  time_of_compilation = time(NULL);
+  ctx.time_of_compilation = time(NULL);
 
   char* path_stderr = NULL;
   char* path_stdout = nullptr;
@@ -3525,7 +3526,6 @@ void
 cc_reset()
 {
   free_and_nullify(included_pch_file);
-  time_of_compilation = 0;
   for (size_t i = 0; i < ignore_headers_len; i++) {
     free_and_nullify(ignore_headers[i]);
   }
index 990ec7098f2360b4b43672d3abe1cc091ed42fb3..0ed862efc8dd8b2ae93d46a5390d3497f77d65fc 100644 (file)
@@ -61,8 +61,6 @@ enum guessed_compiler {
 // Allow caching even if -fmodules is used.
 #define SLOPPY_MODULES (1U << 9)
 
-extern time_t time_of_compilation;
-
 void block_signals();
 void unblock_signals();
 bool cc_process_args(Context& ctx,
index 9afb079fc61428c8c875ddbfc1733f0f9541e665..db97e16d52a45457a1b54efc9fef56633329970b 100644 (file)
 
 #include "legacy_globals.hpp"
 
-// Time of compilation. Used to see if include files have changed after
-// compilation.
-time_t time_of_compilation;
-
 // Files included by the preprocessor and their hashes. Key: file path. Value:
 // struct digest.
 std::unordered_map<std::string, digest> g_included_files;
index b01b6f4450df85dfc2c84a1584f6f6d191a228ce..707cd62249271e1fa00f2e12de9647e55093a11b 100644 (file)
@@ -30,8 +30,6 @@
 
 extern unsigned lock_staleness_limit;
 
-extern time_t time_of_compilation;
-
 extern std::unordered_map<std::string, digest> g_included_files;
 
 extern bool has_absolute_include_headers;
index 965b4f05518ce08587dc65c2f35955295d8aa64d..b1adf0e8f41204b0703ad631df9da24e2de59475 100644 (file)
@@ -178,6 +178,7 @@ struct ManifestData
   add_result_entry(
     const struct digest& result_digest,
     const std::unordered_map<std::string, digest>& included_files,
+    time_t time_of_compilation,
     bool save_timestamp)
   {
     std::unordered_map<std::string, uint32_t /*index*/> mf_files;
@@ -192,8 +193,12 @@ struct ManifestData
 
     std::vector<uint32_t> file_info_indexes;
     for (const auto& item : included_files) {
-      file_info_indexes.push_back(get_file_info_index(
-        item.first, item.second, mf_files, mf_file_infos, save_timestamp));
+      file_info_indexes.push_back(get_file_info_index(item.first,
+                                                      item.second,
+                                                      mf_files,
+                                                      mf_file_infos,
+                                                      time_of_compilation,
+                                                      save_timestamp));
     }
 
     results.push_back(ResultEntry{std::move(file_info_indexes), result_digest});
@@ -206,6 +211,7 @@ private:
     const digest& digest,
     const std::unordered_map<std::string, uint32_t>& mf_files,
     const std::unordered_map<FileInfo, uint32_t>& mf_file_infos,
+    time_t time_of_compilation,
     bool save_timestamp)
   {
     struct FileInfo fi;
@@ -509,6 +515,8 @@ manifest_put(const Config& config,
              const std::string& path,
              const struct digest& result_name,
              const std::unordered_map<std::string, digest>& included_files,
+
+             time_t time_of_compilation,
              bool save_timestamp)
 {
   // We don't bother to acquire a lock when writing the manifest to disk. A
@@ -551,7 +559,8 @@ manifest_put(const Config& config,
     mf = std::make_unique<ManifestData>();
   }
 
-  mf->add_result_entry(result_name, included_files, save_timestamp);
+  mf->add_result_entry(
+    result_name, included_files, time_of_compilation, save_timestamp);
 
   try {
     write_manifest(config, path, *mf);
index 1a574d54f810e2928beb615be4eb2f01aaa5631a..85d88dad2452b5054ba87ae90d0514fc804f79ea 100644 (file)
@@ -35,5 +35,6 @@ bool manifest_put(const Config& config,
                   const std::string& path,
                   const struct digest& result_name,
                   const std::unordered_map<std::string, digest>& included_files,
+                  time_t time_of_compilation,
                   bool save_timestamp);
 bool manifest_dump(const std::string& path, FILE* stream);