]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert guessed_compiler into an enum class
authorThomas Otto <thomas.otto@pdv-fs.de>
Sun, 26 Jan 2020 20:09:14 +0000 (21:09 +0100)
committerThomas Otto <thomas.otto@pdv-fs.de>
Mon, 17 Feb 2020 21:06:17 +0000 (22:06 +0100)
src/ccache.cpp
src/ccache.hpp
src/legacy_globals.cpp
src/legacy_globals.hpp
src/manifest.cpp

index 6b1631eceb99ad7f2c869f358c43bda535561ac8..d4912479ab2f43500c32cc57715bf98126c9b650 100644 (file)
@@ -399,19 +399,19 @@ init_hash_debug(const Context& ctx,
   free(path);
 }
 
-static enum guessed_compiler
+static GuessedCompiler
 guess_compiler(const char* path)
 {
   string_view name = Util::base_name(path);
-  enum guessed_compiler result = GUESSED_UNKNOWN;
+  GuessedCompiler result = GuessedCompiler::unknown;
   if (name == "clang") {
-    result = GUESSED_CLANG;
+    result = GuessedCompiler::clang;
   } else if (name == "gcc" || name == "g++") {
-    result = GUESSED_GCC;
+    result = GuessedCompiler::gcc;
   } else if (name == "nvcc") {
-    result = GUESSED_NVCC;
+    result = GuessedCompiler::nvcc;
   } else if (name == "pump" || name == "distcc-pump") {
-    result = GUESSED_PUMP;
+    result = GuessedCompiler::pump;
   }
   return result;
 }
@@ -1211,7 +1211,7 @@ to_cache(Context& ctx,
 
   // distcc-pump outputs lines like this:
   // __________Using # distcc servers in pump mode
-  if (st.size() != 0 && guessed_compiler != GUESSED_PUMP) {
+  if (st.size() != 0 && guessed_compiler != GuessedCompiler::pump) {
     cc_log("Compiler produced stdout");
     stats_update(STATS_STDOUT);
     tmp_unlink(tmp_stdout);
@@ -1443,7 +1443,7 @@ get_result_name_from_cpp(Context& ctx, struct args* args, struct hash* hash)
 
   hash_delimiter(hash, "cpp");
   if (!process_preprocessed_file(
-        ctx, hash, path_stdout, guessed_compiler == GUESSED_PUMP)) {
+        ctx, hash, path_stdout, guessed_compiler == GuessedCompiler::pump)) {
     stats_update(STATS_ERROR);
     failed();
   }
@@ -1701,7 +1701,7 @@ hash_common_info(Context& ctx,
   }
 
   // Possibly hash GCC_COLORS (for color diagnostics).
-  if (guessed_compiler == GUESSED_GCC) {
+  if (guessed_compiler == GuessedCompiler::gcc) {
     const char* gcc_colors = getenv("GCC_COLORS");
     if (gcc_colors) {
       hash_delimiter(hash, "gcccolors");
@@ -1732,8 +1732,8 @@ calculate_result_name(Context& ctx,
 
   // clang will emit warnings for unused linker flags, so we shouldn't skip
   // those arguments.
-  int is_clang =
-    guessed_compiler == GUESSED_CLANG || guessed_compiler == GUESSED_UNKNOWN;
+  int is_clang = guessed_compiler == GuessedCompiler::clang
+                 || guessed_compiler == GuessedCompiler::unknown;
 
   // First the arguments.
   for (int i = 1; i < args->argc; i++) {
@@ -2037,7 +2037,8 @@ from_cache(Context& ctx,
   //
   //     file 'foo.h' has been modified since the precompiled header 'foo.pch'
   //     was built
-  if ((guessed_compiler == GUESSED_CLANG || guessed_compiler == GUESSED_UNKNOWN)
+  if ((guessed_compiler == GuessedCompiler::clang
+       || guessed_compiler == GuessedCompiler::unknown)
       && ctx.args_info.output_is_precompiled_header
       && mode == FROMCACHE_CPP_MODE) {
     cc_log("Not considering cached precompiled header in preprocessor mode");
@@ -2342,7 +2343,7 @@ cc_process_args(Context& ctx,
     }
 
     // Handle cuda "-optf" and "--options-file" argument.
-    if (guessed_compiler == GUESSED_NVCC
+    if (guessed_compiler == GuessedCompiler::nvcc
         && (str_eq(argv[i], "-optf") || str_eq(argv[i], "--options-file"))) {
       if (i == argc - 1) {
         cc_log("Expected argument after %s", argv[i]);
@@ -2476,7 +2477,7 @@ cc_process_args(Context& ctx,
 
     // when using nvcc with separable compilation, -dc implies -c
     if ((str_eq(argv[i], "-dc") || str_eq(argv[i], "--device-c"))
-        && guessed_compiler == GUESSED_NVCC) {
+        && guessed_compiler == GuessedCompiler::nvcc) {
       found_dc_opt = true;
       continue;
     }
@@ -2522,7 +2523,8 @@ cc_process_args(Context& ctx,
     }
 
     // Alternate form of -o with no space. Nvcc does not support this.
-    if (str_startswith(argv[i], "-o") && guessed_compiler != GUESSED_NVCC) {
+    if (str_startswith(argv[i], "-o")
+        && guessed_compiler != GuessedCompiler::nvcc) {
       args_info.output_obj = make_relative_path(ctx, &argv[i][2]);
       continue;
     }
@@ -3211,13 +3213,13 @@ cc_process_args(Context& ctx,
   // Since output is redirected, compilers will not color their output by
   // default, so force it explicitly if it would be otherwise done.
   if (!found_color_diagnostics && color_output_possible()) {
-    if (guessed_compiler == GUESSED_CLANG) {
+    if (guessed_compiler == GuessedCompiler::clang) {
       if (args_info.actual_language != "assembler") {
         args_add(common_args, "-fcolor-diagnostics");
         add_extra_arg("-fcolor-diagnostics");
         cc_log("Automatically enabling colors");
       }
-    } else if (guessed_compiler == GUESSED_GCC) {
+    } else if (guessed_compiler == GuessedCompiler::gcc) {
       // GCC has it since 4.9, but that'd require detecting what GCC version is
       // used for the actual compile. However it requires also GCC_COLORS to be
       // set (and not empty), so use that for detecting if GCC would use
index 0ed862efc8dd8b2ae93d46a5390d3497f77d65fc..ca0c708444a862daebbde5daeac1faea07602720 100644 (file)
@@ -33,13 +33,7 @@ class Config;
 
 extern const char CCACHE_VERSION[];
 
-enum guessed_compiler {
-  GUESSED_CLANG,
-  GUESSED_GCC,
-  GUESSED_NVCC,
-  GUESSED_PUMP,
-  GUESSED_UNKNOWN
-};
+enum class GuessedCompiler { clang, gcc, nvcc, pump, unknown };
 
 #define SLOPPY_INCLUDE_FILE_MTIME (1U << 0)
 #define SLOPPY_INCLUDE_FILE_CTIME (1U << 1)
index 57ce0f351afc87616c3b7464757585ac93655635..760af6f93c5100e41c89bd0fc4fa62c995dea073 100644 (file)
@@ -26,7 +26,7 @@ size_t ignore_headers_len;
 
 // Compiler guessing is currently only based on the compiler name, so nothing
 // should hard-depend on it if possible.
-enum guessed_compiler guessed_compiler = GUESSED_UNKNOWN;
+GuessedCompiler guessed_compiler = GuessedCompiler::unknown;
 
 // The .gch/.pch/.pth file used for compilation.
 char* included_pch_file = nullptr;
index b4996cf6ec51a8a6715614512045bb5090657662..7dbf34b3f3fceaa5ada49c207b58857c8e7ed46f 100644 (file)
@@ -34,6 +34,6 @@ extern char** ignore_headers;
 
 extern size_t ignore_headers_len;
 
-extern enum guessed_compiler guessed_compiler;
+extern GuessedCompiler guessed_compiler;
 
 extern char* included_pch_file;
index b1adf0e8f41204b0703ad631df9da24e2de59475..a770d818213b42e507231b8b88934e020c17332e 100644 (file)
@@ -417,8 +417,8 @@ verify_result(const Context& ctx,
 
     // Clang stores the mtime of the included files in the precompiled header,
     // and will error out if that header is later used without rebuilding.
-    if ((guessed_compiler == GUESSED_CLANG
-         || guessed_compiler == GUESSED_UNKNOWN)
+    if ((guessed_compiler == GuessedCompiler::clang
+         || guessed_compiler == GuessedCompiler::unknown)
         && ctx.args_info.output_is_precompiled_header && fi.mtime != fs.mtime) {
       cc_log("Precompiled header includes %s, which has a new mtime",
              path.c_str());