ctest: allow HTTP headers via command line

Add ability to specify HTTP headers via `ctest -T Submit`.
This commit is contained in:
Matthew Woehlke
2024-01-08 12:45:20 -05:00
committed by Brad King
parent b2ea53f484
commit 20adf8cfce
5 changed files with 43 additions and 2 deletions

View File

@@ -754,6 +754,16 @@ The available ``<dashboard-options>`` are the following:
This option will submit extra files to the dashboard. This option will submit extra files to the dashboard.
.. option:: --http-header <header>
.. versionadded:: 3.29
Append HTTP header when submitting to the dashboard.
This option will cause CTest to append the specified header
when submitting to the dashboard.
This option may be specified more than once.
.. option:: --http1.0 .. option:: --http1.0
Submit using `HTTP 1.0`. Submit using `HTTP 1.0`.

View File

@@ -0,0 +1,5 @@
ctest-cli-http-headers
----------------------
* :manual:`ctest(1)` gained a :option:`--http-header <ctest --http-header>`
option to add custom headers on submission to CDash.

View File

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

View File

@@ -4,6 +4,7 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <cstddef>
#include <iosfwd> #include <iosfwd>
#include <set> #include <set>
#include <string> #include <string>
@@ -33,6 +34,11 @@ public:
void Initialize() override; void Initialize() override;
//! Set all the submit arguments
int ProcessCommandLineArguments(
const std::string& currentArg, size_t& idx,
const std::vector<std::string>& allArgs) override;
/** Specify a set of parts (by name) to submit. */ /** Specify a set of parts (by name) to submit. */
void SelectParts(std::set<cmCTest::Part> const& parts); void SelectParts(std::set<cmCTest::Part> const& parts);
@@ -44,7 +50,12 @@ public:
void SetHttpHeaders(std::vector<std::string> const& v) void SetHttpHeaders(std::vector<std::string> const& v)
{ {
this->HttpHeaders = v; if (this->CommandLineHttpHeaders.empty()) {
this->HttpHeaders = v;
} else {
this->HttpHeaders = this->CommandLineHttpHeaders;
this->HttpHeaders.insert(this->HttpHeaders.end(), v.begin(), v.end());
}
} }
private: private:
@@ -75,5 +86,6 @@ private:
bool HasWarnings; bool HasWarnings;
bool HasErrors; bool HasErrors;
std::set<std::string> Files; std::set<std::string> Files;
std::vector<std::string> CommandLineHttpHeaders;
std::vector<std::string> HttpHeaders; std::vector<std::string> HttpHeaders;
}; };

View File

@@ -25,7 +25,7 @@ const cmDocumentationEntry cmDocumentationName = {
const cmDocumentationEntry cmDocumentationUsage = { {}, " ctest [options]" }; const cmDocumentationEntry cmDocumentationUsage = { {}, " ctest [options]" };
const cmDocumentationEntry cmDocumentationOptions[74] = { const cmDocumentationEntry cmDocumentationOptions[] = {
{ "--preset <preset>, --preset=<preset>", { "--preset <preset>, --preset=<preset>",
"Read arguments from a test preset." }, "Read arguments from a test preset." },
{ "--list-presets", "List available test presets." }, { "--list-presets", "List available test presets." },
@@ -143,6 +143,7 @@ const cmDocumentationEntry cmDocumentationOptions[74] = {
{ "--tomorrow-tag", "Nightly or experimental starts with next day tag." }, { "--tomorrow-tag", "Nightly or experimental starts with next day tag." },
{ "--overwrite", "Overwrite CTest configuration option." }, { "--overwrite", "Overwrite CTest configuration option." },
{ "--extra-submit <file>[;<file>]", "Submit extra files to the dashboard." }, { "--extra-submit <file>[;<file>]", "Submit extra files to the dashboard." },
{ "--http-header <header>", "Append HTTP header when submitting" },
{ "--force-new-ctest-process", { "--force-new-ctest-process",
"Run child CTest instances as new processes" }, "Run child CTest instances as new processes" },
{ "--schedule-random", "Use a random order for scheduling tests" }, { "--schedule-random", "Use a random order for scheduling tests" },