Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstrumentationQuery.cxx
Line
Count
Source
1
#include "cmInstrumentationQuery.h"
2
3
#include <algorithm>
4
#include <ctime>
5
#include <functional>
6
#include <iostream>
7
#include <iterator>
8
#include <set>
9
#include <vector>
10
11
#include <cmext/string_view>
12
13
#include <cm3p/json/value.h>
14
15
#include "cmJSONHelpers.h"
16
#include "cmStringAlgorithms.h"
17
18
std::vector<std::string> const cmInstrumentationQuery::OptionString{
19
  "staticSystemInformation", "dynamicSystemInformation", "cdashSubmit",
20
  "cdashVerbose", "trace"
21
};
22
std::vector<std::string> const cmInstrumentationQuery::HookString{
23
  "postGenerate",    "preBuild",  "postBuild",        "preCMakeBuild",
24
  "postCMakeBuild",  "postCTest", "postCMakeInstall", "postCMakeWorkflow",
25
  "prepareForCDash", "manual"
26
};
27
28
namespace ErrorMessages {
29
using ErrorGenerator =
30
  std::function<void(Json::Value const*, cmJSONState* state)>;
31
ErrorGenerator ErrorGeneratorBuilder(std::string const& errorMessage)
32
4
{
33
4
  return [errorMessage](Json::Value const* value, cmJSONState* state) -> void {
34
0
    state->AddErrorAtValue(errorMessage, value);
35
0
  };
36
4
};
37
38
static ErrorGenerator InvalidArray = ErrorGeneratorBuilder("Invalid Array");
39
JsonErrors::ErrorGenerator InvalidRootQueryObject(
40
  JsonErrors::ObjectError errorType, Json::Value::Members const& extraFields)
41
0
{
42
0
  return JsonErrors::INVALID_NAMED_OBJECT(
43
0
    [](Json::Value const*, cmJSONState*) -> std::string {
44
0
      return "root object";
45
0
    })(errorType, extraFields);
46
0
}
47
};
48
49
using JSONHelperBuilder = cmJSONHelperBuilder;
50
51
template <typename E>
52
static std::function<bool(E&, Json::Value const*, cmJSONState*)> EnumHelper(
53
  std::vector<std::string> const toString, std::string const& type)
54
8
{
55
8
  return [toString, type](E& out, Json::Value const* value,
56
8
                          cmJSONState* state) -> bool {
57
0
    for (size_t i = 0; i < toString.size(); ++i) {
58
0
      if (value->asString() == toString[i]) {
59
0
        out = (E)i;
60
0
        return true;
61
0
      }
62
0
    }
63
0
    state->AddErrorAtValue(
64
0
      cmStrCat("Not a valid ", type, ": \"", value->asString(), '"'), value);
65
0
    return false;
66
0
  };
Unexecuted instantiation: cmInstrumentationQuery.cxx:EnumHelper<cmInstrumentationQuery::Option>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::{lambda(cmInstrumentationQuery::Option&, Json::Value const*, cmJSONState*)#1}::operator()(cmInstrumentationQuery::Option&, Json::Value const*, cmJSONState*) const
Unexecuted instantiation: cmInstrumentationQuery.cxx:EnumHelper<cmInstrumentationQuery::Hook>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::{lambda(cmInstrumentationQuery::Hook&, Json::Value const*, cmJSONState*)#1}::operator()(cmInstrumentationQuery::Hook&, Json::Value const*, cmJSONState*) const
67
8
}
cmInstrumentationQuery.cxx:std::__1::function<bool (cmInstrumentationQuery::Option&, Json::Value const*, cmJSONState*)> EnumHelper<cmInstrumentationQuery::Option>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
54
4
{
55
4
  return [toString, type](E& out, Json::Value const* value,
56
4
                          cmJSONState* state) -> bool {
57
4
    for (size_t i = 0; i < toString.size(); ++i) {
58
4
      if (value->asString() == toString[i]) {
59
4
        out = (E)i;
60
4
        return true;
61
4
      }
62
4
    }
63
4
    state->AddErrorAtValue(
64
4
      cmStrCat("Not a valid ", type, ": \"", value->asString(), '"'), value);
65
4
    return false;
66
4
  };
67
4
}
cmInstrumentationQuery.cxx:std::__1::function<bool (cmInstrumentationQuery::Hook&, Json::Value const*, cmJSONState*)> EnumHelper<cmInstrumentationQuery::Hook>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
54
4
{
55
4
  return [toString, type](E& out, Json::Value const* value,
56
4
                          cmJSONState* state) -> bool {
57
4
    for (size_t i = 0; i < toString.size(); ++i) {
58
4
      if (value->asString() == toString[i]) {
59
4
        out = (E)i;
60
4
        return true;
61
4
      }
62
4
    }
63
4
    state->AddErrorAtValue(
64
4
      cmStrCat("Not a valid ", type, ": \"", value->asString(), '"'), value);
65
4
    return false;
66
4
  };
67
4
}
68
static auto const OptionHelper = EnumHelper<cmInstrumentationQuery::Option>(
69
  cmInstrumentationQuery::OptionString, "option");
70
static auto const QueryListHelper =
71
  JSONHelperBuilder::Vector<cmInstrumentationQuery::Option>(
72
    ErrorMessages::InvalidArray, OptionHelper);
73
static auto const HookHelper = EnumHelper<cmInstrumentationQuery::Hook>(
74
  cmInstrumentationQuery::HookString, "hook");
75
static auto const HookListHelper =
76
  JSONHelperBuilder::Vector<cmInstrumentationQuery::Hook>(
77
    ErrorMessages::InvalidArray, HookHelper);
78
static auto const CallbackHelper = JSONHelperBuilder::String();
79
static auto const CallbackListHelper = JSONHelperBuilder::Vector<std::string>(
80
  ErrorMessages::InvalidArray, CallbackHelper);
81
static auto const VersionHelper = JSONHelperBuilder::Int();
82
83
using QueryRoot = cmInstrumentationQuery::QueryJSONRoot;
84
85
static auto const QueryRootHelper =
86
  JSONHelperBuilder::Object<QueryRoot>(ErrorMessages::InvalidRootQueryObject,
87
                                       false)
88
    .Bind("version"_s, &QueryRoot::version, VersionHelper, true)
89
    .Bind("options"_s, &QueryRoot::options, QueryListHelper, false)
90
    .Bind("hooks"_s, &QueryRoot::hooks, HookListHelper, false)
91
    .Bind("callbacks"_s, &QueryRoot::callbacks, CallbackListHelper, false);
92
93
bool cmInstrumentationQuery::ReadJSON(std::string const& filename,
94
                                      std::string& errorMessage,
95
                                      std::set<Option>& options,
96
                                      std::set<Hook>& hooks,
97
                                      std::vector<std::string>& callbacks)
98
0
{
99
0
  Json::Value root;
100
0
  this->parseState = cmJSONState(filename, &root);
101
0
  if (!this->parseState.errors.empty()) {
102
0
    std::cerr << this->parseState.GetErrorMessage(true) << std::endl;
103
0
    return false;
104
0
  }
105
0
  if (!QueryRootHelper(this->queryRoot, &root, &this->parseState)) {
106
0
    errorMessage = this->parseState.GetErrorMessage(true);
107
0
    return false;
108
0
  }
109
0
  std::move(this->queryRoot.options.begin(), this->queryRoot.options.end(),
110
0
            std::inserter(options, options.end()));
111
0
  std::move(this->queryRoot.hooks.begin(), this->queryRoot.hooks.end(),
112
0
            std::inserter(hooks, hooks.end()));
113
0
  std::move(this->queryRoot.callbacks.begin(), this->queryRoot.callbacks.end(),
114
0
            std::back_inserter(callbacks));
115
0
  return true;
116
0
}