From f51751706af49f77d0387e0ae807ff7cd14386ca Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Sat, 25 Jan 2020 10:49:49 +0100 Subject: [PATCH] Context: move time_of_compilation, adapt manifest --- src/Context.hpp | 4 ++++ src/ccache.cpp | 10 +++++----- src/ccache.hpp | 2 -- src/legacy_globals.cpp | 4 ---- src/legacy_globals.hpp | 2 -- src/manifest.cpp | 15 ++++++++++++--- src/manifest.hpp | 1 + 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Context.hpp b/src/Context.hpp index 617a09a7c..9335e80ab 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -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; }; diff --git a/src/ccache.cpp b/src/ccache.cpp index c9c015a19..ed8ba7440 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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]); } diff --git a/src/ccache.hpp b/src/ccache.hpp index 990ec7098..0ed862efc 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -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, diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 9afb079fc..db97e16d5 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -18,10 +18,6 @@ #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 g_included_files; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index b01b6f445..707cd6224 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -30,8 +30,6 @@ extern unsigned lock_staleness_limit; -extern time_t time_of_compilation; - extern std::unordered_map g_included_files; extern bool has_absolute_include_headers; diff --git a/src/manifest.cpp b/src/manifest.cpp index 965b4f055..b1adf0e8f 100644 --- a/src/manifest.cpp +++ b/src/manifest.cpp @@ -178,6 +178,7 @@ struct ManifestData add_result_entry( const struct digest& result_digest, const std::unordered_map& included_files, + time_t time_of_compilation, bool save_timestamp) { std::unordered_map mf_files; @@ -192,8 +193,12 @@ struct ManifestData std::vector 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& mf_files, const std::unordered_map& 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& 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(); } - 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); diff --git a/src/manifest.hpp b/src/manifest.hpp index 1a574d54f..85d88dad2 100644 --- a/src/manifest.hpp +++ b/src/manifest.hpp @@ -35,5 +35,6 @@ bool manifest_put(const Config& config, const std::string& path, const struct digest& result_name, const std::unordered_map& included_files, + time_t time_of_compilation, bool save_timestamp); bool manifest_dump(const std::string& path, FILE* stream); -- 2.47.2