From: Thomas Otto Date: Sun, 26 Jan 2020 20:16:58 +0000 (+0100) Subject: Context: move included_pch_file and convert to std::string X-Git-Tag: v4.0~613^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d7c9ec7543eb0deed2c45afdecc9b07b8344cf9;p=thirdparty%2Fccache.git Context: move included_pch_file and convert to std::string --- diff --git a/src/Context.hpp b/src/Context.hpp index 19098a6e8..56358cf2c 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -86,4 +86,7 @@ struct Context : NonCopyable // Compiler guessing is currently only based on the compiler name, so nothing // should hard-depend on it if possible. GuessedCompiler guessed_compiler = GuessedCompiler::unknown; + + // The .gch/.pch/.pth file used for compilation. + std::string included_pch_file; }; diff --git a/src/ccache.cpp b/src/ccache.cpp index e4181f5f8..d93d7cf6c 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -518,7 +518,7 @@ do_remember_include_file(Context& ctx, is_pch = is_precompiled_header(path.c_str()); if (is_pch) { - if (!included_pch_file) { + if (ctx.included_pch_file.empty()) { cc_log("Detected use of precompiled header: %s", path.c_str()); } bool using_pch_sum = false; @@ -868,8 +868,9 @@ process_preprocessed_file(Context& ctx, // Explicitly check the .gch/.pch/.pth file as Clang does not include any // mention of it in the preprocessed output. - if (included_pch_file) { - std::string pch_path = make_relative_path(ctx, included_pch_file); + if (!ctx.included_pch_file.empty()) { + std::string pch_path = + make_relative_path(ctx, ctx.included_pch_file.c_str()); hash_string(hash, pch_path); remember_include_file(ctx, pch_path, hash, false, NULL); } @@ -1006,8 +1007,9 @@ result_name_from_depfile(Context& ctx, struct hash* hash) // Explicitly check the .gch/.pch/.pth file as it may not be mentioned in the // dependencies output. - if (included_pch_file) { - std::string pch_path = make_relative_path(ctx, included_pch_file); + if (!ctx.included_pch_file.empty()) { + std::string pch_path = + make_relative_path(ctx, ctx.included_pch_file.c_str()); hash_string(hash, pch_path); remember_include_file(ctx, pch_path, hash, false, NULL); } @@ -2172,7 +2174,7 @@ color_output_possible(void) } static bool -detect_pch(const char* option, const char* arg, bool* found_pch) +detect_pch(Context& ctx, const char* option, const char* arg, bool* found_pch) { // Try to be smart about detecting precompiled headers. char* pch_file = NULL; @@ -2206,14 +2208,14 @@ detect_pch(const char* option, const char* arg, bool* found_pch) } if (pch_file) { - if (included_pch_file) { + if (!ctx.included_pch_file.empty()) { cc_log("Multiple precompiled headers used: %s and %s\n", - included_pch_file, + ctx.included_pch_file.c_str(), pch_file); stats_update(STATS_ARGS); return false; } - included_pch_file = pch_file; + ctx.included_pch_file = pch_file; *found_pch = true; } return true; @@ -2883,7 +2885,7 @@ cc_process_args(Context& ctx, return false; } - if (!detect_pch(argv[i], argv[i + 1], &found_pch)) { + if (!detect_pch(ctx, argv[i], argv[i + 1], &found_pch)) { return false; } @@ -3530,7 +3532,6 @@ free_and_nullify(T*& ptr) void cc_reset() { - free_and_nullify(included_pch_file); for (size_t i = 0; i < ignore_headers_len; i++) { free_and_nullify(ignore_headers[i]); } diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 19375da7f..1bac9882a 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -24,8 +24,5 @@ char** ignore_headers; // Size of headers to ignore list. size_t ignore_headers_len; -// The .gch/.pch/.pth file used for compilation. -char* included_pch_file = nullptr; - // How long (in microseconds) to wait before breaking a stale lock. unsigned lock_staleness_limit = 2000000; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index 5f5e9a350..bb083fc7e 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -33,5 +33,3 @@ extern unsigned lock_staleness_limit; extern char** ignore_headers; extern size_t ignore_headers_len; - -extern char* included_pch_file;