]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Remove time_of_compilation in favor of time_of_invocation
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 9 Jan 2024 20:28:34 +0000 (21:28 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 14 Jan 2024 21:10:38 +0000 (22:10 +0100)
We can compare source/include files against time of invocation just as
well; source files shouldn't be modified when ccache has started anyway.

(cherry picked from commit b982306349e5ba3229d1ea9c14ff4ce2efb18233)

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

index fcf3a1343fab8ce89458d785ea43a655092593d3..47f9407e0b6305d55fabcdd42c9269ebca8fe7fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 Context::Context()
   : actual_cwd(util::actual_cwd()),
     apparent_cwd(util::apparent_cwd(actual_cwd)),
-    storage(config)
+    storage(config),
 #ifdef INODE_CACHE_SUPPORTED
-    ,
-    inode_cache(config)
+    inode_cache(config),
 #endif
+    time_of_invocation(util::TimePoint::now())
 {
-  time_of_invocation = util::TimePoint::now();
 }
 
 void
index 51b4787b878c0a1a5bf9a023aef09f081ef59b10..e06da471af8184d7563e6f4ba0ed186d7c4c0346 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -67,13 +67,6 @@ public:
   // The original argument list.
   Args orig_args;
 
-  // Time of ccache invocation.
-  util::TimePoint time_of_invocation;
-
-  // Time of compilation. Used to see if include files have changed after
-  // compilation.
-  util::TimePoint time_of_compilation;
-
   // Files included by the preprocessor and their hashes.
   std::unordered_map<std::string, Hash::Digest> included_files;
 
@@ -100,6 +93,9 @@ public:
   mutable InodeCache inode_cache;
 #endif
 
+  // Time of ccache invocation.
+  util::TimePoint time_of_invocation;
+
   // PID of currently executing compiler that we have started, if any. 0 means
   // no ongoing compilation.
   pid_t compiler_pid = 0;
index 9647d3eda21332f72499aa0fda7bc4c7c76c5fa3..43eb92b4a891589ba96d395fdf1dc9d2ccc6ff0f 100644 (file)
@@ -313,14 +313,14 @@ include_file_too_new(const Context& ctx,
   // starting compilation and writing the include file. See also the notes under
   // "Performance" in doc/MANUAL.adoc.
   if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_mtime))
-      && dir_entry.mtime() >= ctx.time_of_compilation) {
+      && dir_entry.mtime() >= ctx.time_of_invocation) {
     LOG("Include file {} too new", path);
     return true;
   }
 
   // The same >= logic as above applies to the change time of the file.
   if (!(ctx.config.sloppiness().contains(core::Sloppy::include_file_ctime))
-      && dir_entry.ctime() >= ctx.time_of_compilation) {
+      && dir_entry.ctime() >= ctx.time_of_invocation) {
     LOG("Include file {} ctime too new", path);
     return true;
   }
@@ -872,7 +872,7 @@ update_manifest(Context& ctx,
 
   MTR_SCOPE("manifest", "manifest_put");
 
-  // ctime() may be 0, so we have to check time_of_compilation against
+  // ctime() may be 0, so we have to check time_of_invocation against
   // MAX(mtime, ctime).
   //
   // ccache only reads mtime/ctime if file_stat_matches sloppiness is enabled,
@@ -887,7 +887,7 @@ update_manifest(Context& ctx,
       DirEntry de(path, DirEntry::LogOnError::yes);
       bool cache_time =
         save_timestamp
-        && ctx.time_of_compilation > std::max(de.mtime(), de.ctime());
+        && ctx.time_of_invocation > std::max(de.mtime(), de.ctime());
       return core::Manifest::FileStats{
         de.size(),
         de.is_regular_file() && cache_time ? de.mtime() : util::TimePoint(),
@@ -1139,7 +1139,6 @@ to_cache(Context& ctx,
     depend_mode_args.insert(1, depend_extra_args);
     add_prefix(ctx, depend_mode_args, ctx.config.prefix_command());
 
-    ctx.time_of_compilation = util::TimePoint::now();
     result = do_execute(ctx, depend_mode_args);
   }
   MTR_END("execute", "compiler");
@@ -1239,8 +1238,6 @@ to_cache(Context& ctx,
 static tl::expected<Hash::Digest, Failure>
 get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash)
 {
-  ctx.time_of_compilation = util::TimePoint::now();
-
   std::string preprocessed_path;
   util::Bytes cpp_stderr_data;