From a2988ace17d61dd8bb1342ffa8b500471307ebde Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 26 Mar 2022 12:20:32 +0100 Subject: [PATCH] fix: Bail out on too hard MSVC environment variables CL and _CL_ 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 | 3 +++ src/ccache.cpp | 9 +++++++++ src/core/Statistic.hpp | 3 ++- src/core/Statistics.cpp | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 7ea5f6395..0cf11e62b 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -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. diff --git a/src/ccache.cpp b/src/ccache.cpp index 5ecad3381..8d30e37d7 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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); diff --git a/src/core/Statistic.hpp b/src/core/Statistic.hpp index dddfca927..7adce5cc5 100644 --- a/src/core/Statistic.hpp +++ b/src/core/Statistic.hpp @@ -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 }; diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index c50c13afb..7786b2614 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -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), -- 2.47.2