From: Joel Rosdahl Date: Sat, 7 Nov 2020 18:20:48 +0000 (+0100) Subject: Rename GuessedCompiler to CompilerType X-Git-Tag: v4.1~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f3de1d8bb599623f68f879e320cf6f73069dec8;p=thirdparty%2Fccache.git Rename GuessedCompiler to CompilerType --- diff --git a/src/Context.hpp b/src/Context.hpp index 239081f22..ef25edf6e 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -93,9 +93,9 @@ public: // The name of the cpp stderr file. std::string cpp_stderr; - // Compiler guessing is currently only based on the compiler name, so nothing - // should hard-depend on it if possible. - GuessedCompiler guessed_compiler = GuessedCompiler::unknown; + // The compiler type is by default a guess based on the compiler name, so + // nothing should hard-depend on it if possible. + CompilerType compiler_type = CompilerType::unknown; // The .gch/.pch/.pth file used for compilation. std::string included_pch_file; diff --git a/src/Manifest.cpp b/src/Manifest.cpp index 0c089055e..b25ad3047 100644 --- a/src/Manifest.cpp +++ b/src/Manifest.cpp @@ -435,8 +435,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 ((ctx.guessed_compiler == GuessedCompiler::clang - || ctx.guessed_compiler == GuessedCompiler::unknown) + if ((ctx.compiler_type == CompilerType::clang + || ctx.compiler_type == CompilerType::unknown) && ctx.args_info.output_is_precompiled_header && !ctx.args_info.fno_pch_timestamp && fi.mtime != fs.mtime) { LOG("Precompiled header includes {}, which has a new mtime", path); diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 7957fd9a5..1aefdd348 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -158,7 +158,7 @@ process_profiling_option(Context& ctx, const std::string& arg) new_profile_path = arg.substr(arg.find('=') + 1); } else if (arg == "-fprofile-generate" || arg == "-fprofile-instr-generate") { ctx.args_info.profile_generate = true; - if (ctx.guessed_compiler == GuessedCompiler::clang) { + if (ctx.compiler_type == CompilerType::clang) { new_profile_path = "."; } else { // GCC uses $PWD/$(basename $obj). @@ -254,7 +254,7 @@ process_arg(Context& ctx, } // Handle cuda "-optf" and "--options-file" argument. - if (ctx.guessed_compiler == GuessedCompiler::nvcc + if (ctx.compiler_type == CompilerType::nvcc && (args[i] == "-optf" || args[i] == "--options-file")) { if (i == args.size() - 1) { LOG("Expected argument after {}", args[i]); @@ -327,8 +327,7 @@ process_arg(Context& ctx, if (compopt_affects_compiler_output(args[i])) { state.compiler_only_args.push_back(args[i]); if (compopt_takes_arg(args[i]) - || (ctx.guessed_compiler == GuessedCompiler::nvcc - && args[i] == "-Werror")) { + || (ctx.compiler_type == CompilerType::nvcc && args[i] == "-Werror")) { if (i == args.size() - 1) { LOG("Missing argument to {}", args[i]); return Statistic::bad_compiler_arguments; @@ -372,7 +371,7 @@ process_arg(Context& ctx, // when using nvcc with separable compilation, -dc implies -c if ((args[i] == "-dc" || args[i] == "--device-c") - && ctx.guessed_compiler == GuessedCompiler::nvcc) { + && ctx.compiler_type == CompilerType::nvcc) { state.found_dc_opt = true; return nullopt; } @@ -428,7 +427,7 @@ process_arg(Context& ctx, // Alternate form of -o with no space. Nvcc does not support this. if (Util::starts_with(args[i], "-o") - && ctx.guessed_compiler != GuessedCompiler::nvcc) { + && ctx.compiler_type != CompilerType::nvcc) { args_info.output_obj = Util::make_relative_path(ctx, string_view(args[i]).substr(2)); return nullopt; @@ -1099,13 +1098,13 @@ process_args(Context& ctx) // Since output is redirected, compilers will not color their output by // default, so force it explicitly. nonstd::optional diagnostics_color_arg; - if (ctx.guessed_compiler == GuessedCompiler::clang) { + if (ctx.compiler_type == CompilerType::clang) { // Don't pass -fcolor-diagnostics when compiling assembler to avoid an // "argument unused during compilation" warning. if (args_info.actual_language != "assembler") { diagnostics_color_arg = "-fcolor-diagnostics"; } - } else if (ctx.guessed_compiler == GuessedCompiler::gcc) { + } else if (ctx.compiler_type == CompilerType::gcc) { diagnostics_color_arg = "-fdiagnostics-color"; } else { // Other compilers shouldn't output color, so no need to strip it. diff --git a/src/ccache.cpp b/src/ccache.cpp index b9c0039f1..641175746 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -250,7 +250,7 @@ init_hash_debug(Context& ctx, } } -GuessedCompiler +CompilerType guess_compiler(string_view path) { std::string compiler_path(path); @@ -274,16 +274,16 @@ guess_compiler(string_view path) const string_view name = Util::base_name(compiler_path); if (name.find("clang") != nonstd::string_view::npos) { - return GuessedCompiler::clang; + return CompilerType::clang; } else if (name.find("gcc") != nonstd::string_view::npos || name.find("g++") != nonstd::string_view::npos) { - return GuessedCompiler::gcc; + return CompilerType::gcc; } else if (name.find("nvcc") != nonstd::string_view::npos) { - return GuessedCompiler::nvcc; + return CompilerType::nvcc; } else if (name == "pump" || name == "distcc-pump") { - return GuessedCompiler::pump; + return CompilerType::pump; } else { - return GuessedCompiler::unknown; + return CompilerType::unknown; } } @@ -756,8 +756,7 @@ do_execute(Context& ctx, { UmaskScope umask_scope(ctx.original_umask); - if (ctx.diagnostics_color_failed - && ctx.guessed_compiler == GuessedCompiler::gcc) { + if (ctx.diagnostics_color_failed && ctx.compiler_type == CompilerType::gcc) { args.erase_last("-fdiagnostics-color"); } int status = execute(args.to_argv().data(), @@ -765,7 +764,7 @@ do_execute(Context& ctx, std::move(tmp_stderr.fd), &ctx.compiler_pid); if (status != 0 && !ctx.diagnostics_color_failed - && ctx.guessed_compiler == GuessedCompiler::gcc) { + && ctx.compiler_type == CompilerType::gcc) { auto errors = Util::read_file(tmp_stderr.path); if (errors.find("unrecognized command line option") != std::string::npos && errors.find("-fdiagnostics-color") != std::string::npos) { @@ -1009,7 +1008,7 @@ to_cache(Context& ctx, // distcc-pump outputs lines like this: // __________Using # distcc servers in pump mode - if (st.size() != 0 && ctx.guessed_compiler != GuessedCompiler::pump) { + if (st.size() != 0 && ctx.compiler_type != CompilerType::pump) { LOG_RAW("Compiler produced stdout"); throw Failure(Statistic::compiler_produced_stdout); } @@ -1180,7 +1179,7 @@ get_result_name_from_cpp(Context& ctx, Args& args, Hash& hash) } hash.hash_delimiter("cpp"); - bool is_pump = ctx.guessed_compiler == GuessedCompiler::pump; + bool is_pump = ctx.compiler_type == CompilerType::pump; if (!process_preprocessed_file(ctx, hash, stdout_path, is_pump)) { throw Failure(Statistic::internal_error); } @@ -1438,7 +1437,7 @@ hash_common_info(const Context& ctx, } // Possibly hash GCC_COLORS (for color diagnostics). - if (ctx.guessed_compiler == GuessedCompiler::gcc) { + if (ctx.compiler_type == CompilerType::gcc) { const char* gcc_colors = getenv("GCC_COLORS"); if (gcc_colors) { hash.hash_delimiter("gcccolors"); @@ -1519,8 +1518,8 @@ calculate_result_name(Context& ctx, // clang will emit warnings for unused linker flags, so we shouldn't skip // those arguments. - int is_clang = ctx.guessed_compiler == GuessedCompiler::clang - || ctx.guessed_compiler == GuessedCompiler::unknown; + int is_clang = ctx.compiler_type == CompilerType::clang + || ctx.compiler_type == CompilerType::unknown; // First the arguments. for (size_t i = 1; i < args.size(); i++) { @@ -1816,8 +1815,8 @@ from_cache(Context& ctx, FromCacheCallMode mode) // // file 'foo.h' has been modified since the precompiled header 'foo.pch' // was built - if ((ctx.guessed_compiler == GuessedCompiler::clang - || ctx.guessed_compiler == GuessedCompiler::unknown) + if ((ctx.compiler_type == CompilerType::clang + || ctx.compiler_type == CompilerType::unknown) && ctx.args_info.output_is_precompiled_header && !ctx.args_info.fno_pch_timestamp && mode == FromCacheCallMode::cpp) { LOG_RAW("Not considering cached precompiled header in preprocessor mode"); @@ -2304,13 +2303,13 @@ cache_compilation(int argc, const char* const* argv) } static std::string -guessed_compiler_to_string(GuessedCompiler guessed_compiler) +compiler_type_to_string(CompilerType compiler_type) { #define CASE(type) \ - case GuessedCompiler::type: \ + case CompilerType::type: \ return #type - switch (guessed_compiler) { + switch (compiler_type) { CASE(clang); CASE(gcc); CASE(nvcc); @@ -2357,10 +2356,8 @@ do_cache_compilation(Context& ctx, const char* const* argv) LOG("Apparent working directory: {}", ctx.apparent_cwd); } - MTR_BEGIN("main", "guess_compiler"); - ctx.guessed_compiler = guess_compiler(ctx.orig_args[0]); - LOG("Guessed compiler: {}", guessed_compiler_to_string(ctx.guessed_compiler)); - MTR_END("main", "guess_compiler"); + ctx.compiler_type = guess_compiler(ctx.orig_args[0]); + LOG("Compiler type: {}", compiler_type_to_string(ctx.compiler_type)); MTR_BEGIN("main", "process_args"); ProcessArgsResult processed = process_args(ctx); diff --git a/src/ccache.hpp b/src/ccache.hpp index 173b3b901..e74daf734 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -31,7 +31,7 @@ class Context; extern const char CCACHE_VERSION[]; -enum class GuessedCompiler { clang, gcc, nvcc, pump, unknown }; +enum class CompilerType { clang, gcc, nvcc, pump, unknown }; const uint32_t SLOPPY_INCLUDE_FILE_MTIME = 1 << 0; const uint32_t SLOPPY_INCLUDE_FILE_CTIME = 1 << 1; @@ -61,6 +61,6 @@ using FindExecutableFunction = // Tested by unit tests. void find_compiler(Context& ctx, const FindExecutableFunction& find_executable_function); -GuessedCompiler guess_compiler(nonstd::string_view path); +CompilerType guess_compiler(nonstd::string_view path); nonstd::optional rewrite_dep_file_paths(const Context& ctx, const std::string& file_content); diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 089d8495f..0f2d90709 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -532,7 +532,7 @@ TEST_CASE("cuda_option_file") { TestContext test_context; Context ctx; - ctx.guessed_compiler = GuessedCompiler::nvcc; + ctx.compiler_type = CompilerType::nvcc; ctx.orig_args = Args::from_string("nvcc -optf foo.optf,bar.optf"); Util::write_file("foo.c", ""); Util::write_file("foo.optf", "-c foo.c -g -Wall -o"); diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index 93d69c5a8..0a8b68aa6 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -163,28 +163,27 @@ TEST_CASE("guess_compiler") SUBCASE("Compiler not in file system") { - CHECK(guess_compiler("/test/prefix/clang") == GuessedCompiler::clang); - CHECK(guess_compiler("/test/prefix/clang-3.8") == GuessedCompiler::clang); - CHECK(guess_compiler("/test/prefix/clang++") == GuessedCompiler::clang); - CHECK(guess_compiler("/test/prefix/clang++-10") == GuessedCompiler::clang); - - CHECK(guess_compiler("/test/prefix/gcc") == GuessedCompiler::gcc); - CHECK(guess_compiler("/test/prefix/gcc-4.8") == GuessedCompiler::gcc); - CHECK(guess_compiler("/test/prefix/g++") == GuessedCompiler::gcc); - CHECK(guess_compiler("/test/prefix/g++-9") == GuessedCompiler::gcc); + CHECK(guess_compiler("/test/prefix/clang") == CompilerType::clang); + CHECK(guess_compiler("/test/prefix/clang-3.8") == CompilerType::clang); + CHECK(guess_compiler("/test/prefix/clang++") == CompilerType::clang); + CHECK(guess_compiler("/test/prefix/clang++-10") == CompilerType::clang); + + CHECK(guess_compiler("/test/prefix/gcc") == CompilerType::gcc); + CHECK(guess_compiler("/test/prefix/gcc-4.8") == CompilerType::gcc); + CHECK(guess_compiler("/test/prefix/g++") == CompilerType::gcc); + CHECK(guess_compiler("/test/prefix/g++-9") == CompilerType::gcc); CHECK(guess_compiler("/test/prefix/x86_64-w64-mingw32-gcc-posix") - == GuessedCompiler::gcc); + == CompilerType::gcc); - CHECK(guess_compiler("/test/prefix/nvcc") == GuessedCompiler::nvcc); - CHECK(guess_compiler("/test/prefix/nvcc-10.1.243") - == GuessedCompiler::nvcc); + CHECK(guess_compiler("/test/prefix/nvcc") == CompilerType::nvcc); + CHECK(guess_compiler("/test/prefix/nvcc-10.1.243") == CompilerType::nvcc); - CHECK(guess_compiler("/test/prefix/pump") == GuessedCompiler::pump); - CHECK(guess_compiler("/test/prefix/distcc-pump") == GuessedCompiler::pump); + CHECK(guess_compiler("/test/prefix/pump") == CompilerType::pump); + CHECK(guess_compiler("/test/prefix/distcc-pump") == CompilerType::pump); - CHECK(guess_compiler("/test/prefix/x") == GuessedCompiler::unknown); - CHECK(guess_compiler("/test/prefix/cc") == GuessedCompiler::unknown); - CHECK(guess_compiler("/test/prefix/c++") == GuessedCompiler::unknown); + CHECK(guess_compiler("/test/prefix/x") == CompilerType::unknown); + CHECK(guess_compiler("/test/prefix/cc") == CompilerType::unknown); + CHECK(guess_compiler("/test/prefix/c++") == CompilerType::unknown); } #ifndef _WIN32 @@ -196,7 +195,7 @@ TEST_CASE("guess_compiler") const auto cc = FMT("{}/cc", cwd); CHECK(symlink("intermediate", cc.c_str()) == 0); - CHECK(guess_compiler(cc) == GuessedCompiler::gcc); + CHECK(guess_compiler(cc) == CompilerType::gcc); } #endif }