Browse Source

Merge topic 'ctest-command-line'

c0c4d48ba2 cmCTest: Use cmCommandLineArgument command-line parsing infrastructure
67dc003467 cmCTest: Add missing const
9b09c3733a cmCTestBuildAndTestHandler: Simplify constructor
30ece11e66 cmCommandLineArgument: Do not treat negative numbers as flags

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !9901
Brad King 1 năm trước cách đây
mục cha
commit
f521d20cb4

+ 1 - 97
Source/CTest/cmCTestBuildAndTestHandler.cxx

@@ -3,7 +3,6 @@
 #include "cmCTestBuildAndTestHandler.h"
 
 #include <chrono>
-#include <cstdlib>
 #include <cstring>
 #include <ratio>
 
@@ -20,13 +19,7 @@
 
 struct cmMessageMetadata;
 
-cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
-{
-  this->BuildTwoConfig = false;
-  this->BuildNoClean = false;
-  this->BuildNoCMake = false;
-  this->Timeout = cmDuration::zero();
-}
+cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler() = default;
 
 void cmCTestBuildAndTestHandler::Initialize()
 {
@@ -362,92 +355,3 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
   }
   return retval;
 }
-
-int cmCTestBuildAndTestHandler::ProcessCommandLineArguments(
-  const std::string& currentArg, size_t& idx,
-  const std::vector<std::string>& allArgs, bool& validArg)
-{
-  bool buildAndTestArg = true;
-  // --build-and-test options
-  if (cmHasLiteralPrefix(currentArg, "--build-and-test") &&
-      idx < allArgs.size() - 1) {
-    if (idx + 2 < allArgs.size()) {
-      idx++;
-      this->SourceDir = allArgs[idx];
-      idx++;
-      this->BinaryDir = allArgs[idx];
-      // dir must exist before CollapseFullPath is called
-      cmSystemTools::MakeDirectory(this->BinaryDir);
-      this->BinaryDir = cmSystemTools::CollapseFullPath(this->BinaryDir);
-      this->SourceDir = cmSystemTools::CollapseFullPath(this->SourceDir);
-    } else {
-      cmCTestLog(this->CTest, ERROR_MESSAGE,
-                 "--build-and-test must have source and binary dir"
-                   << std::endl);
-      return 0;
-    }
-  } else if (cmHasLiteralPrefix(currentArg, "--build-target") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildTargets.push_back(allArgs[idx]);
-  } else if (cmHasLiteralPrefix(currentArg, "--build-nocmake")) {
-    this->BuildNoCMake = true;
-  } else if (cmHasLiteralPrefix(currentArg, "--build-run-dir") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildRunDir = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--build-two-config")) {
-    this->BuildTwoConfig = true;
-  } else if (cmHasLiteralPrefix(currentArg, "--build-exe-dir") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->ExecutableDirectory = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--test-timeout") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->Timeout = cmDuration(atof(allArgs[idx].c_str()));
-  } else if (currentArg == "--build-generator" && idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildGenerator = allArgs[idx];
-  } else if (currentArg == "--build-generator-platform" &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildGeneratorPlatform = allArgs[idx];
-  } else if (currentArg == "--build-generator-toolset" &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildGeneratorToolset = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--build-project") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildProject = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--build-makeprogram") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->BuildMakeProgram = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--build-config-sample") &&
-             idx < allArgs.size() - 1) {
-    idx++;
-    this->ConfigSample = allArgs[idx];
-  } else if (cmHasLiteralPrefix(currentArg, "--build-noclean")) {
-    this->BuildNoClean = true;
-  } else if (cmHasLiteralPrefix(currentArg, "--build-options")) {
-    while (idx + 1 < allArgs.size() && allArgs[idx + 1] != "--build-target" &&
-           allArgs[idx + 1] != "--test-command") {
-      ++idx;
-      this->BuildOptions.push_back(allArgs[idx]);
-    }
-  } else if (cmHasLiteralPrefix(currentArg, "--test-command") &&
-             idx < allArgs.size() - 1) {
-    ++idx;
-    this->TestCommand = allArgs[idx];
-    while (idx + 1 < allArgs.size()) {
-      ++idx;
-      this->TestCommandArgs.push_back(allArgs[idx]);
-    }
-  } else {
-    buildAndTestArg = false;
-  }
-  validArg = validArg || buildAndTestArg;
-  return 1;
-}

+ 6 - 10
Source/CTest/cmCTestBuildAndTestHandler.h

@@ -4,7 +4,6 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include <cstddef>
 #include <sstream>
 #include <string>
 #include <vector>
@@ -28,11 +27,6 @@ public:
    */
   int ProcessHandler() override;
 
-  //! Set all the build and test arguments
-  int ProcessCommandLineArguments(const std::string& currentArg, size_t& idx,
-                                  const std::vector<std::string>& allArgs,
-                                  bool& validArg) override;
-
   /*
    * Get the output variable
    */
@@ -54,18 +48,20 @@ protected:
   std::string BuildGeneratorPlatform;
   std::string BuildGeneratorToolset;
   std::vector<std::string> BuildOptions;
-  bool BuildTwoConfig;
+  bool BuildTwoConfig = false;
   std::string BuildMakeProgram;
   std::string ConfigSample;
   std::string SourceDir;
   std::string BinaryDir;
   std::string BuildProject;
   std::string TestCommand;
-  bool BuildNoClean;
+  bool BuildNoClean = false;
   std::string BuildRunDir;
   std::string ExecutableDirectory;
   std::vector<std::string> TestCommandArgs;
   std::vector<std::string> BuildTargets;
-  bool BuildNoCMake;
-  cmDuration Timeout;
+  bool BuildNoCMake = false;
+  cmDuration Timeout = cmDuration::zero();
+
+  friend class cmCTest;
 };

+ 0 - 11
Source/CTest/cmCTestGenericHandler.h

@@ -4,7 +4,6 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include <cstddef>
 #include <map>
 #include <string>
 #include <vector>
@@ -43,16 +42,6 @@ public:
    */
   virtual int ProcessHandler() = 0;
 
-  /**
-   * Process command line arguments that are applicable for the handler
-   */
-  virtual int ProcessCommandLineArguments(
-    const std::string& /*currentArg*/, size_t& /*idx*/,
-    const std::vector<std::string>& /*allArgs*/, bool& /*valid*/)
-  {
-    return 1;
-  }
-
   /**
    * Initialize handler
    */

+ 0 - 14
Source/CTest/cmCTestSubmitHandler.cxx

@@ -139,20 +139,6 @@ void cmCTestSubmitHandler::Initialize()
   this->Files.clear();
 }
 
-int cmCTestSubmitHandler::ProcessCommandLineArguments(
-  const std::string& currentArg, size_t& idx,
-  const std::vector<std::string>& allArgs, bool& validArg)
-{
-  if (cmHasLiteralPrefix(currentArg, "--http-header") &&
-      idx < allArgs.size() - 1) {
-    ++idx;
-    this->HttpHeaders.push_back(allArgs[idx]);
-    this->CommandLineHttpHeaders.push_back(allArgs[idx]);
-    validArg = true;
-  }
-  return 1;
-}
-
 bool cmCTestSubmitHandler::SubmitUsingHTTP(
   const std::string& localprefix, const std::vector<std::string>& files,
   const std::string& remoteprefix, const std::string& url)

+ 6 - 6
Source/CTest/cmCTestSubmitHandler.h

@@ -4,7 +4,6 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include <cstddef>
 #include <iosfwd>
 #include <set>
 #include <string>
@@ -34,11 +33,6 @@ public:
 
   void Initialize() override;
 
-  //! Set all the submit arguments
-  int ProcessCommandLineArguments(const std::string& currentArg, size_t& idx,
-                                  const std::vector<std::string>& allArgs,
-                                  bool& validArg) override;
-
   /** Specify a set of parts (by name) to submit.  */
   void SelectParts(std::set<cmCTest::Part> const& parts);
 
@@ -48,6 +42,12 @@ public:
   // handle the cdash file upload protocol
   int HandleCDashUploadFile(std::string const& file, std::string const& type);
 
+  void AddCommandLineHttpHeader(std::string const& h)
+  {
+    this->HttpHeaders.push_back(h);
+    this->CommandLineHttpHeaders.push_back(h);
+  }
+
   void SetHttpHeaders(std::vector<std::string> const& v)
   {
     if (this->CommandLineHttpHeaders.empty()) {

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 700 - 503
Source/cmCTest.cxx


+ 2 - 20
Source/cmCTest.h

@@ -486,10 +486,10 @@ private:
   int Initialize(const std::string& binary_dir, cmCTestStartCommand* command);
 
   /** parse the option after -D and convert it into the appropriate steps */
-  bool AddTestsForDashboardType(std::string& targ);
+  bool AddTestsForDashboardType(std::string const& targ);
 
   /** read as "emit an error message for an unknown -D value" */
-  void ErrorMessageUnknownDashDValue(std::string& val);
+  void ErrorMessageUnknownDashDValue(std::string const& val);
 
   /** add a variable definition from a command line -D value */
   bool AddVariableDefinition(const std::string& arg);
@@ -497,10 +497,6 @@ private:
   /** set command line arguments read from a test preset */
   bool SetArgsFromPreset(const std::string& presetName, bool listPresets);
 
-  /** parse and process most common command line arguments */
-  bool HandleCommandLineArguments(size_t& i, std::vector<std::string>& args,
-                                  std::string& errormsg);
-
 #if !defined(_WIN32)
   /** returns true iff the console supports progress output */
   static bool ConsoleIsNotDumb();
@@ -512,10 +508,6 @@ private:
   /** returns true iff the console supports colored output */
   static bool ColoredOutputSupportedByConsole();
 
-  /** handle the -S -SP and -SR arguments */
-  bool HandleScriptArguments(size_t& i, std::vector<std::string>& args,
-                             bool& SRArgumentSpecified);
-
   /** Reread the configuration file */
   bool UpdateCTestConfiguration();
 
@@ -530,16 +522,6 @@ private:
   /** Output errors from a test */
   void OutputTestErrors(std::vector<char> const& process_output);
 
-  /** Handle the --test-action command line argument */
-  bool HandleTestActionArgument(const char* ctestExec, size_t& i,
-                                const std::vector<std::string>& args,
-                                bool& validArg);
-
-  /** Handle the --test-model command line argument */
-  bool HandleTestModelArgument(const char* ctestExec, size_t& i,
-                               const std::vector<std::string>& args,
-                               bool& validArg);
-
   int RunCMakeAndTest(std::string* output);
   int ExecuteTests();
 

+ 14 - 5
Source/cmCommandLineArgument.h

@@ -2,7 +2,10 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #pragma once
 
+#include <cctype>
+
 #include <cm/optional>
+#include <cm/string_view>
 
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
@@ -126,7 +129,7 @@ struct cmCommandLineArgument
       if (input.size() == this->Name.size()) {
         auto nextValueIndex = index + 1;
         if (nextValueIndex >= allArgs.size() ||
-            allArgs[nextValueIndex][0] == '-') {
+            IsFlag(allArgs[nextValueIndex])) {
           if (this->Type == Values::ZeroOrOne) {
             parseState =
               this->StoreCall(std::string{}, std::forward<CallState>(state)...)
@@ -153,8 +156,8 @@ struct cmCommandLineArgument
       }
     } else if (this->Type == Values::Two) {
       if (input.size() == this->Name.size()) {
-        if (index + 2 >= allArgs.size() || allArgs[index + 1][0] == '-' ||
-            allArgs[index + 2][0] == '-') {
+        if (index + 2 >= allArgs.size() || IsFlag(allArgs[index + 1]) ||
+            IsFlag(allArgs[index + 2])) {
           parseState = ParseMode::ValueError;
         } else {
           index += 2;
@@ -169,12 +172,12 @@ struct cmCommandLineArgument
       if (input.size() == this->Name.size()) {
         auto nextValueIndex = index + 1;
         if (nextValueIndex >= allArgs.size() ||
-            allArgs[nextValueIndex][0] == '-') {
+            IsFlag(allArgs[nextValueIndex])) {
           parseState = ParseMode::ValueError;
         } else {
           std::string buffer = allArgs[nextValueIndex++];
           while (nextValueIndex < allArgs.size() &&
-                 allArgs[nextValueIndex][0] != '-') {
+                 !IsFlag(allArgs[nextValueIndex])) {
             buffer = cmStrCat(buffer, ";", allArgs[nextValueIndex++]);
           }
           parseState =
@@ -281,4 +284,10 @@ private:
     }
     return std::string(possible_value);
   }
+
+  static bool IsFlag(cm::string_view arg)
+  {
+    return !arg.empty() && arg[0] == '-' &&
+      !(arg.size() >= 2 && std::isdigit(arg[1]));
+  }
 };

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác