From: Joel Rosdahl Date: Tue, 29 Jun 2021 18:09:49 +0000 (+0200) Subject: Allow one -Xarch_* option that matches -arch (#874) X-Git-Tag: v4.4~172 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9a810afab8aaacfd997418e96609b2589d512a5;p=thirdparty%2Fccache.git Allow one -Xarch_* option that matches -arch (#874) Closes #871. --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 92b929e09..839e4538a 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -46,6 +46,7 @@ struct ArgumentProcessingState ColorDiagnostics color_diagnostics = ColorDiagnostics::automatic; bool found_directives_only = false; bool found_rewrite_includes = false; + nonstd::optional found_xarch_arch; std::string explicit_language; // As specified with -x. std::string input_charset_option; // -finput-charset=... @@ -303,8 +304,20 @@ process_arg(Context& ctx, // -Xarch_* options are too hard. if (Util::starts_with(args[i], "-Xarch_")) { - LOG("Unsupported compiler option: {}", args[i]); - return Statistic::unsupported_compiler_option; + if (i == args.size() - 1) { + LOG("Missing argument to {}", args[i]); + return Statistic::bad_compiler_arguments; + } + const auto arch = args[i].substr(7); + if (!state.found_xarch_arch) { + state.found_xarch_arch = arch; + } else if (*state.found_xarch_arch != arch) { + LOG_RAW("Multiple different -Xarch_* options not supported"); + return Statistic::unsupported_compiler_option; + } + state.common_args.push_back(args[i]); + state.common_args.push_back(args[i + 1]); + return nullopt; } // Handle -arch options. @@ -1254,6 +1267,17 @@ process_args(Context& ctx) compiler_args.push_back("-dc"); } + if (state.found_xarch_arch && !args_info.arch_args.empty()) { + if (args_info.arch_args.size() > 1) { + LOG_RAW( + "Multiple -arch options in combination with -Xarch_* not supported"); + return Statistic::unsupported_compiler_option; + } else if (args_info.arch_args[0] != *state.found_xarch_arch) { + LOG_RAW("-arch option not matching -Xarch_* option not supported"); + return Statistic::unsupported_compiler_option; + } + } + for (const auto& arch : args_info.arch_args) { compiler_args.push_back("-arch"); compiler_args.push_back(arch); diff --git a/test/suites/multi_arch.bash b/test/suites/multi_arch.bash index 786b71bed..650ac87ca 100644 --- a/test/suites/multi_arch.bash +++ b/test/suites/multi_arch.bash @@ -36,6 +36,15 @@ SUITE_multi_arch() { expect_stat 'cache hit (direct)' 2 expect_stat 'cache miss' 3 + # A single -Xarch_* matching -arch is supported. + $CCACHE_COMPILE -arch x86_64 -Xarch_x86_64 -I. -c test1.c + expect_stat 'cache hit (direct)' 2 + expect_stat 'cache miss' 4 + + $CCACHE_COMPILE -arch x86_64 -Xarch_x86_64 -I. -c test1.c + expect_stat 'cache hit (direct)' 3 + expect_stat 'cache miss' 4 + # ------------------------------------------------------------------------- TEST "cache hit, preprocessor mode"