From: Thomas Otto Date: Sun, 26 Jan 2020 20:09:14 +0000 (+0100) Subject: Convert guessed_compiler into an enum class X-Git-Tag: v4.0~613^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cb437b17fd1610da01c42eb884c5589ce48c2da;p=thirdparty%2Fccache.git Convert guessed_compiler into an enum class --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 6b1631ece..d4912479a 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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 diff --git a/src/ccache.hpp b/src/ccache.hpp index 0ed862efc..ca0c70844 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -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) diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 57ce0f351..760af6f93 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -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; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index b4996cf6e..7dbf34b3f 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -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; diff --git a/src/manifest.cpp b/src/manifest.cpp index b1adf0e8f..a770d8182 100644 --- a/src/manifest.cpp +++ b/src/manifest.cpp @@ -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());