From: Alexander Lanin Date: Tue, 19 Jan 2021 07:38:06 +0000 (+0100) Subject: Extract enums into separate headers (#764) X-Git-Tag: v4.2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3bba66048da99c25373905ddb61886f04f0552c;p=thirdparty%2Fccache.git Extract enums into separate headers (#764) --- diff --git a/src/Config.cpp b/src/Config.cpp index 4866294c7..68dc3f575 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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" diff --git a/src/Context.hpp b/src/Context.hpp index 7af070569..c0211244c 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -23,11 +23,12 @@ #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" diff --git a/src/Counters.cpp b/src/Counters.cpp index 2e1b0e282..1263d9da3 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -18,7 +18,7 @@ #include "Counters.hpp" -#include "Statistics.hpp" +#include "Statistic.hpp" #include "assertions.hpp" #include diff --git a/src/Manifest.cpp b/src/Manifest.cpp index f594ed1d7..38aec0c4d 100644 --- a/src/Manifest.cpp +++ b/src/Manifest.cpp @@ -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" diff --git a/src/Result.cpp b/src/Result.cpp index ef8ac747e..b20aa6228 100644 --- a/src/Result.cpp +++ b/src/Result.cpp @@ -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 index 000000000..bd2078e9a --- /dev/null +++ b/src/Sloppiness.hpp @@ -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 index 000000000..cd6cda629 --- /dev/null +++ b/src/Statistic.hpp @@ -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 +}; diff --git a/src/Statistics.hpp b/src/Statistics.hpp index 61721b462..34a99824c 100644 --- a/src/Statistics.hpp +++ b/src/Statistics.hpp @@ -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" @@ -29,45 +30,6 @@ 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. diff --git a/src/argprocessing.hpp b/src/argprocessing.hpp index 1da89d3f3..a8e8f3aee 100644 --- a/src/argprocessing.hpp +++ b/src/argprocessing.hpp @@ -19,7 +19,7 @@ #pragma once #include "Args.hpp" -#include "Statistics.hpp" +#include "Statistic.hpp" #include "third_party/nonstd/optional.hpp" diff --git a/src/ccache.cpp b/src/ccache.cpp index eabe6846c..048b15caf 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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 exit_code = nonstd::nullopt); + + nonstd::optional exit_code() const; + Statistic statistic() const; + +private: + Statistic m_statistic; + nonstd::optional m_exit_code; +}; + +inline Failure::Failure(Statistic statistic, nonstd::optional exit_code) + : m_statistic(statistic), m_exit_code(exit_code) +{ +} + +inline nonstd::optional +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) { diff --git a/src/ccache.hpp b/src/ccache.hpp index 7f833ee9b..bf34cb0eb 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -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(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 exit_code = nonstd::nullopt); - - nonstd::optional exit_code() const; - Statistic statistic() const; - -private: - Statistic m_statistic; - nonstd::optional m_exit_code; -}; - -inline Failure::Failure(Statistic statistic, nonstd::optional exit_code) - : m_statistic(statistic), m_exit_code(exit_code) -{ -} - -inline nonstd::optional -Failure::exit_code() const -{ - return m_exit_code; -} - -inline Statistic -Failure::statistic() const -{ - return m_statistic; -} diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 072d821d5..90816fa5f 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -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" diff --git a/unittest/test_Config.cpp b/unittest/test_Config.cpp index 46e56a33b..fad4ff424 100644 --- a/unittest/test_Config.cpp +++ b/unittest/test_Config.cpp @@ -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" diff --git a/unittest/test_Counters.cpp b/unittest/test_Counters.cpp index d2382af3d..b4d3be323 100644 --- a/unittest/test_Counters.cpp +++ b/unittest/test_Counters.cpp @@ -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" diff --git a/unittest/test_Statistics.cpp b/unittest/test_Statistics.cpp index 5d6892c81..0e647fb2e 100644 --- a/unittest/test_Statistics.cpp +++ b/unittest/test_Statistics.cpp @@ -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" diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 7e2cbca17..7db1ad3ca 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -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" diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index e6cd6eb7d..cd59588ae 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -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"