]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Allow one -Xarch_* option that matches -arch (#874)
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 29 Jun 2021 18:09:49 +0000 (20:09 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Jun 2021 18:09:49 +0000 (20:09 +0200)
Closes #871.

src/argprocessing.cpp
test/suites/multi_arch.bash

index 92b929e09b29f3e3eb3bf4c62160e623503f0222..839e4538a90402ea6f4fb29b3ffea2446264ec8a 100644 (file)
@@ -46,6 +46,7 @@ struct ArgumentProcessingState
   ColorDiagnostics color_diagnostics = ColorDiagnostics::automatic;
   bool found_directives_only = false;
   bool found_rewrite_includes = false;
+  nonstd::optional<std::string> 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);
index 786b71beddfee2fd23137cc1494c87c7d6883b33..650ac87ca267efb014186ab1f52601cb9e7bd2c5 100644 (file)
@@ -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"