]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Bail out on too hard MSVC environment variables CL and _CL_
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 26 Mar 2022 11:20:32 +0000 (12:20 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 26 Mar 2022 11:43:22 +0000 (12:43 +0100)
To handle the CL and _CL_ variables properly, ccache needs to parse them
according to [1] and then include the compiler options as part of
regular argument processing. Until that is done we have to bail out and
just run the original compiler.

[1]: https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170

Fixes #1022.

doc/MANUAL.adoc
src/ccache.cpp
src/core/Statistic.hpp
src/core/Statistics.cpp

index 7ea5f639512964c87065b94b53151f382de904ed..0cf11e62b710394c74ddb8edf437fa42db1b0460 100644 (file)
@@ -1351,6 +1351,9 @@ by ccache.
 | Unsupported compiler option |
 A compiler option not supported by ccache was found.
 
+| Unsupported environment variable |
+An environment variable not supported by ccache was set.
+
 | Unsupported source language |
 A source language e.g. specified with `-x` was unsupported by ccache.
 
index 5ecad3381f288594ffd6449d6d607e03e58ecd42..8d30e37d7831aca37f33da055c229d9a5a56fd37 100644 (file)
@@ -2138,6 +2138,15 @@ do_cache_compilation(Context& ctx, const char* const* argv)
 
   TRY(set_up_uncached_err());
 
+  if (ctx.config.is_compiler_group_msvc()) {
+    for (const auto& name : {"CL", "_CL_"}) {
+      if (getenv(name)) {
+        LOG("Unsupported environment variable: {}", name);
+        return Statistic::unsupported_environment_variable;
+      }
+    }
+  }
+
   if (!ctx.config.run_second_cpp() && ctx.config.is_compiler_group_msvc()) {
     LOG_RAW("Second preprocessor cannot be disabled");
     ctx.config.set_run_second_cpp(true);
index dddfca9272511dc4ec43ef3447a39bc26357ab28..7adce5cc5d63e77e286cdb90eed7da1522139f37 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -64,6 +64,7 @@ enum class Statistic {
   secondary_storage_error = 39,
   secondary_storage_timeout = 40,
   recache = 41,
+  unsupported_environment_variable = 42,
 
   END
 };
index c50c13afb512dc4ad5ff1a57e7fce95b3d59e634..7786b261499f21be7614f814ba7120bce3cd59c8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -113,6 +113,9 @@ const StatisticsField k_statistics_fields[] = {
   FIELD(unsupported_compiler_option,
         "Unsupported compiler option",
         FLAG_UNCACHEABLE),
+  FIELD(unsupported_environment_variable,
+        "Unsupported environment variable",
+        FLAG_UNCACHEABLE),
   FIELD(unsupported_source_language,
         "Unsupported source language",
         FLAG_UNCACHEABLE),