]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Extract enums into separate headers (#764)
authorAlexander Lanin <alex@lanin.de>
Tue, 19 Jan 2021 07:38:06 +0000 (08:38 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Jan 2021 07:38:06 +0000 (08:38 +0100)
19 files changed:
src/Config.cpp
src/Context.hpp
src/Counters.cpp
src/Manifest.cpp
src/Result.cpp
src/Sloppiness.hpp [new file with mode: 0644]
src/Statistic.hpp [new file with mode: 0644]
src/Statistics.hpp
src/argprocessing.hpp
src/ccache.cpp
src/ccache.hpp
src/cleanup.cpp
src/exceptions.hpp
src/hashutil.cpp
unittest/test_Config.cpp
unittest/test_Counters.cpp
unittest/test_Statistics.cpp
unittest/test_argprocessing.cpp
unittest/test_ccache.cpp

index 4866294c798d40201f312fda5076d097b5833449..68dc3f5752dffe8d6c50e439cd2005a0c2603c08 100644 (file)
@@ -20,9 +20,9 @@
 
 #include "AtomicFile.hpp"
 #include "Compression.hpp"
+#include "Sloppiness.hpp"
 #include "Util.hpp"
 #include "assertions.hpp"
-#include "ccache.hpp"
 #include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
index 7af070569ef7ec170014c17cf27f5a25b31b28aa..c0211244c36a4ea39305712888837a13e72df6ba 100644 (file)
 #include "Args.hpp"
 #include "ArgsInfo.hpp"
 #include "Config.hpp"
+#include "Counters.hpp"
 #include "Digest.hpp"
 #include "File.hpp"
 #include "MiniTrace.hpp"
 #include "NonCopyable.hpp"
-#include "ccache.hpp"
+#include "Sloppiness.hpp"
 
 #ifdef INODE_CACHE_SUPPORTED
 #  include "InodeCache.hpp"
index 2e1b0e282e6da2c59ba9c91627e6a0af9ba505e4..1263d9da39b2ed719c1f157a80757674a95244f6 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "Counters.hpp"
 
-#include "Statistics.hpp"
+#include "Statistic.hpp"
 #include "assertions.hpp"
 
 #include <algorithm>
index f594ed1d79cf30a5a68a9009e28ac89a544bdaf8..38aec0c4d1d0e3a9cc180e22e824094021b3491c 100644 (file)
@@ -28,8 +28,8 @@
 #include "File.hpp"
 #include "Hash.hpp"
 #include "Logging.hpp"
+#include "Sloppiness.hpp"
 #include "StdMakeUnique.hpp"
-#include "ccache.hpp"
 #include "fmtmacros.hpp"
 #include "hashutil.hpp"
 
index ef8ac747e692e93d900abc286663edc870d8ef56..b20aa6228acb54b6a9ea6c9bab806c1bf678531d 100644 (file)
@@ -27,7 +27,7 @@
 #include "File.hpp"
 #include "Logging.hpp"
 #include "Stat.hpp"
-#include "Statistics.hpp"
+#include "Statistic.hpp"
 #include "Util.hpp"
 #include "exceptions.hpp"
 #include "fmtmacros.hpp"
diff --git a/src/Sloppiness.hpp b/src/Sloppiness.hpp
new file mode 100644 (file)
index 0000000..bd2078e
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright (C) 2021 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#pragma once
+
+enum Sloppiness {
+  SLOPPY_INCLUDE_FILE_MTIME = 1 << 0,
+  SLOPPY_INCLUDE_FILE_CTIME = 1 << 1,
+  SLOPPY_TIME_MACROS = 1 << 2,
+  SLOPPY_PCH_DEFINES = 1 << 3,
+  // Allow us to match files based on their stats (size, mtime, ctime), without
+  // looking at their contents.
+  SLOPPY_FILE_STAT_MATCHES = 1 << 4,
+  // Allow us to not include any system headers in the manifest include files,
+  // similar to -MM versus -M for dependencies.
+  SLOPPY_SYSTEM_HEADERS = 1 << 5,
+  // Allow us to ignore ctimes when comparing file stats, so we can fake mtimes
+  // if we want to (it is much harder to fake ctimes, requires changing clock)
+  SLOPPY_FILE_STAT_MATCHES_CTIME = 1 << 6,
+  // Allow us to not include the -index-store-path option in the manifest hash.
+  SLOPPY_CLANG_INDEX_STORE = 1 << 7,
+  // Ignore locale settings.
+  SLOPPY_LOCALE = 1 << 8,
+  // Allow caching even if -fmodules is used.
+  SLOPPY_MODULES = 1 << 9,
+};
diff --git a/src/Statistic.hpp b/src/Statistic.hpp
new file mode 100644 (file)
index 0000000..cd6cda6
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright (C) 2021 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#pragma once
+
+// Statistics fields in storage order.
+enum class Statistic {
+  none = 0,
+  compiler_produced_stdout = 1,
+  compile_failed = 2,
+  internal_error = 3,
+  cache_miss = 4,
+  preprocessor_error = 5,
+  could_not_find_compiler = 6,
+  missing_cache_file = 7,
+  preprocessed_cache_hit = 8,
+  bad_compiler_arguments = 9,
+  called_for_link = 10,
+  files_in_cache = 11,
+  cache_size_kibibyte = 12,
+  obsolete_max_files = 13,
+  obsolete_max_size = 14,
+  unsupported_source_language = 15,
+  bad_output_file = 16,
+  no_input_file = 17,
+  multiple_source_files = 18,
+  autoconf_test = 19,
+  unsupported_compiler_option = 20,
+  output_to_stdout = 21,
+  direct_cache_hit = 22,
+  compiler_produced_no_output = 23,
+  compiler_produced_empty_output = 24,
+  error_hashing_extra_file = 25,
+  compiler_check_failed = 26,
+  could_not_use_precompiled_header = 27,
+  called_for_preprocessing = 28,
+  cleanups_performed = 29,
+  unsupported_code_directive = 30,
+  stats_zeroed_timestamp = 31,
+  could_not_use_modules = 32,
+
+  END
+};
index 61721b462ccad923068740ae1b46fd142d739b42..34a99824c90cff2766d6a8cea22db30a78a52978 100644 (file)
@@ -21,6 +21,7 @@
 #include "system.hpp"
 
 #include "Counters.hpp"
+#include "Statistic.hpp" // Any reasonable use of Statistics requires the Statistic enum.
 
 #include "third_party/nonstd/optional.hpp"
 
 
 class Config;
 
-// Statistics fields in storage order.
-enum class Statistic {
-  none = 0,
-  compiler_produced_stdout = 1,
-  compile_failed = 2,
-  internal_error = 3,
-  cache_miss = 4,
-  preprocessor_error = 5,
-  could_not_find_compiler = 6,
-  missing_cache_file = 7,
-  preprocessed_cache_hit = 8,
-  bad_compiler_arguments = 9,
-  called_for_link = 10,
-  files_in_cache = 11,
-  cache_size_kibibyte = 12,
-  obsolete_max_files = 13,
-  obsolete_max_size = 14,
-  unsupported_source_language = 15,
-  bad_output_file = 16,
-  no_input_file = 17,
-  multiple_source_files = 18,
-  autoconf_test = 19,
-  unsupported_compiler_option = 20,
-  output_to_stdout = 21,
-  direct_cache_hit = 22,
-  compiler_produced_no_output = 23,
-  compiler_produced_empty_output = 24,
-  error_hashing_extra_file = 25,
-  compiler_check_failed = 26,
-  could_not_use_precompiled_header = 27,
-  called_for_preprocessing = 28,
-  cleanups_performed = 29,
-  unsupported_code_directive = 30,
-  stats_zeroed_timestamp = 31,
-  could_not_use_modules = 32,
-
-  END
-};
-
 namespace Statistics {
 
 // Read counters from `path`. No lock is acquired.
index 1da89d3f379136d70cb84c77e921b6de5b600d72..a8e8f3aee358839c789dc4ed3674f76d6a1b92aa 100644 (file)
@@ -19,7 +19,7 @@
 #pragma once
 
 #include "Args.hpp"
-#include "Statistics.hpp"
+#include "Statistic.hpp"
 
 #include "third_party/nonstd/optional.hpp"
 
index eabe6846c90b639852f8ddfcf89af12c772ad01a..048b15caf69301839dbe8d6da85d9dd7b3302a4e 100644 (file)
@@ -40,6 +40,7 @@
 #include "ResultExtractor.hpp"
 #include "ResultRetriever.hpp"
 #include "SignalHandler.hpp"
+#include "Statistics.hpp"
 #include "StdMakeUnique.hpp"
 #include "TemporaryFile.hpp"
 #include "UmaskScope.hpp"
@@ -181,6 +182,45 @@ const uint8_t k_max_cache_levels = 4;
 // stored in the cache changes in a backwards-incompatible way.
 const char HASH_PREFIX[] = "3";
 
+namespace {
+
+// Throw a Failure if ccache did not succeed in getting or putting a result in
+// the cache. If `exit_code` is set, just exit with that code directly,
+// otherwise execute the real compiler and exit with its exit code. Also updates
+// statistics counter `statistic` if it's not `Statistic::none`.
+class Failure : public std::exception
+{
+public:
+  Failure(Statistic statistic,
+          nonstd::optional<int> exit_code = nonstd::nullopt);
+
+  nonstd::optional<int> exit_code() const;
+  Statistic statistic() const;
+
+private:
+  Statistic m_statistic;
+  nonstd::optional<int> m_exit_code;
+};
+
+inline Failure::Failure(Statistic statistic, nonstd::optional<int> exit_code)
+  : m_statistic(statistic), m_exit_code(exit_code)
+{
+}
+
+inline nonstd::optional<int>
+Failure::exit_code() const
+{
+  return m_exit_code;
+}
+
+inline Statistic
+Failure::statistic() const
+{
+  return m_statistic;
+}
+
+} // namespace
+
 static void
 add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
 {
index 7f833ee9b34ce852491fbf3ae565aea509de6f4f..bf34cb0eb34e80ce34bdfc8ac365f1f5c6936190 100644 (file)
@@ -32,26 +32,6 @@ class Context;
 
 extern const char CCACHE_VERSION[];
 
-const uint32_t SLOPPY_INCLUDE_FILE_MTIME = 1 << 0;
-const uint32_t SLOPPY_INCLUDE_FILE_CTIME = 1 << 1;
-const uint32_t SLOPPY_TIME_MACROS = 1 << 2;
-const uint32_t SLOPPY_PCH_DEFINES = 1 << 3;
-// Allow us to match files based on their stats (size, mtime, ctime), without
-// looking at their contents.
-const uint32_t SLOPPY_FILE_STAT_MATCHES = 1 << 4;
-// Allow us to not include any system headers in the manifest include files,
-// similar to -MM versus -M for dependencies.
-const uint32_t SLOPPY_SYSTEM_HEADERS = 1 << 5;
-// Allow us to ignore ctimes when comparing file stats, so we can fake mtimes
-// if we want to (it is much harder to fake ctimes, requires changing clock)
-const uint32_t SLOPPY_FILE_STAT_MATCHES_CTIME = 1 << 6;
-// Allow us to not include the -index-store-path option in the manifest hash.
-const uint32_t SLOPPY_CLANG_INDEX_STORE = 1 << 7;
-// Ignore locale settings.
-const uint32_t SLOPPY_LOCALE = 1 << 8;
-// Allow caching even if -fmodules is used.
-const uint32_t SLOPPY_MODULES = 1 << 9;
-
 using FindExecutableFunction =
   std::function<std::string(const Context& ctx,
                             const std::string& name,
index 6d91d777dc7269d1842a79a895f3100cb889d6c7..a3ee774ee46b305b39294ee4b91381d7f312387a 100644 (file)
@@ -23,6 +23,7 @@
 #include "Config.hpp"
 #include "Context.hpp"
 #include "Logging.hpp"
+#include "Statistics.hpp"
 #include "Util.hpp"
 
 #ifdef INODE_CACHE_SUPPORTED
index 1c731414bc97dce4831202a46efc6d69e9e8f795..f35f50c4dcfc0bc8c00eff46273938226c50c1e4 100644 (file)
@@ -21,7 +21,6 @@
 #include "system.hpp"
 
 #include "FormatNonstdStringView.hpp"
-#include "Statistics.hpp"
 
 #include "third_party/fmt/core.h"
 #include "third_party/nonstd/optional.hpp"
@@ -80,38 +79,3 @@ inline Fatal::Fatal(T&&... args)
   : ErrorBase(fmt::format(std::forward<T>(args)...))
 {
 }
-
-// Throw a Failure if ccache did not succeed in getting or putting a result in
-// the cache. If `exit_code` is set, just exit with that code directly,
-// otherwise execute the real compiler and exit with its exit code. Also updates
-// statistics counter `statistic` if it's not `Statistic::none`.
-class Failure : public std::exception
-{
-public:
-  Failure(Statistic statistic,
-          nonstd::optional<int> exit_code = nonstd::nullopt);
-
-  nonstd::optional<int> exit_code() const;
-  Statistic statistic() const;
-
-private:
-  Statistic m_statistic;
-  nonstd::optional<int> m_exit_code;
-};
-
-inline Failure::Failure(Statistic statistic, nonstd::optional<int> exit_code)
-  : m_statistic(statistic), m_exit_code(exit_code)
-{
-}
-
-inline nonstd::optional<int>
-Failure::exit_code() const
-{
-  return m_exit_code;
-}
-
-inline Statistic
-Failure::statistic() const
-{
-  return m_statistic;
-}
index 072d821d50b144bd0f3d45bbc0decddb3a08ad44..90816fa5f604c2faa93f123d757eb2812c3eea93 100644 (file)
@@ -23,8 +23,8 @@
 #include "Context.hpp"
 #include "Hash.hpp"
 #include "Logging.hpp"
+#include "Sloppiness.hpp"
 #include "Stat.hpp"
-#include "ccache.hpp"
 #include "execute.hpp"
 #include "fmtmacros.hpp"
 #include "macroskip.hpp"
index 46e56a33b601c1f6a0ec05b5602955a5dcd6cd5e..fad4ff424be73331d7ed5e248888877926baf290 100644 (file)
@@ -17,8 +17,8 @@
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include "../src/Config.hpp"
+#include "../src/Sloppiness.hpp"
 #include "../src/Util.hpp"
-#include "../src/ccache.hpp"
 #include "../src/exceptions.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
index d2382af3d1a1d294bc06cdb9fb760ebf16e41be0..b4d3be3239964150e94384ff4fa62ed4b46f7a99 100644 (file)
@@ -17,7 +17,7 @@
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include "../src/Counters.hpp"
-#include "../src/Statistics.hpp"
+#include "../src/Statistic.hpp"
 #include "TestUtil.hpp"
 
 #include "third_party/doctest.h"
index 5d6892c8175cdd0f769b8451b70e51eb807f7986..0e647fb2e43818eefaf8555df5d1a482bfb34f00 100644 (file)
@@ -16,6 +16,7 @@
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+#include "../src/Statistic.hpp"
 #include "../src/Statistics.hpp"
 #include "../src/Util.hpp"
 #include "../src/fmtmacros.hpp"
index 7e2cbca17fa934d0e94294c8f16e33864870b907..7db1ad3ca29be6b96fd3312d7489c7aeec0d97f1 100644 (file)
@@ -19,7 +19,7 @@
 #include "../src/Args.hpp"
 #include "../src/Config.hpp"
 #include "../src/Context.hpp"
-#include "../src/Statistics.hpp"
+#include "../src/Statistic.hpp"
 #include "../src/Util.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
index e6cd6eb7dc28db4e9d9b63e3a78b16a0d8783229..cd59588ae82e8ac2ea091ad74dfbd3b644b87034 100644 (file)
@@ -17,6 +17,7 @@
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include "../src/Context.hpp"
+#include "../src/Sloppiness.hpp"
 #include "../src/ccache.hpp"
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"