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

index 7af2ec4e45b9ef070b0b24de733cc338649f37d2..19098a6e8ba92a845eba7eb9012843702e7a9dfc 100644 (file)
@@ -23,6 +23,7 @@
 #include "ArgsInfo.hpp"
 #include "Config.hpp"
 #include "NonCopyable.hpp"
+#include "ccache.hpp"
 #include "hash.hpp"
 
 #include <unordered_map>
@@ -81,4 +82,8 @@ struct Context : NonCopyable
 
   // The stats file to use for the manifest.
   std::string manifest_stats_file;
+
+  // Compiler guessing is currently only based on the compiler name, so nothing
+  // should hard-depend on it if possible.
+  GuessedCompiler guessed_compiler = GuessedCompiler::unknown;
 };
index d4912479ab2f43500c32cc57715bf98126c9b650..e4181f5f8fc90eb01cc8ad70e0883e24b79544ed 100644 (file)
@@ -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 != GuessedCompiler::pump) {
+  if (st.size() != 0 && ctx.guessed_compiler != GuessedCompiler::pump) {
     cc_log("Compiler produced stdout");
     stats_update(STATS_STDOUT);
     tmp_unlink(tmp_stdout);
@@ -1442,8 +1442,11 @@ 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 == GuessedCompiler::pump)) {
+  if (!process_preprocessed_file(ctx,
+                                 hash,
+                                 path_stdout,
+                                 ctx.guessed_compiler
+                                   == GuessedCompiler::pump)) {
     stats_update(STATS_ERROR);
     failed();
   }
@@ -1701,7 +1704,7 @@ hash_common_info(Context& ctx,
   }
 
   // Possibly hash GCC_COLORS (for color diagnostics).
-  if (guessed_compiler == GuessedCompiler::gcc) {
+  if (ctx.guessed_compiler == GuessedCompiler::gcc) {
     const char* gcc_colors = getenv("GCC_COLORS");
     if (gcc_colors) {
       hash_delimiter(hash, "gcccolors");
@@ -1732,8 +1735,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 == GuessedCompiler::clang
-                 || guessed_compiler == GuessedCompiler::unknown;
+  int is_clang = ctx.guessed_compiler == GuessedCompiler::clang
+                 || ctx.guessed_compiler == GuessedCompiler::unknown;
 
   // First the arguments.
   for (int i = 1; i < args->argc; i++) {
@@ -2037,8 +2040,8 @@ from_cache(Context& ctx,
   //
   //     file 'foo.h' has been modified since the precompiled header 'foo.pch'
   //     was built
-  if ((guessed_compiler == GuessedCompiler::clang
-       || guessed_compiler == GuessedCompiler::unknown)
+  if ((ctx.guessed_compiler == GuessedCompiler::clang
+       || ctx.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");
@@ -2343,7 +2346,7 @@ cc_process_args(Context& ctx,
     }
 
     // Handle cuda "-optf" and "--options-file" argument.
-    if (guessed_compiler == GuessedCompiler::nvcc
+    if (ctx.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]);
@@ -2477,7 +2480,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 == GuessedCompiler::nvcc) {
+        && ctx.guessed_compiler == GuessedCompiler::nvcc) {
       found_dc_opt = true;
       continue;
     }
@@ -2524,8 +2527,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 != GuessedCompiler::nvcc) {
-      args_info.output_obj = make_relative_path(ctx, &argv[i][2]);
+        && ctx.guessed_compiler != GuessedCompiler::nvcc) {
+      ctx.args_info.output_obj = make_relative_path(ctx, &argv[i][2]);
       continue;
     }
 
@@ -3213,13 +3216,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 == GuessedCompiler::clang) {
-      if (args_info.actual_language != "assembler") {
+    if (ctx.guessed_compiler == GuessedCompiler::clang) {
+      if (ctx.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 == GuessedCompiler::gcc) {
+    } else if (ctx.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
@@ -3656,7 +3659,7 @@ do_cache_compilation(Context& ctx, char* argv[])
     std::min(std::max(ctx.config.limit_multiple(), 0.0), 1.0));
 
   MTR_BEGIN("main", "guess_compiler");
-  guessed_compiler = guess_compiler(ctx.orig_args->argv[0]);
+  ctx.guessed_compiler = guess_compiler(ctx.orig_args->argv[0]);
   MTR_END("main", "guess_compiler");
 
   // Arguments (except -E) to send to the preprocessor.
index 760af6f93c5100e41c89bd0fc4fa62c995dea073..19375da7f38bc5e50ff0b4fdcf02e5eea1d294a6 100644 (file)
@@ -24,10 +24,6 @@ char** ignore_headers;
 // Size of headers to ignore list.
 size_t ignore_headers_len;
 
-// 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 .gch/.pch/.pth file used for compilation.
 char* included_pch_file = nullptr;
 
index 7dbf34b3f3fceaa5ada49c207b58857c8e7ed46f..5f5e9a350a35e31fcca5a40a596b8c52b3050bdd 100644 (file)
@@ -34,6 +34,4 @@ extern char** ignore_headers;
 
 extern size_t ignore_headers_len;
 
-extern GuessedCompiler guessed_compiler;
-
 extern char* included_pch_file;
index a770d818213b42e507231b8b88934e020c17332e..ccdee31dfe1c66d6cb9a738c6cbc82e327726f49 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 == GuessedCompiler::clang
-         || guessed_compiler == GuessedCompiler::unknown)
+    if ((ctx.guessed_compiler == GuessedCompiler::clang
+         || ctx.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());