]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Build InodeCache.cpp only when inode cache is supported
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 19 Jun 2020 18:52:51 +0000 (20:52 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 23 Jun 2020 19:44:45 +0000 (21:44 +0200)
CMakeLists.txt
src/CMakeLists.txt
src/Context.hpp
src/InodeCache.cpp
src/InodeCache.hpp
src/cleanup.cpp
src/hashutil.cpp
unittest/CMakeLists.txt
unittest/test_InodeCache.cpp

index 09946819bca5265e9de79f8965764ea0b7d86212..2a4ad08afb28281cd19b6f15f5753a6a9270a8cb 100644 (file)
@@ -30,6 +30,10 @@ include(GNUInstallDirs)
 include(GenerateConfigurationFile)
 include(GenerateVersionFile)
 
+if(HAVE_SYS_MMAN_H)
+  set(INODE_CACHE_SUPPORTED 1)
+endif()
+
 #
 # Third party
 #
index 61522b78565843a7f9bf59bb5f6054b73ccc88c7..207513c1a5c041a96d96ba92b2ae1911869451b5 100644 (file)
@@ -11,7 +11,6 @@ set(
   Context.cpp
   Counters.cpp
   Decompressor.cpp
-  InodeCache.cpp
   Lockfile.cpp
   MiniTrace.cpp
   NullCompressor.cpp
@@ -39,6 +38,10 @@ set(
   stats.cpp
   Version.cpp)
 
+if(INODE_CACHE_SUPPORTED)
+  list(APPEND source_files InodeCache.cpp)
+endif()
+
 if(WIN32)
   list(APPEND source_files win32compat.cpp)
 endif()
index 385daedee03218c37872eeadf47fb6220c808efb..9e8937376222d01ef1bab481508196677f3a2c3d 100644 (file)
 #include "ArgsInfo.hpp"
 #include "Config.hpp"
 #include "File.hpp"
-#include "InodeCache.hpp"
 #include "MiniTrace.hpp"
 #include "NonCopyable.hpp"
 #include "ccache.hpp"
 #include "hash.hpp"
 
+#ifdef INODE_CACHE_SUPPORTED
+#  include "InodeCache.hpp"
+#endif
+
 #include "third_party/nonstd/optional.hpp"
 #include "third_party/nonstd/string_view.hpp"
 
index e73c35b460cd93523d4b6fd5eeb84222cff6e7ac..64cba57756a16cf76c51fdcf4617bf3bbfb79511 100644 (file)
 
 #include "InodeCache.hpp"
 
-#ifdef INODE_CACHE_SUPPORTED
-
-#  include "Config.hpp"
-#  include "Fd.hpp"
-#  include "Finalizer.hpp"
-#  include "Stat.hpp"
-#  include "Util.hpp"
-#  include "ccache.hpp"
-#  include "hash.hpp"
-#  include "logging.hpp"
-
-#  include <atomic>
-#  include <libgen.h>
-#  include <sys/mman.h>
-#  include <type_traits>
+#include "Config.hpp"
+#include "Fd.hpp"
+#include "Finalizer.hpp"
+#include "Stat.hpp"
+#include "Util.hpp"
+#include "ccache.hpp"
+#include "hash.hpp"
+#include "logging.hpp"
+
+#include <atomic>
+#include <libgen.h>
+#include <sys/mman.h>
+#include <type_traits>
 
 // The inode cache resides on a file that is mapped into shared memory by
 // running processes. It is implemented as a two level structure, where the top
@@ -87,16 +85,16 @@ struct InodeCache::Key
   dev_t st_dev;
   ino_t st_ino;
   mode_t st_mode;
-#  ifdef HAVE_STRUCT_STAT_ST_MTIM
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
   timespec st_mtim;
-#  else
+#else
   time_t st_mtim;
-#  endif
-#  ifdef HAVE_STRUCT_STAT_ST_CTIM
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_CTIM
   timespec st_ctim; // Included for sanity checking.
-#  else
+#else
   time_t st_ctim; // Included for sanity checking.
-#  endif
+#endif
   off_t st_size; // Included for sanity checking.
   bool sloppy_time_macros;
 };
@@ -185,16 +183,16 @@ InodeCache::hash_inode(const char* path, ContentType type, Digest& digest)
   key.st_dev = stat.device();
   key.st_ino = stat.inode();
   key.st_mode = stat.mode();
-#  ifdef HAVE_STRUCT_STAT_ST_MTIM
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
   key.st_mtim = stat.mtim();
-#  else
+#else
   key.st_mtim = stat.mtime();
-#  endif
-#  ifdef HAVE_STRUCT_STAT_ST_CTIM
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_CTIM
   key.st_ctim = stat.ctim();
-#  else
+#else
   key.st_ctim = stat.ctime();
-#  endif
+#endif
   key.st_size = stat.size();
 
   digest = hash_buffer_once(&key, sizeof(Key));
@@ -206,7 +204,7 @@ InodeCache::acquire_bucket(uint32_t index)
 {
   Bucket* bucket = &m_sr->buckets[index];
   int err = pthread_mutex_lock(&bucket->mt);
-#  ifdef PTHREAD_MUTEX_ROBUST
+#ifdef PTHREAD_MUTEX_ROBUST
   if (err == EOWNERDEAD) {
     if (m_config.debug()) {
       ++m_sr->errors;
@@ -221,16 +219,16 @@ InodeCache::acquire_bucket(uint32_t index)
     cc_log("Wiping bucket at index %u because of stale mutex", index);
     memset(bucket->entries, 0, sizeof(Bucket::entries));
   } else {
-#  endif
+#endif
     if (err) {
       cc_log("Failed to lock mutex at index %u: %s", index, strerror(err));
       cc_log("Consider removing the inode cache file if problem persists");
       ++m_sr->errors;
       return nullptr;
     }
-#  ifdef PTHREAD_MUTEX_ROBUST
+#ifdef PTHREAD_MUTEX_ROBUST
   }
-#  endif
+#endif
   return bucket;
 }
 
@@ -291,9 +289,9 @@ InodeCache::create_new_file(const std::string& filename)
   pthread_mutexattr_t mattr;
   pthread_mutexattr_init(&mattr);
   pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
-#  ifdef PTHREAD_MUTEX_ROBUST
+#ifdef PTHREAD_MUTEX_ROBUST
   pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST);
-#  endif
+#endif
   for (auto& bucket : sr->buckets) {
     pthread_mutex_init(&bucket.mt, &mattr);
   }
@@ -487,5 +485,3 @@ InodeCache::get_errors()
 {
   return initialize() ? m_sr->errors.load() : -1;
 }
-
-#endif
index a538940ed97b06eeca28dae557c49e287efc169d..1c0fdf06f39a43e232ecbabe0e83808c60431b5d 100644 (file)
 
 #include "config.h"
 
-#ifdef INODE_CACHE_SUPPORTED
-
-#  include <stdint.h>
-#  include <string>
+#include <stdint.h>
+#include <string>
 
 class Config;
 class Context;
@@ -110,4 +108,3 @@ private:
   struct SharedRegion* m_sr = nullptr;
   bool m_failed = false;
 };
-#endif
index e2a720a33b610e40d1aaf323f17f97a4490ad950..8423301d563258b6dbe85553ab12d8a93e40beb0 100644 (file)
 #include "CacheFile.hpp"
 #include "Config.hpp"
 #include "Context.hpp"
-#include "InodeCache.hpp"
 #include "Util.hpp"
 #include "logging.hpp"
 #include "stats.hpp"
 
+#ifdef INODE_CACHE_SUPPORTED
+#  include "InodeCache.hpp"
+#endif
+
 #include <algorithm>
 #include <cmath>
 
index 777c1e8efecdf498d669da332fb074d01598f8ec..90bfe3ba54c271736ec1dbf09c2a1477e00f17e6 100644 (file)
@@ -21,7 +21,6 @@
 #include "Args.hpp"
 #include "Config.hpp"
 #include "Context.hpp"
-#include "InodeCache.hpp"
 #include "Stat.hpp"
 #include "ccache.hpp"
 #include "execute.hpp"
 #include "macroskip.hpp"
 #include "stats.hpp"
 
+#ifdef INODE_CACHE_SUPPORTED
+#  include "InodeCache.hpp"
+#endif
+
 #include "third_party/xxhash.h"
 
 // With older GCC (libgcc), __builtin_cpu_supports("avx2) returns true if AVX2
index 7e34081658935ef77f890f12097fdccf82ed39e2..6e6cfc4b1e2842e3534755a052fe72322bfe3f73 100644 (file)
@@ -1,5 +1,5 @@
-add_executable(
-  unittest
+set(
+  source_files
   TestUtil.cpp
   catch2_tests.cpp
   main.cpp
@@ -9,7 +9,6 @@ add_executable(
   test_Compression.cpp
   test_Config.cpp
   test_FormatNonstdStringView.cpp
-  test_InodeCache.cpp
   test_Lockfile.cpp
   test_NullCompression.cpp
   test_Stat.cpp
@@ -21,6 +20,12 @@ add_executable(
   test_hashutil.cpp
   test_legacy_util.cpp)
 
+if(INODE_CACHE_SUPPORTED)
+  list(APPEND source_files test_InodeCache.cpp)
+endif()
+
+add_executable(unittest ${source_files})
+
 target_link_libraries(
   unittest
   PRIVATE standard_settings standard_warnings ccache_lib)
index f2396116c762c12ecd59f75345e8221fdf8ab1c8..ae417055fc93fcf80838178ff1a6409be2e853d0 100644 (file)
@@ -25,8 +25,6 @@
 
 #include "third_party/catch.hpp"
 
-#ifdef INODE_CACHE_SUPPORTED
-
 using TestUtil::TestContext;
 
 namespace {
@@ -203,5 +201,3 @@ TEST_CASE("Test content type")
   CHECK(digest == code_with_sloppy_time_macros_digest);
   CHECK(return_value == 3);
 }
-
-#endif