From: Joel Rosdahl Date: Wed, 29 Jul 2020 17:10:23 +0000 (+0200) Subject: C++-ify is_precompiled_header and move to Util X-Git-Tag: v4.0~261 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d1e68b890897689545b3ce1442eebdf8fc821ef0;p=thirdparty%2Fccache.git C++-ify is_precompiled_header and move to Util --- diff --git a/src/Util.cpp b/src/Util.cpp index 6e1d55633..a6db3ccb1 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -696,6 +696,14 @@ is_nfs_fd([[gnu::unused]] int fd, [[gnu::unused]] bool* is_nfs) } #endif +bool +is_precompiled_header(string_view path) +{ + string_view ext = get_extension(path); + return ext == ".gch" || ext == ".pch" || ext == ".pth" + || get_extension(dir_name(path)) == ".gch"; +} + std::string make_relative_path(const Context& ctx, string_view path) { diff --git a/src/Util.hpp b/src/Util.hpp index f48fc96e7..7028caf8a 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -262,6 +262,10 @@ is_dir_separator(char ch) ; } +// Return whether `path` represents a precompiled header (see "Precompiled +// Headers" in GCC docs). +bool is_precompiled_header(nonstd::string_view path); + // Make a relative path from current working directory to `path` if `path` is // under the base directory. std::string make_relative_path(const Context& ctx, nonstd::string_view path); diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 7adbad4cc..981eb31a1 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -992,7 +992,7 @@ process_args(Context& ctx, args_info.output_is_precompiled_header = args_info.actual_language.find("-header") != std::string::npos - || is_precompiled_header(args_info.output_obj.c_str()); + || Util::is_precompiled_header(args_info.output_obj); if (args_info.output_is_precompiled_header && !(config.sloppiness() & SLOPPY_PCH_DEFINES)) { diff --git a/src/ccache.cpp b/src/ccache.cpp index 94c979785..eb2f3f1c3 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -327,7 +327,7 @@ do_remember_include_file(Context& ctx, // Let's hash the include file content. Hash fhash; - is_pch = is_precompiled_header(path.c_str()); + is_pch = Util::is_precompiled_header(path); if (is_pch) { if (ctx.included_pch_file.empty()) { cc_log("Detected use of precompiled header: %s", path.c_str()); @@ -1747,15 +1747,6 @@ find_compiler(Context& ctx, const char* const* argv) ctx.orig_args[0] = compiler; } -bool -is_precompiled_header(const char* path) -{ - // See "Precompiled Headers" in GCC docs. - string_view ext = Util::get_extension(path); - return ext == ".gch" || ext == ".pch" || ext == ".pth" - || Util::get_extension(Util::dir_name(path)) == ".gch"; -} - static void create_initial_config_file(Config& config) { diff --git a/src/ccache.hpp b/src/ccache.hpp index c69db323e..69bd5ffa5 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -62,4 +62,3 @@ enum class GuessedCompiler { clang, gcc, nvcc, pump, unknown }; void block_signals(); void unblock_signals(); -bool is_precompiled_header(const char* path); diff --git a/src/hashutil.cpp b/src/hashutil.cpp index fdf00cfd6..e09a349cb 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -58,7 +58,6 @@ # include #endif - // Returns one of HASH_SOURCE_CODE_FOUND_DATE, HASH_SOURCE_CODE_FOUND_TIME or // HASH_SOURCE_CODE_FOUND_TIMESTAMP if "_DATE__", "_TIME__" or "_TIMESTAMP__" // starts at str[pos]. @@ -292,7 +291,7 @@ hash_source_code_file_nocache(const Context& ctx, static InodeCache::ContentType get_content_type(const Config& config, const char* path) { - if (is_precompiled_header(path)) { + if (Util::is_precompiled_header(path)) { return InodeCache::ContentType::precompiled_header; } if (config.sloppiness() & SLOPPY_TIME_MACROS) { @@ -314,7 +313,7 @@ hash_source_code_file(const Context& ctx, if (!ctx.config.inode_cache()) { #endif return hash_source_code_file_nocache( - ctx, hash, path, size_hint, is_precompiled_header(path)); + ctx, hash, path, size_hint, Util::is_precompiled_header(path)); #ifdef INODE_CACHE_SUPPORTED }