]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Store mtime/ctime as -1 if sloppy_file_stat is not set (#495)
authorMizuhaHimuraki <mocha.java.cchip@gmail.com>
Mon, 2 Dec 2019 20:54:22 +0000 (04:54 +0800)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 2 Dec 2019 21:26:29 +0000 (22:26 +0100)
As discussed in #493.

(cherry picked from commit 6341a2abd47eb43123ce9fc92716d9768300795e)

src/ccache.cpp
src/manifest.cpp
src/manifest.hpp

index 81f738113da5b5b9ee876d36dbd891b64d341f61..3cda1e4d6ac84dbe2f042a5f744ecbface2838f1 100644 (file)
@@ -1218,9 +1218,13 @@ update_manifest_file(void)
 
   auto old_st = Stat::stat(manifest_path);
 
+  bool save_timestamp = (g_config.sloppiness() & SLOPPY_FILE_STAT_MATCHES)
+                        || output_is_precompiled_header;
+
   MTR_BEGIN("manifest", "manifest_put");
   cc_log("Adding result name to %s", manifest_path);
-  if (!manifest_put(manifest_path, *cached_result_name, g_included_files)) {
+  if (!manifest_put(
+        manifest_path, *cached_result_name, g_included_files, save_timestamp)) {
     cc_log("Failed to add result name to %s", manifest_path);
   } else {
     auto st = Stat::stat(manifest_path, Stat::OnError::log);
index 1c88cb73919510f58324ddbf26cb6c215a531a93..e634d8615eb81ef6128221edb0711f9257cfca1e 100644 (file)
@@ -173,7 +173,8 @@ struct ManifestData
   void
   add_result_entry(
     const struct digest& result_digest,
-    const std::unordered_map<std::string, digest>& included_files)
+    const std::unordered_map<std::string, digest>& included_files,
+    bool save_timestamp)
   {
     std::unordered_map<std::string, uint32_t /*index*/> mf_files;
     for (uint32_t i = 0; i < files.size(); ++i) {
@@ -187,8 +188,8 @@ 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));
+      file_info_indexes.push_back(get_file_info_index(
+        item.first, item.second, mf_files, mf_file_infos, save_timestamp));
     }
 
     results.push_back(ResultEntry{std::move(file_info_indexes), result_digest});
@@ -200,7 +201,8 @@ private:
     const std::string& path,
     const digest& digest,
     const std::unordered_map<std::string, uint32_t>& mf_files,
-    const std::unordered_map<FileInfo, uint32_t>& mf_file_infos)
+    const std::unordered_map<FileInfo, uint32_t>& mf_file_infos,
+    bool save_timestamp)
   {
     struct FileInfo fi;
 
@@ -220,11 +222,17 @@ private:
     //
     // file_stat.ctime() may be 0, so we have to check time_of_compilation
     // against MAX(mtime, ctime).
+    //
+    // ccache only reads mtime/ctime if sloppy_file_stat_match is setted,
+    // so mtimes/ctimes could store as a dummy value (-1) in other scenarios.
+    // This will effectively control the total number of file infos in
+    // certain scenarios, such as CI.
 
     auto file_stat = Stat::stat(path, Stat::OnError::log);
     if (file_stat) {
-      if (time_of_compilation
-          > std::max(file_stat.mtime(), file_stat.ctime())) {
+      if (save_timestamp
+          && time_of_compilation
+               > std::max(file_stat.mtime(), file_stat.ctime())) {
         fi.mtime = file_stat.mtime();
         fi.ctime = file_stat.ctime();
       } else {
@@ -494,7 +502,8 @@ manifest_get(const Config& config, const std::string& path)
 bool
 manifest_put(const std::string& path,
              const struct digest& result_name,
-             const std::unordered_map<std::string, digest>& included_files)
+             const std::unordered_map<std::string, digest>& included_files,
+             bool save_timestamp)
 {
   // We don't bother to acquire a lock when writing the manifest to disk. A
   // race between two processes will only result in one lost entry, which is
@@ -536,7 +545,7 @@ manifest_put(const std::string& path,
     mf = std::make_unique<ManifestData>();
   }
 
-  mf->add_result_entry(result_name, included_files);
+  mf->add_result_entry(result_name, included_files, save_timestamp);
 
   try {
     write_manifest(path, *mf);
index 9822c45e1614e1f46d5266508e31e1b17e9129f6..62c3f3975d770a73aea890b6028884e35a3af1fe 100644 (file)
@@ -30,8 +30,8 @@ extern const uint8_t k_manifest_magic[4];
 extern const uint8_t k_manifest_version;
 
 struct digest* manifest_get(const Config& config, const std::string& path);
-bool
-manifest_put(const std::string& path,
-             const struct digest& result_name,
-             const std::unordered_map<std::string, digest>& included_files);
+bool manifest_put(const std::string& path,
+                  const struct digest& result_name,
+                  const std::unordered_map<std::string, digest>& included_files,
+                  bool save_timestamp);
 bool manifest_dump(const std::string& path, FILE* stream);