瀏覽代碼

cmCommand refactor: cmUseMangledMesaCommand

Gabor Bencze 6 年之前
父節點
當前提交
524d721514
共有 3 個文件被更改,包括 17 次插入28 次删除
  1. 1 2
      Source/cmCommands.cxx
  2. 14 8
      Source/cmUseMangledMesaCommand.cxx
  3. 2 18
      Source/cmUseMangledMesaCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -208,8 +208,7 @@ void GetScriptingCommands(cmState* state)
     "build_name", cmBuildNameCommand, cmPolicies::CMP0036,
     "The build_name command should not be called; see CMP0036.");
   state->AddDisallowedCommand(
-    "use_mangled_mesa", cm::make_unique<cmUseMangledMesaCommand>(),
-    cmPolicies::CMP0030,
+    "use_mangled_mesa", cmUseMangledMesaCommand, cmPolicies::CMP0030,
     "The use_mangled_mesa command should not be called; see CMP0030.");
 
 #endif

+ 14 - 8
Source/cmUseMangledMesaCommand.cxx

@@ -5,26 +5,30 @@
 #include "cmsys/FStream.hxx"
 #include "cmsys/RegularExpression.hxx"
 
+#include "cmExecutionStatus.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
+namespace {
+void CopyAndFullPathMesaHeader(const std::string& source,
+                               const std::string& outdir);
+}
 
-bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
-                                          cmExecutionStatus&)
+bool cmUseMangledMesaCommand(std::vector<std::string> const& args,
+                             cmExecutionStatus& status)
 {
   // expected two arguments:
   // argument one: the full path to gl_mangle.h
   // argument two : directory for output of edited headers
   if (args.size() != 2) {
-    this->SetError("called with incorrect number of arguments");
+    status.SetError("called with incorrect number of arguments");
     return false;
   }
   const std::string& inputDir = args[0];
   std::string glh = cmStrCat(inputDir, "/gl.h");
   if (!cmSystemTools::FileExists(glh)) {
     std::string e = cmStrCat("Bad path to Mesa, could not find: ", glh, ' ');
-    this->SetError(e);
+    status.SetError(e);
     return false;
   }
   const std::string& destDir = args[1];
@@ -37,14 +41,15 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
   cmSystemTools::MakeDirectory(destDir);
   for (std::string const& f : files) {
     std::string path = cmStrCat(inputDir, '/', f);
-    this->CopyAndFullPathMesaHeader(path, destDir);
+    CopyAndFullPathMesaHeader(path, destDir);
   }
 
   return true;
 }
 
-void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(
-  const std::string& source, const std::string& outdir)
+namespace {
+void CopyAndFullPathMesaHeader(const std::string& source,
+                               const std::string& outdir)
 {
   std::string dir;
   std::string file;
@@ -96,3 +101,4 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(
   cmSystemTools::CopyFileIfDifferent(tempOutputFile, outFile);
   cmSystemTools::RemoveFile(tempOutputFile);
 }
+}

+ 2 - 18
Source/cmUseMangledMesaCommand.h

@@ -8,25 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-class cmUseMangledMesaCommand : public cmCommand
-{
-public:
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmUseMangledMesaCommand>();
-  }
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) override;
-
-protected:
-  void CopyAndFullPathMesaHeader(const std::string& source,
-                                 const std::string& outdir);
-};
+bool cmUseMangledMesaCommand(std::vector<std::string> const& args,
+                             cmExecutionStatus& status);
 
 #endif