Browse Source

cmCommand refactor: cmMakeDirectoryCommand

Gabor Bencze 6 years ago
parent
commit
5b40a872dd
3 changed files with 10 additions and 32 deletions
  1. 1 2
      Source/cmCommands.cxx
  2. 6 7
      Source/cmMakeDirectoryCommand.cxx
  3. 3 23
      Source/cmMakeDirectoryCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -146,8 +146,7 @@ void GetScriptingCommands(cmState* state)
   state->AddBuiltinCommand("include_guard", cmIncludeGuardCommand);
   state->AddBuiltinCommand("list", cmListCommand);
   state->AddBuiltinCommand("macro", cmMacroCommand);
-  state->AddBuiltinCommand("make_directory",
-                           cm::make_unique<cmMakeDirectoryCommand>());
+  state->AddBuiltinCommand("make_directory", cmMakeDirectoryCommand);
   state->AddBuiltinCommand("mark_as_advanced",
                            cm::make_unique<cmMarkAsAdvancedCommand>());
   state->AddBuiltinCommand("math", cm::make_unique<cmMathCommand>());

+ 6 - 7
Source/cmMakeDirectoryCommand.cxx

@@ -2,23 +2,22 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmMakeDirectoryCommand.h"
 
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
-
 // cmMakeDirectoryCommand
-bool cmMakeDirectoryCommand::InitialPass(std::vector<std::string> const& args,
-                                         cmExecutionStatus&)
+bool cmMakeDirectoryCommand(std::vector<std::string> const& args,
+                            cmExecutionStatus& status)
 {
   if (args.size() != 1) {
-    this->SetError("called with incorrect number of arguments");
+    status.SetError("called with incorrect number of arguments");
     return false;
   }
-  if (!this->Makefile->CanIWriteThisFile(args[0])) {
+  if (!status.GetMakefile().CanIWriteThisFile(args[0])) {
     std::string e = "attempted to create a directory: " + args[0] +
       " into a source directory.";
-    this->SetError(e);
+    status.SetError(e);
     cmSystemTools::SetFatalErrorOccured();
     return false;
   }

+ 3 - 23
Source/cmMakeDirectoryCommand.h

@@ -8,13 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmMakeDirectoryCommand
+/**
  * \brief Specify auxiliary source code directories.
  *
  * cmMakeDirectoryCommand specifies source code directories
@@ -23,23 +19,7 @@ class cmExecutionStatus;
  * A side effect of this command is to create a subdirectory in the build
  * directory structure.
  */
-class cmMakeDirectoryCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmMakeDirectoryCommand>();
-  }
-
-  /**
-   * 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;
-};
+bool cmMakeDirectoryCommand(std::vector<std::string> const& args,
+                            cmExecutionStatus& status);
 
 #endif