Преглед изворни кода

cmGlobalNinjaGenerator: tell `ninja` to actually read the depfile

But only do so if the depfile is not specified as an output of the
command. Otherwise the command will out-of-date itself as `ninja`
deletes depfiles that it incorporates into the database and a missing
output will cause the command to run again.
Ben Boeckel пре 2 година
родитељ
комит
b0177003e1
2 измењених фајлова са 21 додато и 1 уклоњено
  1. 5 0
      Help/command/add_custom_command.rst
  2. 16 1
      Source/cmGlobalNinjaGenerator.cxx

+ 5 - 0
Help/command/add_custom_command.rst

@@ -373,6 +373,11 @@ The options are:
     :manual:`generator expressions <cmake-generator-expressions(7)>` was also
     added.
 
+  .. versionadded:: 3.29
+    The :ref:`Ninja Generators` will now incorporate the dependencies into its
+    "deps log" database if the file is not listed in ``OUTPUTS`` or
+    ``BYPRODUCTS``.
+
   Using ``DEPFILE`` with generators other than those listed above is an error.
 
   If the ``DEPFILE`` argument is relative, it should be relative to

+ 16 - 1
Source/cmGlobalNinjaGenerator.cxx

@@ -378,6 +378,15 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
   }
 
   {
+    std::string ninjaDepfilePath;
+    bool depfileIsOutput = false;
+    if (!depfile.empty()) {
+      ninjaDepfilePath = this->ConvertToNinjaPath(depfile);
+      depfileIsOutput =
+        std::find(outputs.ExplicitOuts.begin(), outputs.ExplicitOuts.end(),
+                  ninjaDepfilePath) != outputs.ExplicitOuts.end();
+    }
+
     cmNinjaBuild build("CUSTOM_COMMAND");
     build.Comment = comment;
     build.Outputs = std::move(outputs.ExplicitOuts);
@@ -405,7 +414,13 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
       vars["pool"] = job_pool;
     }
     if (!depfile.empty()) {
-      vars["depfile"] = depfile;
+      vars["depfile"] = ninjaDepfilePath;
+      // Add the depfile to the `.ninja_deps` database. Since this (generally)
+      // removes the file, it cannot be declared as an output or byproduct of
+      // the command.
+      if (!depfileIsOutput) {
+        vars["deps"] = "gcc";
+      }
     }
     if (config.empty()) {
       this->WriteBuild(*this->GetCommonFileStream(), build);