Jelajahi Sumber

cmCommand refactor: cmSetCommand

Gabor Bencze 6 tahun lalu
induk
melakukan
b3aa789630
3 mengubah file dengan 18 tambahan dan 39 penghapusan
  1. 1 1
      Source/cmCommands.cxx
  2. 14 15
      Source/cmSetCommand.cxx
  3. 3 23
      Source/cmSetCommand.h

+ 1 - 1
Source/cmCommands.cxx

@@ -154,7 +154,7 @@ void GetScriptingCommands(cmState* state)
   state->AddBuiltinCommand("cmake_parse_arguments", cmParseArgumentsCommand);
   state->AddBuiltinCommand("return", cmReturnCommand);
   state->AddBuiltinCommand("separate_arguments", cmSeparateArgumentsCommand);
-  state->AddBuiltinCommand("set", cm::make_unique<cmSetCommand>());
+  state->AddBuiltinCommand("set", cmSetCommand);
   state->AddBuiltinCommand("set_directory_properties",
                            cm::make_unique<cmSetDirectoryPropertiesCommand>());
   state->AddBuiltinCommand("set_property",

+ 14 - 15
Source/cmSetCommand.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmSetCommand.h"
 
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmRange.h"
@@ -10,14 +11,12 @@
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
-
 // cmSetCommand
-bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
-                               cmExecutionStatus&)
+bool cmSetCommand(std::vector<std::string> const& args,
+                  cmExecutionStatus& status)
 {
   if (args.empty()) {
-    this->SetError("called with incorrect number of arguments");
+    status.SetError("called with incorrect number of arguments");
     return false;
   }
 
@@ -45,7 +44,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
         std::string m = "Only the first value argument is used when setting "
                         "an environment variable.  Argument '" +
           args[2] + "' and later are unused.";
-        this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
+        status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, m);
       }
       return true;
     }
@@ -59,13 +58,13 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
 
   // SET (VAR) // Removes the definition of VAR.
   if (args.size() == 1) {
-    this->Makefile->RemoveDefinition(variable);
+    status.GetMakefile().RemoveDefinition(variable);
     return true;
   }
   // SET (VAR PARENT_SCOPE) // Removes the definition of VAR
   // in the parent scope.
   if (args.size() == 2 && args.back() == "PARENT_SCOPE") {
-    this->Makefile->RaiseScope(variable, nullptr);
+    status.GetMakefile().RaiseScope(variable, nullptr);
     return true;
   }
 
@@ -106,7 +105,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
   value = cmJoin(cmMakeRange(args).advance(1).retreat(ignoreLastArgs), ";");
 
   if (parentScope) {
-    this->Makefile->RaiseScope(variable, value.c_str());
+    status.GetMakefile().RaiseScope(variable, value.c_str());
     return true;
   }
 
@@ -116,7 +115,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
   if ((args.back() == "CACHE") ||
       (args.size() > 1 && args[args.size() - 2] == "CACHE") ||
       (force && !cache)) {
-    this->SetError("given invalid arguments for CACHE mode.");
+    status.SetError("given invalid arguments for CACHE mode.");
     return false;
   }
 
@@ -125,7 +124,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
     if (!cmState::StringToCacheEntryType(args[cacheStart + 1].c_str(), type)) {
       std::string m = "implicitly converting '" + args[cacheStart + 1] +
         "' to 'STRING' type.";
-      this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
+      status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, m);
       // Setting this may not be required, since it's
       // initialized as a string. Keeping this here to
       // ensure that the type is actually converting to a string.
@@ -135,7 +134,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
   }
 
   // see if this is already in the cache
-  cmState* state = this->Makefile->GetState();
+  cmState* state = status.GetMakefile().GetState();
   const char* existingValue = state->GetCacheEntryValue(variable);
   if (existingValue &&
       (state->GetCacheEntryType(variable) != cmStateEnums::UNINITIALIZED)) {
@@ -150,11 +149,11 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
 
   // if it is meant to be in the cache then define it in the cache
   if (cache) {
-    this->Makefile->AddCacheDefinition(variable, value.c_str(), docstring,
-                                       type, force);
+    status.GetMakefile().AddCacheDefinition(variable, value.c_str(), docstring,
+                                            type, force);
   } else {
     // add the definition
-    this->Makefile->AddDefinition(variable, value);
+    status.GetMakefile().AddDefinition(variable, value);
   }
   return true;
 }

+ 3 - 23
Source/cmSetCommand.h

@@ -8,34 +8,14 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmSetCommand
+/**
  * \brief Set a CMAKE variable
  *
  * cmSetCommand sets a variable to a value with expansion.
  */
-class cmSetCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmSetCommand>();
-  }
-
-  /**
-   * 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 cmSetCommand(std::vector<std::string> const& args,
+                  cmExecutionStatus& status);
 
 #endif