]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify is_precompiled_header and move to Util
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 29 Jul 2020 17:10:23 +0000 (19:10 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 29 Jul 2020 17:11:13 +0000 (19:11 +0200)
src/Util.cpp
src/Util.hpp
src/argprocessing.cpp
src/ccache.cpp
src/ccache.hpp
src/hashutil.cpp

index 6e1d55633f9edafa57412b722e4065f9d48c94a8..a6db3ccb10e8fd722346ad3008c44634402389cd 100644 (file)
@@ -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)
 {
index f48fc96e785d985dee3767b9c309da30363e6598..7028caf8a1a4a9df182738ad84e8f1d157293054 100644 (file)
@@ -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);
index 7adbad4cc6e5a981831c1bb86a3520110de7cf93..981eb31a1c8199b21009e3c12bb90feb9354f806 100644 (file)
@@ -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)) {
index 94c979785216a82e70f4ad2ca7c7c2e64c8b324d..eb2f3f1c39b9b1fed0fc84422a29d702b1f93a9a 100644 (file)
@@ -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)
 {
index c69db323eaa8e65d69207f7e83837527d52a201c..69bd5ffa577c321434b4c0bb8d6ce36a91a4abe1 100644 (file)
@@ -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);
index fdf00cfd6ab04fdf7d77571361b8cdf7da0e91f8..e09a349cb9b66e31bb1d2ff48e8b08a39635e107 100644 (file)
@@ -58,7 +58,6 @@
 #  include <immintrin.h>
 #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
   }