cmCTest: Use cmCommandLineArgument command-line parsing infrastructure

This commit is contained in:
Brad King committed 2024-10-14 12:12:51 -04:00
1 parent 67dc003467
commit c0c4d48ba2
7 files changed
+714 -721

No files matched your search

@@ -3,7 +3,6 @@
#include "cmCTestBuildAndTestHandler.h"
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <ratio>
@@ -356,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;
}
+2 -6
View File
@@ -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
*/
@@ -68,4 +62,6 @@ protected:
std::vector<std::string> BuildTargets;
bool BuildNoCMake = false;
cmDuration Timeout = cmDuration::zero();
friend class cmCTest;
};
-11
View File
@@ -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
*/
-14
View File
@@ -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
View File
@@ -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()) {
+706 -576
View File
File diff suppressed because it is too large. Load diff
-18
View File
@@ -492,10 +492,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();
@@ -507,10 +503,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();
@@ -525,16 +517,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();