Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/CTest/cmCTestHandlerCommand.h
4998 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <functional>
8
#include <memory>
9
#include <string>
10
#include <type_traits>
11
#include <vector>
12
13
#include <cm/string_view>
14
#include <cmext/string_view>
15
16
#include "cmArgumentParser.h"
17
#include "cmCTestCommand.h"
18
19
class cmExecutionStatus;
20
class cmCTestGenericHandler;
21
22
class cmCTestHandlerCommand : public cmCTestCommand
23
{
24
public:
25
using cmCTestCommand::cmCTestCommand;
26
27
protected:
28
struct BasicArguments : ArgumentParser::ParseResult
29
{
30
std::string CaptureCMakeError;
31
std::vector<cm::string_view> ParsedKeywords;
32
};
33
34
template <typename Args>
35
static auto MakeBasicParser() -> cmArgumentParser<Args>
36
{
37
static_assert(std::is_base_of<BasicArguments, Args>::value, "");
38
return cmArgumentParser<Args>{}
39
.Bind("CAPTURE_CMAKE_ERROR"_s, &BasicArguments::CaptureCMakeError)
40
.BindParsedKeywords(&BasicArguments::ParsedKeywords);
41
}
42
43
struct HandlerArguments : BasicArguments
44
{
45
bool Append = false;
46
bool Quiet = false;
47
std::string ReturnValue;
48
std::string Build;
49
std::string Source;
50
std::string SubmitIndex;
51
};
52
53
template <typename Args>
54
static auto MakeHandlerParser() -> cmArgumentParser<Args>
55
{
56
static_assert(std::is_base_of<HandlerArguments, Args>::value, "");
57
return cmArgumentParser<Args>{ MakeBasicParser<Args>() }
58
.Bind("APPEND"_s, &HandlerArguments::Append)
59
.Bind("QUIET"_s, &HandlerArguments::Quiet)
60
.Bind("RETURN_VALUE"_s, &HandlerArguments::ReturnValue)
61
.Bind("SOURCE"_s, &HandlerArguments::Source)
62
.Bind("BUILD"_s, &HandlerArguments::Build)
63
.Bind("SUBMIT_INDEX"_s, &HandlerArguments::SubmitIndex);
64
}
65
66
protected:
67
template <typename Args, typename Handler>
68
bool Invoke(cmArgumentParser<Args> const& parser,
69
std::vector<std::string> const& arguments,
70
cmExecutionStatus& status, Handler handler) const
71
{
72
std::vector<std::string> unparsed;
73
Args args = parser.Parse(arguments, &unparsed);
74
return this->InvokeImpl(args, unparsed, status,
75
[&]() -> bool { return handler(args); });
76
};
77
78
bool ExecuteHandlerCommand(HandlerArguments& args,
79
cmExecutionStatus& status) const;
80
81
private:
82
bool InvokeImpl(BasicArguments& args,
83
std::vector<std::string> const& unparsed,
84
cmExecutionStatus& status,
85
std::function<bool()> handler) const;
86
87
virtual std::string GetName() const = 0;
88
89
virtual void CheckArguments(HandlerArguments& arguments,
90
cmExecutionStatus& status) const;
91
92
virtual std::unique_ptr<cmCTestGenericHandler> InitializeHandler(
93
HandlerArguments& arguments, cmExecutionStatus& status) const;
94
95
virtual void ProcessAdditionalValues(cmCTestGenericHandler*,
96
HandlerArguments const& arguments,
97
cmExecutionStatus& status) const;
98
};
99
100