]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Handle NVCC long option alternatives to -M/-MD/-MF/-MM/-MMD/-MT master
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 21 Dec 2025 16:07:37 +0000 (17:07 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 21 Dec 2025 18:57:14 +0000 (19:57 +0100)
Fixes #1663.

src/ccache/argprocessing.cpp
src/ccache/ccache.cpp
src/ccache/compopt.cpp

index de6ece914bb2c7bcbf14145e29dbc4a638b69c0d..7d1f83cc7e0f66db129a85fbd50ab5b5b6c30497 100644 (file)
@@ -818,18 +818,26 @@ process_option_arg(const Context& ctx,
 
   // These options require special handling, because they behave differently
   // with gcc -E, when the output file is not specified.
-  if ((arg == "-MD" || arg == "-MMD") && !config.is_compiler_group_msvc()) {
+  if (!config.is_compiler_group_msvc()
+      && (arg == "-MD"
+          || arg == "-MMD"
+          // nvcc -MD:
+          || arg == "--generate-dependencies-with-compile"
+          // nvcc -MMD:
+          || arg == "--generate-nonsystem-dependencies-with-compile")) {
     state.found_md_or_mmd_opt = true;
     args_info.generating_dependencies = true;
     state.add_compiler_only_arg(args[i]);
     return Statistic::none;
   }
 
-  if (util::starts_with(arg, "-MF")) {
+  if (util::starts_with(arg, "-MF")
+      // nvcc -MF:
+      || arg == "--dependency-output") {
     state.found_mf_opt = true;
 
     std::string dep_file;
-    bool separate_argument = (arg.size() == 3);
+    bool separate_argument = (arg.size() == 3 || arg == "--dependency-output");
     if (separate_argument) {
       // -MF arg
       if (i == args.size() - 1) {
@@ -857,12 +865,15 @@ process_option_arg(const Context& ctx,
     return Statistic::none;
   }
 
-  if ((util::starts_with(arg, "-MQ") || util::starts_with(arg, "-MT"))
-      && !config.is_compiler_group_msvc()) {
+  if (!config.is_compiler_group_msvc()
+      && (util::starts_with(arg, "-MQ")
+          || util::starts_with(arg, "-MT")
+          // nvcc -MT:
+          || arg == "--dependency-target-name")) {
     const bool is_mq = arg[2] == 'Q';
 
     std::string_view dep_target;
-    if (arg.size() == 3) {
+    if (arg.size() == 3 || arg == "--dependency-target-name") {
       // -MQ arg or -MT arg
       if (i == args.size() - 1) {
         LOG("Missing argument to {}", args[i]);
@@ -1067,7 +1078,9 @@ process_option_arg(const Context& ctx,
     return Statistic::none;
   }
 
-  if (arg == "-MP") {
+  if (arg == "-MP"
+      // nvcc -MP:
+      || arg == "--generate-dependency-targets") {
     state.add_compiler_only_arg(args[i]);
     return Statistic::none;
   }
index 7aa40c659942d8f975d60dbacbe1449bc5f3b924..413242510866dcfed8a68cafd8d2381633cb49d7 100644 (file)
@@ -2254,9 +2254,6 @@ hash_argument(const Context& ctx,
   }
 
   if (ctx.args_info.generating_dependencies) {
-    std::optional<std::string_view> option;
-    std::optional<std::string_view> value;
-
     if (util::starts_with(args[i], "-Wp,")) {
       // Skip the dependency filename since it doesn't impact the output.
       if (util::starts_with(args[i], "-Wp,-MD,")
@@ -2268,23 +2265,21 @@ hash_argument(const Context& ctx,
         hash.hash(args[i].data(), 9);
         return {};
       }
-    } else if (std::tie(option, value) = get_option_and_value("-MF", args, i);
-               option) {
-      // Skip the dependency filename since it doesn't impact the output.
-      hash.hash(*option);
-      return {};
-    } else if (std::tie(option, value) = get_option_and_value("-MQ", args, i);
-               option) {
-      hash.hash(*option);
-      // No need to hash the dependency target since we always calculate it on
-      // a cache hit.
-      return {};
-    } else if (std::tie(option, value) = get_option_and_value("-MT", args, i);
-               option) {
-      hash.hash(*option);
-      // No need to hash the dependency target since we always calculate it on
-      // a cache hit.
-      return {};
+    } else {
+      static std::array skip_options = {
+        "-MF",                 // dependency filename doesn't impact the output
+        "-MQ",                 // dependency target is calculated on cache hit
+        "-MT",                 // dependency target is calculated on cache hit
+        "--dependency-output", // nvcc version of -MF
+        "--dependency-target-name", // nvcc version of -MT
+      };
+      for (auto opt : skip_options) {
+        if (const auto [option, _value] = get_option_and_value(opt, args, i);
+            option) {
+          hash.hash(*option);
+          return {};
+        }
+      }
     }
   }
 
index 81c421705e94345570d07883878ae4188a92181f..8db5fea9f84e577cc1c7ee93091e8e40c5b25535 100644 (file)
@@ -49,6 +49,7 @@ struct CompOpt
   int type;
 };
 
+// clang-format off
 const CompOpt compopts[] = {
   {"--Werror",                TAKES_ARG | AFFECTS_COMP                               }, // nvcc
   {"--analyzer-output",       TOO_HARD                                               }, // Clang
@@ -57,6 +58,8 @@ const CompOpt compopts[] = {
   {"--config",                TAKES_ARG                                              }, // Clang
   {"--em-config",             TAKES_ARG                                              }, // emcc
   {"--gcc-toolchain=",        TAKES_CONCAT_ARG | TAKES_PATH                          }, // Clang
+  {"--generate-dependencies", TOO_HARD                                               }, // nvcc (-M)
+  {"--generate-nonsystem-dependencies", TOO_HARD                                     }, // nvcc (-MM)
   {"--include",               AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
   {"--libdevice-directory",   AFFECTS_CPP | TAKES_ARG                                }, // nvcc
   {"--offload-compress",      AFFECTS_COMP                                           }, // Clang
@@ -177,6 +180,7 @@ const CompOpt compopts[] = {
   {"-wrapper",                TAKES_ARG | TOO_HARD                                   },
   {"-z",                      TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP            },
 };
+// clang-format on
 
 static int
 compare_compopts(const void* key1, const void* key2)