Forráskód Böngészése

cmBuildCommand: Port away from cmCommand

Ref: #19499
Regina Pfeifer 6 éve
szülő
commit
f0ecb12398
3 módosított fájl, 41 hozzáadás és 78 törlés
  1. 38 37
      Source/cmBuildCommand.cxx
  2. 2 40
      Source/cmBuildCommand.h
  3. 1 1
      Source/cmCommands.cxx

+ 38 - 37
Source/cmBuildCommand.cxx

@@ -2,32 +2,21 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmBuildCommand.h"
 
-#include <sstream>
-
+#include "cmExecutionStatus.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmStateTypes.h"
+#include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
-
-bool cmBuildCommand::InitialPass(std::vector<std::string> const& args,
-                                 cmExecutionStatus&)
-{
-  // Support the legacy signature of the command:
-  //
-  if (2 == args.size()) {
-    return this->TwoArgsSignature(args);
-  }
-
-  return this->MainSignature(args);
-}
+namespace {
 
-bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
+bool MainSignature(std::vector<std::string> const& args,
+                   cmExecutionStatus& status)
 {
   if (args.empty()) {
-    this->SetError("requires at least one argument naming a CMake variable");
+    status.SetError("requires at least one argument naming a CMake variable");
     return false;
   }
 
@@ -63,9 +52,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
       doing = DoingNone;
       target = args[i];
     } else {
-      std::ostringstream e;
-      e << "unknown argument \"" << args[i] << "\"";
-      this->SetError(e.str());
+      status.SetError(cmStrCat("unknown argument \"", args[i], "\""));
       return false;
     }
   }
@@ -82,30 +69,32 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
     configuration = "Release";
   }
 
+  cmMakefile& mf = status.GetMakefile();
   if (!project_name.empty()) {
-    this->Makefile->IssueMessage(
-      MessageType::AUTHOR_WARNING,
-      "Ignoring PROJECT_NAME option because it has no effect.");
+    mf.IssueMessage(MessageType::AUTHOR_WARNING,
+                    "Ignoring PROJECT_NAME option because it has no effect.");
   }
 
-  std::string makecommand =
-    this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
-      target, configuration, "", this->Makefile->IgnoreErrorsCMP0061());
+  std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
+    target, configuration, "", mf.IgnoreErrorsCMP0061());
 
-  this->Makefile->AddDefinition(variable, makecommand);
+  mf.AddDefinition(variable, makecommand);
 
   return true;
 }
 
-bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
+bool TwoArgsSignature(std::vector<std::string> const& args,
+                      cmExecutionStatus& status)
 {
   if (args.size() < 2) {
-    this->SetError("called with less than two arguments");
+    status.SetError("called with less than two arguments");
     return false;
   }
 
+  cmMakefile& mf = status.GetMakefile();
+
   std::string const& define = args[0];
-  const char* cacheValue = this->Makefile->GetDefinition(define);
+  const char* cacheValue = mf.GetDefinition(define);
 
   std::string configType;
   if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) ||
@@ -113,16 +102,28 @@ bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
     configType = "Release";
   }
 
-  std::string makecommand =
-    this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
-      "", configType, "", this->Makefile->IgnoreErrorsCMP0061());
+  std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand(
+    "", configType, "", mf.IgnoreErrorsCMP0061());
 
   if (cacheValue) {
     return true;
   }
-  this->Makefile->AddCacheDefinition(define, makecommand.c_str(),
-                                     "Command used to build entire project "
-                                     "from the command line.",
-                                     cmStateEnums::STRING);
+  mf.AddCacheDefinition(define, makecommand.c_str(),
+                        "Command used to build entire project "
+                        "from the command line.",
+                        cmStateEnums::STRING);
   return true;
 }
+
+} // namespace
+
+bool cmBuildCommand(std::vector<std::string> const& args,
+                    cmExecutionStatus& status)
+{
+  // Support the legacy signature of the command:
+  if (args.size() == 2) {
+    return TwoArgsSignature(args, status);
+  }
+
+  return MainSignature(args, status);
+}

+ 2 - 40
Source/cmBuildCommand.h

@@ -8,47 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmBuildCommand
- * \brief build_command command
- *
- * cmBuildCommand implements the build_command CMake command
- */
-class cmBuildCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmBuildCommand>();
-  }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) override;
-
-  /**
-   * The primary command signature with optional, KEYWORD-based args.
-   */
-  virtual bool MainSignature(std::vector<std::string> const& args);
-
-  /**
-   * Legacy "exactly 2 args required" signature.
-   */
-  virtual bool TwoArgsSignature(std::vector<std::string> const& args);
-
-private:
-  bool IgnoreErrors() const;
-};
+bool cmBuildCommand(std::vector<std::string> const& args,
+                    cmExecutionStatus& status);
 
 #endif

+ 1 - 1
Source/cmCommands.cxx

@@ -222,7 +222,7 @@ void GetProjectCommands(cmState* state)
   state->AddBuiltinCommand("add_library", cmAddLibraryCommand);
   state->AddBuiltinCommand("add_subdirectory", cmAddSubDirectoryCommand);
   state->AddBuiltinCommand("add_test", cmAddTestCommand);
-  state->AddBuiltinCommand("build_command", cm::make_unique<cmBuildCommand>());
+  state->AddBuiltinCommand("build_command", cmBuildCommand);
   state->AddBuiltinCommand("create_test_sourcelist",
                            cm::make_unique<cmCreateTestSourceList>());
   state->AddBuiltinCommand("define_property",