Browse Source

cmCTest*Command:: Use cm::optional for keyword argument presence

Brad King 3 years ago
parent
commit
2586afa31b

+ 2 - 11
Source/CTest/cmCTestCoverageCommand.cxx

@@ -4,8 +4,6 @@
 
 #include <set>
 
-#include <cm/string_view>
-#include <cmext/algorithm>
 #include <cmext/string_view>
 
 #include "cmCTest.h"
@@ -19,13 +17,6 @@ void cmCTestCoverageCommand::BindArguments()
   this->Bind("LABELS"_s, this->Labels);
 }
 
-void cmCTestCoverageCommand::CheckArguments(
-  std::vector<cm::string_view> const& keywords)
-{
-  this->LabelsMentioned =
-    !this->Labels.empty() || cm::contains(keywords, "LABELS"_s);
-}
-
 cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
 {
   this->CTest->SetCTestConfigurationFromCMakeVariable(
@@ -37,9 +28,9 @@ cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
   handler->Initialize();
 
   // If a LABELS option was given, select only files with the labels.
-  if (this->LabelsMentioned) {
+  if (this->Labels) {
     handler->SetLabelFilter(
-      std::set<std::string>(this->Labels.begin(), this->Labels.end()));
+      std::set<std::string>(this->Labels->begin(), this->Labels->end()));
   }
 
   handler->SetQuiet(this->Quiet);

+ 2 - 4
Source/CTest/cmCTestCoverageCommand.h

@@ -9,7 +9,7 @@
 #include <vector>
 
 #include <cm/memory>
-#include <cm/string_view>
+#include <cm/optional>
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCommand.h"
@@ -42,9 +42,7 @@ public:
 
 protected:
   void BindArguments() override;
-  void CheckArguments(std::vector<cm::string_view> const& keywords) override;
   cmCTestGenericHandler* InitializeHandler() override;
 
-  bool LabelsMentioned;
-  std::vector<std::string> Labels;
+  cm::optional<std::vector<std::string>> Labels;
 };

+ 3 - 4
Source/CTest/cmCTestHandlerCommand.cxx

@@ -82,11 +82,10 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
 
   // Process input arguments.
   std::vector<std::string> unparsedArguments;
-  std::vector<cm::string_view> keywordsMissingValue;
   std::vector<cm::string_view> parsedKeywords;
-  this->Parse(args, &unparsedArguments, &keywordsMissingValue,
+  this->Parse(args, &unparsedArguments, /*keywordsMissingValue=*/nullptr,
               &parsedKeywords);
-  this->CheckArguments(keywordsMissingValue);
+  this->CheckArguments();
 
   std::sort(parsedKeywords.begin(), parsedKeywords.end());
   auto it = std::adjacent_find(parsedKeywords.begin(), parsedKeywords.end());
@@ -243,6 +242,6 @@ void cmCTestHandlerCommand::BindArguments()
   this->Bind("SUBMIT_INDEX"_s, this->SubmitIndex);
 }
 
-void cmCTestHandlerCommand::CheckArguments(std::vector<cm::string_view> const&)
+void cmCTestHandlerCommand::CheckArguments()
 {
 }

+ 1 - 3
Source/CTest/cmCTestHandlerCommand.h

@@ -7,8 +7,6 @@
 #include <string>
 #include <vector>
 
-#include <cm/string_view>
-
 #include "cmArgumentParser.h"
 #include "cmCTestCommand.h"
 
@@ -44,7 +42,7 @@ protected:
 
   // Command argument handling.
   virtual void BindArguments();
-  virtual void CheckArguments(std::vector<cm::string_view> const& keywords);
+  virtual void CheckArguments();
 
   bool Append = false;
   bool Quiet = false;

+ 31 - 35
Source/CTest/cmCTestSubmitCommand.cxx

@@ -7,9 +7,7 @@
 #include <utility>
 
 #include <cm/memory>
-#include <cm/string_view>
 #include <cm/vector>
-#include <cmext/algorithm>
 #include <cmext/string_view>
 
 #include "cmCTest.h"
@@ -88,7 +86,7 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
   // If FILES are given, but not PARTS, only the FILES are submitted
   // and *no* PARTS are submitted.
   //  (This is why we select the empty "noParts" set in the
-  //   FilesMentioned block below...)
+  //   if(this->Files) block below...)
   //
   // If PARTS are given, only the selected PARTS are submitted.
   //
@@ -97,7 +95,7 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
 
   // If given explicit FILES to submit, pass them to the handler.
   //
-  if (this->FilesMentioned) {
+  if (this->Files) {
     // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
     // were also explicitly mentioned, they will be selected below...
     // But FILES with no PARTS mentioned should just submit the FILES
@@ -105,14 +103,14 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
     //
     handler->SelectParts(std::set<cmCTest::Part>());
     handler->SelectFiles(
-      std::set<std::string>(this->Files.begin(), this->Files.end()));
+      std::set<std::string>(this->Files->begin(), this->Files->end()));
   }
 
   // If a PARTS option was given, select only the named parts for submission.
   //
-  if (this->PartsMentioned) {
+  if (this->Parts) {
     auto parts =
-      cmMakeRange(this->Parts).transform([this](std::string const& arg) {
+      cmMakeRange(*(this->Parts)).transform([this](std::string const& arg) {
         return this->CTest->GetPartFromName(arg);
       });
     handler->SelectParts(std::set<cmCTest::Part>(parts.begin(), parts.end()));
@@ -173,33 +171,31 @@ void cmCTestSubmitCommand::BindArguments()
   this->cmCTestHandlerCommand::BindArguments();
 }
 
-void cmCTestSubmitCommand::CheckArguments(
-  std::vector<cm::string_view> const& keywords)
+void cmCTestSubmitCommand::CheckArguments()
 {
-  this->PartsMentioned =
-    !this->Parts.empty() || cm::contains(keywords, "PARTS"_s);
-  this->FilesMentioned =
-    !this->Files.empty() || cm::contains(keywords, "FILES"_s);
-
-  cm::erase_if(this->Parts, [this](std::string const& arg) -> bool {
-    cmCTest::Part p = this->CTest->GetPartFromName(arg);
-    if (p == cmCTest::PartCount) {
-      std::ostringstream e;
-      e << "Part name \"" << arg << "\" is invalid.";
-      this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
-      return true;
-    }
-    return false;
-  });
-
-  cm::erase_if(this->Files, [this](std::string const& arg) -> bool {
-    if (!cmSystemTools::FileExists(arg)) {
-      std::ostringstream e;
-      e << "File \"" << arg << "\" does not exist. Cannot submit "
-        << "a non-existent file.";
-      this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
-      return true;
-    }
-    return false;
-  });
+  if (this->Parts) {
+    cm::erase_if(*(this->Parts), [this](std::string const& arg) -> bool {
+      cmCTest::Part p = this->CTest->GetPartFromName(arg);
+      if (p == cmCTest::PartCount) {
+        std::ostringstream e;
+        e << "Part name \"" << arg << "\" is invalid.";
+        this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+        return true;
+      }
+      return false;
+    });
+  }
+
+  if (this->Files) {
+    cm::erase_if(*(this->Files), [this](std::string const& arg) -> bool {
+      if (!cmSystemTools::FileExists(arg)) {
+        std::ostringstream e;
+        e << "File \"" << arg << "\" does not exist. Cannot submit "
+          << "a non-existent file.";
+        this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+        return true;
+      }
+      return false;
+    });
+  }
 }

+ 4 - 6
Source/CTest/cmCTestSubmitCommand.h

@@ -8,7 +8,7 @@
 #include <string>
 #include <vector>
 
-#include <cm/string_view>
+#include <cm/optional>
 
 #include "cmCTestHandlerCommand.h"
 
@@ -37,13 +37,11 @@ public:
 
 protected:
   void BindArguments() override;
-  void CheckArguments(std::vector<cm::string_view> const& keywords) override;
+  void CheckArguments() override;
   cmCTestGenericHandler* InitializeHandler() override;
 
   bool CDashUpload = false;
-  bool FilesMentioned = false;
   bool InternalTest = false;
-  bool PartsMentioned = false;
 
   std::string BuildID;
   std::string CDashUploadFile;
@@ -52,7 +50,7 @@ protected:
   std::string RetryDelay;
   std::string SubmitURL;
 
-  std::vector<std::string> Files;
+  cm::optional<std::vector<std::string>> Files;
   std::vector<std::string> HttpHeaders;
-  std::vector<std::string> Parts;
+  cm::optional<std::vector<std::string>> Parts;
 };

+ 1 - 2
Source/CTest/cmCTestUploadCommand.cxx

@@ -5,7 +5,6 @@
 #include <set>
 #include <sstream>
 
-#include <cm/string_view>
 #include <cm/vector>
 #include <cmext/string_view>
 
@@ -22,7 +21,7 @@ void cmCTestUploadCommand::BindArguments()
   this->Bind("CAPTURE_CMAKE_ERROR"_s, this->CaptureCMakeError);
 }
 
-void cmCTestUploadCommand::CheckArguments(std::vector<cm::string_view> const&)
+void cmCTestUploadCommand::CheckArguments()
 {
   cm::erase_if(this->Files, [this](std::string const& arg) -> bool {
     if (!cmSystemTools::FileExists(arg)) {

+ 1 - 2
Source/CTest/cmCTestUploadCommand.h

@@ -9,7 +9,6 @@
 #include <vector>
 
 #include <cm/memory>
-#include <cm/string_view>
 
 #include "cmCTestHandlerCommand.h"
 #include "cmCommand.h"
@@ -43,7 +42,7 @@ public:
 
 protected:
   void BindArguments() override;
-  void CheckArguments(std::vector<cm::string_view> const&) override;
+  void CheckArguments() override;
   cmCTestGenericHandler* InitializeHandler() override;
 
   std::vector<std::string> Files;