瀏覽代碼

Merge topic 'prepare-deferred-custom-command-creation'

5d28e361b7 add_custom_command: Move append functionality into class cmMakefile
4fb29850ad add_custom_command: Refactor setting implicit depends

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3810
Brad King 6 年之前
父節點
當前提交
7c47894b45

+ 8 - 32
Source/cmAddCustomCommandCommand.cxx

@@ -12,7 +12,6 @@
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmMessageType.h"
 #include "cmPolicies.h"
 #include "cmPolicies.h"
-#include "cmSourceFile.h"
 #include "cmStringAlgorithms.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmTarget.h"
 #include "cmTarget.h"
@@ -50,7 +49,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
   bool uses_terminal = false;
   bool uses_terminal = false;
   bool command_expand_lists = false;
   bool command_expand_lists = false;
   std::string implicit_depends_lang;
   std::string implicit_depends_lang;
-  cmCustomCommand::ImplicitDependsList implicit_depends;
+  cmImplicitDependsList implicit_depends;
 
 
   // Accumulate one command line at a time.
   // Accumulate one command line at a time.
   cmCustomCommandLine currentLine;
   cmCustomCommandLine currentLine;
@@ -316,14 +315,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
 
 
   // Check for an append request.
   // Check for an append request.
   if (append) {
   if (append) {
-    // Lookup an existing command.
-    if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) {
-      if (cmCustomCommand* cc = sf->GetCustomCommand()) {
-        cc->AppendCommands(commandLines);
-        cc->AppendDepends(depends);
-        cc->AppendImplicitDepends(implicit_depends);
-        return true;
-      }
+    if (mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends,
+                                       commandLines)) {
+      return true;
     }
     }
 
 
     // No command for this output exists.
     // No command for this output exists.
@@ -350,28 +344,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
                                 job_pool, command_expand_lists);
                                 job_pool, command_expand_lists);
   } else if (target.empty()) {
   } else if (target.empty()) {
     // Target is empty, use the output.
     // Target is empty, use the output.
-    mf.AddCustomCommandToOutput(output, byproducts, depends, main_dependency,
-                                commandLines, comment, working.c_str(), false,
-                                escapeOldStyle, uses_terminal,
-                                command_expand_lists, depfile, job_pool);
-
-    // Add implicit dependency scanning requests if any were given.
-    if (!implicit_depends.empty()) {
-      bool okay = false;
-      if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) {
-        if (cmCustomCommand* cc = sf->GetCustomCommand()) {
-          okay = true;
-          cc->SetImplicitDepends(implicit_depends);
-        }
-      }
-      if (!okay) {
-        std::ostringstream e;
-        e << "could not locate source file with a custom command producing \""
-          << output[0] << "\" even though this command tried to create it!";
-        status.SetError(e.str());
-        return false;
-      }
-    }
+    mf.AddCustomCommandToOutput(
+      output, byproducts, depends, main_dependency, implicit_depends,
+      commandLines, comment, working.c_str(), false, escapeOldStyle,
+      uses_terminal, command_expand_lists, depfile, job_pool);
   } else if (!byproducts.empty()) {
   } else if (!byproducts.empty()) {
     status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
     status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
     return false;
     return false;

+ 3 - 4
Source/cmCustomCommand.cxx

@@ -88,18 +88,17 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
   return this->Backtrace;
   return this->Backtrace;
 }
 }
 
 
-cmCustomCommand::ImplicitDependsList const&
-cmCustomCommand::GetImplicitDepends() const
+cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const
 {
 {
   return this->ImplicitDepends;
   return this->ImplicitDepends;
 }
 }
 
 
-void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
+void cmCustomCommand::SetImplicitDepends(cmImplicitDependsList const& l)
 {
 {
   this->ImplicitDepends = l;
   this->ImplicitDepends = l;
 }
 }
 
 
-void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
+void cmCustomCommand::AppendImplicitDepends(cmImplicitDependsList const& l)
 {
 {
   cmAppend(this->ImplicitDepends, l);
   cmAppend(this->ImplicitDepends, l);
 }
 }

+ 9 - 8
Source/cmCustomCommand.h

@@ -14,6 +14,11 @@
 
 
 class cmMakefile;
 class cmMakefile;
 
 
+class cmImplicitDependsList
+  : public std::vector<std::pair<std::string, std::string>>
+{
+};
+
 /** \class cmCustomCommand
 /** \class cmCustomCommand
  * \brief A class to encapsulate a custom command
  * \brief A class to encapsulate a custom command
  *
  *
@@ -68,13 +73,9 @@ public:
   /** Backtrace of the command that created this custom command.  */
   /** Backtrace of the command that created this custom command.  */
   cmListFileBacktrace const& GetBacktrace() const;
   cmListFileBacktrace const& GetBacktrace() const;
 
 
-  using ImplicitDependsPair = std::pair<std::string, std::string>;
-  class ImplicitDependsList : public std::vector<ImplicitDependsPair>
-  {
-  };
-  void SetImplicitDepends(ImplicitDependsList const&);
-  void AppendImplicitDepends(ImplicitDependsList const&);
-  ImplicitDependsList const& GetImplicitDepends() const;
+  void SetImplicitDepends(cmImplicitDependsList const&);
+  void AppendImplicitDepends(cmImplicitDependsList const&);
+  cmImplicitDependsList const& GetImplicitDepends() const;
 
 
   /** Set/Get whether this custom command should be given access to the
   /** Set/Get whether this custom command should be given access to the
       real console (if possible).  */
       real console (if possible).  */
@@ -99,7 +100,7 @@ private:
   std::vector<std::string> Depends;
   std::vector<std::string> Depends;
   cmCustomCommandLines CommandLines;
   cmCustomCommandLines CommandLines;
   cmListFileBacktrace Backtrace;
   cmListFileBacktrace Backtrace;
-  ImplicitDependsList ImplicitDepends;
+  cmImplicitDependsList ImplicitDepends;
   std::string Comment;
   std::string Comment;
   std::string WorkingDirectory;
   std::string WorkingDirectory;
   std::string Depfile;
   std::string Depfile;

+ 6 - 3
Source/cmGlobalVisualStudio8Generator.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmGlobalVisualStudio8Generator.h"
 #include "cmGlobalVisualStudio8Generator.h"
 
 
+#include "cmCustomCommand.h"
 #include "cmDocumentationEntry.h"
 #include "cmDocumentationEntry.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
@@ -191,11 +192,13 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
     // file as the main dependency because it would get
     // file as the main dependency because it would get
     // overwritten by the CreateVCProjBuildRule.
     // overwritten by the CreateVCProjBuildRule.
     // (this could be avoided with per-target source files)
     // (this could be avoided with per-target source files)
-    std::string no_main_dependency;
     std::vector<std::string> no_byproducts;
     std::vector<std::string> no_byproducts;
+    std::string no_main_dependency;
+    cmImplicitDependsList no_implicit_depends;
     if (cmSourceFile* file = mf->AddCustomCommandToOutput(
     if (cmSourceFile* file = mf->AddCustomCommandToOutput(
-          stamps, no_byproducts, listFiles, no_main_dependency, commandLines,
-          "Checking Build System", no_working_directory, true, false)) {
+          stamps, no_byproducts, listFiles, no_main_dependency,
+          no_implicit_depends, commandLines, "Checking Build System",
+          no_working_directory, true, false)) {
       gt->AddSource(file->ResolveFullPath());
       gt->AddSource(file->ResolveFullPath());
     } else {
     } else {
       cmSystemTools::Error("Error adding rule for " + stamps[0]);
       cmSystemTools::Error("Error adding rule for " + stamps[0]);

+ 27 - 6
Source/cmMakefile.cxx

@@ -945,6 +945,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
   const std::vector<std::string>& outputs,
   const std::vector<std::string>& outputs,
   const std::vector<std::string>& byproducts,
   const std::vector<std::string>& byproducts,
   const std::vector<std::string>& depends, const std::string& main_dependency,
   const std::vector<std::string>& depends, const std::string& main_dependency,
+  const cmImplicitDependsList& implicit_depends,
   const cmCustomCommandLines& commandLines, const char* comment,
   const cmCustomCommandLines& commandLines, const char* comment,
   const char* workingDir, bool replace, bool escapeOldStyle,
   const char* workingDir, bool replace, bool escapeOldStyle,
   bool uses_terminal, bool command_expand_lists, const std::string& depfile,
   bool uses_terminal, bool command_expand_lists, const std::string& depfile,
@@ -1029,6 +1030,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
       this, outputs, byproducts, depends2, commandLines, comment, workingDir);
       this, outputs, byproducts, depends2, commandLines, comment, workingDir);
     cc->SetEscapeOldStyle(escapeOldStyle);
     cc->SetEscapeOldStyle(escapeOldStyle);
     cc->SetEscapeAllowMakeVars(true);
     cc->SetEscapeAllowMakeVars(true);
+    cc->SetImplicitDepends(implicit_depends);
     cc->SetUsesTerminal(uses_terminal);
     cc->SetUsesTerminal(uses_terminal);
     cc->SetCommandExpandLists(command_expand_lists);
     cc->SetCommandExpandLists(command_expand_lists);
     cc->SetDepfile(depfile);
     cc->SetDepfile(depfile);
@@ -1087,10 +1089,11 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
   std::vector<std::string> outputs;
   std::vector<std::string> outputs;
   outputs.push_back(output);
   outputs.push_back(output);
   std::vector<std::string> no_byproducts;
   std::vector<std::string> no_byproducts;
+  cmImplicitDependsList no_implicit_depends;
   return this->AddCustomCommandToOutput(
   return this->AddCustomCommandToOutput(
-    outputs, no_byproducts, depends, main_dependency, commandLines, comment,
-    workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists,
-    depfile, job_pool);
+    outputs, no_byproducts, depends, main_dependency, no_implicit_depends,
+    commandLines, comment, workingDir, replace, escapeOldStyle, uses_terminal,
+    command_expand_lists, depfile, job_pool);
 }
 }
 
 
 void cmMakefile::AddCustomCommandOldStyle(
 void cmMakefile::AddCustomCommandOldStyle(
@@ -1151,6 +1154,23 @@ void cmMakefile::AddCustomCommandOldStyle(
   }
   }
 }
 }
 
 
+bool cmMakefile::AppendCustomCommandToOutput(
+  const std::string& output, const std::vector<std::string>& depends,
+  const cmImplicitDependsList& implicit_depends,
+  const cmCustomCommandLines& commandLines)
+{
+  // Lookup an existing command.
+  if (cmSourceFile* sf = this->GetSourceFileWithOutput(output)) {
+    if (cmCustomCommand* cc = sf->GetCustomCommand()) {
+      cc->AppendCommands(commandLines);
+      cc->AppendDepends(depends);
+      cc->AppendImplicitDepends(implicit_depends);
+      return true;
+    }
+  }
+  return false;
+}
+
 cmTarget* cmMakefile::AddUtilityCommand(
 cmTarget* cmMakefile::AddUtilityCommand(
   const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
   const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
   const std::vector<std::string>& depends, const char* workingDirectory,
   const std::vector<std::string>& depends, const char* workingDirectory,
@@ -1224,11 +1244,12 @@ cmTarget* cmMakefile::AddUtilityCommand(
     std::vector<std::string> forced;
     std::vector<std::string> forced;
     forced.push_back(force);
     forced.push_back(force);
     std::string no_main_dependency;
     std::string no_main_dependency;
+    cmImplicitDependsList no_implicit_depends;
     bool no_replace = false;
     bool no_replace = false;
     this->AddCustomCommandToOutput(
     this->AddCustomCommandToOutput(
-      forced, byproducts, depends, no_main_dependency, commandLines, comment,
-      workingDirectory, no_replace, escapeOldStyle, uses_terminal,
-      command_expand_lists, /*depfile=*/"", job_pool);
+      forced, byproducts, depends, no_main_dependency, no_implicit_depends,
+      commandLines, comment, workingDirectory, no_replace, escapeOldStyle,
+      uses_terminal, command_expand_lists, /*depfile=*/"", job_pool);
     cmSourceFile* sf = target->AddSourceCMP0049(force);
     cmSourceFile* sf = target->AddSourceCMP0049(force);
 
 
     // The output is not actually created so mark it symbolic.
     // The output is not actually created so mark it symbolic.

+ 6 - 0
Source/cmMakefile.h

@@ -42,6 +42,7 @@ class cmExportBuildFileGenerator;
 class cmFunctionBlocker;
 class cmFunctionBlocker;
 class cmGeneratorExpressionEvaluationFile;
 class cmGeneratorExpressionEvaluationFile;
 class cmGlobalGenerator;
 class cmGlobalGenerator;
+class cmImplicitDependsList;
 class cmInstallGenerator;
 class cmInstallGenerator;
 class cmMessenger;
 class cmMessenger;
 class cmSourceFile;
 class cmSourceFile;
@@ -184,6 +185,7 @@ public:
     const std::vector<std::string>& byproducts,
     const std::vector<std::string>& byproducts,
     const std::vector<std::string>& depends,
     const std::vector<std::string>& depends,
     const std::string& main_dependency,
     const std::string& main_dependency,
+    const cmImplicitDependsList& implicit_depends,
     const cmCustomCommandLines& commandLines, const char* comment,
     const cmCustomCommandLines& commandLines, const char* comment,
     const char* workingDir, bool replace = false, bool escapeOldStyle = true,
     const char* workingDir, bool replace = false, bool escapeOldStyle = true,
     bool uses_terminal = false, bool command_expand_lists = false,
     bool uses_terminal = false, bool command_expand_lists = false,
@@ -201,6 +203,10 @@ public:
                                 const std::string& source,
                                 const std::string& source,
                                 const cmCustomCommandLines& commandLines,
                                 const cmCustomCommandLines& commandLines,
                                 const char* comment);
                                 const char* comment);
+  bool AppendCustomCommandToOutput(
+    const std::string& output, const std::vector<std::string>& depends,
+    const cmImplicitDependsList& implicit_depends,
+    const cmCustomCommandLines& commandLines);
 
 
   /**
   /**
    * Add a define flag to the build.
    * Add a define flag to the build.

+ 6 - 4
Source/cmQtAutoGenInitializer.cxx

@@ -1166,10 +1166,12 @@ bool cmQtAutoGenInitializer::InitRccTargets()
         if (!this->Rcc.ExecutableTargetName.empty()) {
         if (!this->Rcc.ExecutableTargetName.empty()) {
           ccDepends.push_back(this->Rcc.ExecutableTargetName);
           ccDepends.push_back(this->Rcc.ExecutableTargetName);
         }
         }
-        makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
-                                           /*main_dependency*/ std::string(),
-                                           commandLines, ccComment.c_str(),
-                                           this->Dir.Work.c_str());
+        std::string no_main_dependency;
+        cmImplicitDependsList no_implicit_depends;
+        makefile->AddCustomCommandToOutput(
+          ccOutput, ccByproducts, ccDepends, no_main_dependency,
+          no_implicit_depends, commandLines, ccComment.c_str(),
+          this->Dir.Work.c_str());
       }
       }
       // Reconfigure when .qrc file changes
       // Reconfigure when .qrc file changes
       makefile->AddCMakeDependFile(qrc.QrcFile);
       makefile->AddCMakeDependFile(qrc.QrcFile);