]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Rename GuessedCompiler to CompilerType
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 7 Nov 2020 18:20:48 +0000 (19:20 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 9 Nov 2020 07:54:00 +0000 (08:54 +0100)
src/Context.hpp
src/Manifest.cpp
src/argprocessing.cpp
src/ccache.cpp
src/ccache.hpp
unittest/test_argprocessing.cpp
unittest/test_ccache.cpp

index 239081f22e6a37a705ba4cf2bb62163dc34182f1..ef25edf6e48190c68ce35f1a6d2c05c1a47d53e9 100644 (file)
@@ -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;
index 0c089055e757578d08e8204194a6fd56cab3f0e1..b25ad3047230e014916e084b7e264ba339bab99c 100644 (file)
@@ -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);
index 7957fd9a59a86b1ef8ee2ea9e8cf6f3b1120ac6a..1aefdd348012b00d7f189d23260e491ea4936690 100644 (file)
@@ -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<std::string> 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.
index b9c0039f149fd8438aecab44b6ad465fa2ac540e..64117574687e82efcd81e9bc5d0481d66264f4a6 100644 (file)
@@ -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);
index 173b3b90114883b7a114362052a6ac50ae6ecc0c..e74daf734d136d2278ac3191fac752bec4bf98ef 100644 (file)
@@ -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<std::string>
 rewrite_dep_file_paths(const Context& ctx, const std::string& file_content);
index 089d8495fc6e96be314191d18d3c529632def04f..0f2d90709bd93460de9e95f17426ba716f751bbf 100644 (file)
@@ -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");
index 93d69c5a8d218baa15d1c256684d1da04f44a170..0a8b68aa67b0e8b81b2ad571b3264893a42ffdf8 100644 (file)
@@ -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
 }