/src/CMake/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include <cassert> |
4 | | #include <cstddef> |
5 | | #include <functional> |
6 | | #include <map> |
7 | | #include <memory> |
8 | | #include <string> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include <cm/optional> |
13 | | #include <cm/string_view> |
14 | | #include <cmext/algorithm> |
15 | | #include <cmext/string_view> |
16 | | |
17 | | #include <cm3p/json/value.h> |
18 | | |
19 | | #include "cmsys/String.h" |
20 | | |
21 | | #include "cmCMakePresetsErrors.h" |
22 | | #include "cmCMakePresetsGraph.h" |
23 | | #include "cmCMakePresetsGraphInternal.h" |
24 | | #include "cmDiagnostics.h" |
25 | | #include "cmJSONHelpers.h" |
26 | | #include "cmStateTypes.h" |
27 | | |
28 | | class cmJSONState; |
29 | | |
30 | | namespace { |
31 | | using CacheVariable = cmCMakePresetsGraph::CacheVariable; |
32 | | using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset; |
33 | | using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy; |
34 | | using JSONHelperBuilder = cmJSONHelperBuilder; |
35 | | using TraceEnableMode = cmCMakePresetsGraph::TraceEnableMode; |
36 | | using TraceOutputFormat = cmTraceEnums::TraceOutputFormat; |
37 | | |
38 | | bool ArchToolsetStrategyHelper(cm::optional<ArchToolsetStrategy>& out, |
39 | | Json::Value const* value, cmJSONState* state) |
40 | 0 | { |
41 | 0 | if (!value) { |
42 | 0 | out = cm::nullopt; |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | 0 | if (!value->isString()) { |
47 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
48 | 0 | return false; |
49 | 0 | } |
50 | | |
51 | 0 | if (value->asString() == "set") { |
52 | 0 | out = ArchToolsetStrategy::Set; |
53 | 0 | return true; |
54 | 0 | } |
55 | | |
56 | 0 | if (value->asString() == "external") { |
57 | 0 | out = ArchToolsetStrategy::External; |
58 | 0 | return true; |
59 | 0 | } |
60 | | |
61 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
62 | 0 | return false; |
63 | 0 | } |
64 | | |
65 | | std::function<bool(ConfigurePreset&, Json::Value const*, cmJSONState*)> |
66 | | ArchToolsetHelper( |
67 | | std::string ConfigurePreset::*valueField, |
68 | | cm::optional<ArchToolsetStrategy> ConfigurePreset::*strategyField) |
69 | 8 | { |
70 | 8 | auto const objectHelper = |
71 | 8 | JSONHelperBuilder::Object<ConfigurePreset>(JsonErrors::INVALID_OBJECT, |
72 | 8 | false) |
73 | 8 | .Bind("value", valueField, |
74 | 8 | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
75 | 8 | .Bind("strategy", strategyField, ArchToolsetStrategyHelper, false); |
76 | 8 | return [valueField, strategyField, |
77 | 8 | objectHelper](ConfigurePreset& out, Json::Value const* value, |
78 | 8 | cmJSONState* state) -> bool { |
79 | 0 | if (!value) { |
80 | 0 | (out.*valueField).clear(); |
81 | 0 | out.*strategyField = cm::nullopt; |
82 | 0 | return true; |
83 | 0 | } |
84 | | |
85 | 0 | if (value->isString()) { |
86 | 0 | out.*valueField = value->asString(); |
87 | 0 | out.*strategyField = cm::nullopt; |
88 | 0 | return true; |
89 | 0 | } |
90 | | |
91 | 0 | if (value->isObject()) { |
92 | 0 | return objectHelper(out, value, state); |
93 | 0 | } |
94 | | |
95 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
96 | 0 | return false; |
97 | 0 | }; |
98 | 8 | } |
99 | | |
100 | | auto const ArchitectureHelper = ArchToolsetHelper( |
101 | | &ConfigurePreset::Architecture, &ConfigurePreset::ArchitectureStrategy); |
102 | | auto const ToolsetHelper = ArchToolsetHelper( |
103 | | &ConfigurePreset::Toolset, &ConfigurePreset::ToolsetStrategy); |
104 | | |
105 | | bool TraceEnableModeHelper(cm::optional<TraceEnableMode>& out, |
106 | | Json::Value const* value, cmJSONState* state) |
107 | 0 | { |
108 | 0 | if (!value) { |
109 | 0 | out = cm::nullopt; |
110 | 0 | return true; |
111 | 0 | } |
112 | | |
113 | 0 | if (!value->isString()) { |
114 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
115 | 0 | return false; |
116 | 0 | } |
117 | | |
118 | 0 | if (value->asString() == "on") { |
119 | 0 | out = TraceEnableMode::Default; |
120 | 0 | } else if (value->asString() == "off") { |
121 | 0 | out = TraceEnableMode::Disable; |
122 | 0 | } else if (value->asString() == "expand") { |
123 | 0 | out = TraceEnableMode::Expand; |
124 | 0 | } else { |
125 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
126 | 0 | return false; |
127 | 0 | } |
128 | | |
129 | 0 | return true; |
130 | 0 | } |
131 | | |
132 | | bool TraceOutputFormatHelper(cm::optional<TraceOutputFormat>& out, |
133 | | Json::Value const* value, cmJSONState* state) |
134 | 0 | { |
135 | 0 | if (!value) { |
136 | 0 | out = cm::nullopt; |
137 | 0 | return true; |
138 | 0 | } |
139 | | |
140 | 0 | if (!value->isString()) { |
141 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
142 | 0 | return false; |
143 | 0 | } |
144 | | |
145 | 0 | if (value->asString() == "human") { |
146 | 0 | out = TraceOutputFormat::Human; |
147 | 0 | } else if (value->asString() == "json-v1") { |
148 | 0 | out = TraceOutputFormat::JSONv1; |
149 | 0 | } else { |
150 | 0 | cmCMakePresetsErrors::INVALID_PRESET(value, state); |
151 | 0 | return false; |
152 | 0 | } |
153 | | |
154 | 0 | return true; |
155 | 0 | } |
156 | | |
157 | | auto const VariableStringHelper = JSONHelperBuilder::String(); |
158 | | |
159 | | bool VariableValueHelper(std::string& out, Json::Value const* value, |
160 | | cmJSONState* state) |
161 | 0 | { |
162 | 0 | if (!value) { |
163 | 0 | out.clear(); |
164 | 0 | return true; |
165 | 0 | } |
166 | | |
167 | 0 | if (value->isBool()) { |
168 | 0 | out = value->asBool() ? "TRUE" : "FALSE"; |
169 | 0 | return true; |
170 | 0 | } |
171 | | |
172 | 0 | return VariableStringHelper(out, value, state); |
173 | 0 | } |
174 | | |
175 | | auto const VariableObjectHelper = |
176 | | JSONHelperBuilder::Object<CacheVariable>( |
177 | | cmCMakePresetsErrors::INVALID_VARIABLE_OBJECT, false) |
178 | | .Bind("type"_s, &CacheVariable::Type, VariableStringHelper, false) |
179 | | .Bind("value"_s, &CacheVariable::Value, VariableValueHelper); |
180 | | |
181 | | bool VariableHelper(cm::optional<CacheVariable>& out, Json::Value const* value, |
182 | | cmJSONState* state) |
183 | 0 | { |
184 | 0 | if (value->isBool()) { |
185 | 0 | out = CacheVariable{ |
186 | 0 | /*Type=*/"BOOL", |
187 | 0 | /*Value=*/value->asBool() ? "TRUE" : "FALSE", |
188 | 0 | }; |
189 | 0 | return true; |
190 | 0 | } |
191 | 0 | if (value->isString()) { |
192 | 0 | out = CacheVariable{ |
193 | 0 | /*Type=*/"", |
194 | 0 | /*Value=*/value->asString(), |
195 | 0 | }; |
196 | 0 | return true; |
197 | 0 | } |
198 | 0 | if (value->isObject()) { |
199 | 0 | out.emplace(); |
200 | 0 | return VariableObjectHelper(*out, value, state); |
201 | 0 | } |
202 | 0 | if (value->isNull()) { |
203 | 0 | out = cm::nullopt; |
204 | 0 | return true; |
205 | 0 | } |
206 | 0 | cmCMakePresetsErrors::INVALID_VARIABLE(value, state); |
207 | 0 | return false; |
208 | 0 | } |
209 | | |
210 | | auto const VariablesHelper = |
211 | | JSONHelperBuilder::Map<cm::optional<CacheVariable>>( |
212 | | cmCMakePresetsErrors::INVALID_PRESET, VariableHelper); |
213 | | |
214 | | template <cmDiagnosticCategory C> |
215 | | cm::string_view GetJSONName() |
216 | 32 | { |
217 | 32 | static std::string storage = [] { |
218 | 16 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); |
219 | 16 | std::string out; |
220 | 16 | bool sep = false; |
221 | 156 | for (char const c : in) { |
222 | 156 | if (sep) { |
223 | 4 | out += c; |
224 | 4 | sep = false; |
225 | 152 | } else if (c == '_') { |
226 | 4 | sep = true; |
227 | 148 | } else { |
228 | 148 | out += static_cast<char>(cmsysString_tolower(c)); |
229 | 148 | } |
230 | 156 | } |
231 | 16 | return out; |
232 | 16 | }(); cmCMakePresetsGraphReadJSONConfigurePresets.cxx:(anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)1>()::{lambda()#1}::operator()() constLine | Count | Source | 217 | 4 | static std::string storage = [] { | 218 | 4 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 4 | std::string out; | 220 | 4 | bool sep = false; | 221 | 24 | for (char const c : in) { | 222 | 24 | if (sep) { | 223 | 0 | out += c; | 224 | 0 | sep = false; | 225 | 24 | } else if (c == '_') { | 226 | 0 | sep = true; | 227 | 24 | } else { | 228 | 24 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 24 | } | 230 | 24 | } | 231 | 4 | return out; | 232 | 4 | }(); |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:(anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)2>()::{lambda()#1}::operator()() constLine | Count | Source | 217 | 4 | static std::string storage = [] { | 218 | 4 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 4 | std::string out; | 220 | 4 | bool sep = false; | 221 | 40 | for (char const c : in) { | 222 | 40 | if (sep) { | 223 | 0 | out += c; | 224 | 0 | sep = false; | 225 | 40 | } else if (c == '_') { | 226 | 0 | sep = true; | 227 | 40 | } else { | 228 | 40 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 40 | } | 230 | 40 | } | 231 | 4 | return out; | 232 | 4 | }(); |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:(anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)3>()::{lambda()#1}::operator()() constLine | Count | Source | 217 | 4 | static std::string storage = [] { | 218 | 4 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 4 | std::string out; | 220 | 4 | bool sep = false; | 221 | 52 | for (char const c : in) { | 222 | 52 | if (sep) { | 223 | 0 | out += c; | 224 | 0 | sep = false; | 225 | 52 | } else if (c == '_') { | 226 | 0 | sep = true; | 227 | 52 | } else { | 228 | 52 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 52 | } | 230 | 52 | } | 231 | 4 | return out; | 232 | 4 | }(); |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:(anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)4>()::{lambda()#1}::operator()() constLine | Count | Source | 217 | 4 | static std::string storage = [] { | 218 | 4 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 4 | std::string out; | 220 | 4 | bool sep = false; | 221 | 40 | for (char const c : in) { | 222 | 40 | if (sep) { | 223 | 4 | out += c; | 224 | 4 | sep = false; | 225 | 36 | } else if (c == '_') { | 226 | 4 | sep = true; | 227 | 32 | } else { | 228 | 32 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 32 | } | 230 | 40 | } | 231 | 4 | return out; | 232 | 4 | }(); |
|
233 | 32 | return storage; |
234 | 32 | } cmCMakePresetsGraphReadJSONConfigurePresets.cxx:std::__1::basic_string_view<char, std::__1::char_traits<char> > (anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)1>() Line | Count | Source | 216 | 8 | { | 217 | 8 | static std::string storage = [] { | 218 | 8 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 8 | std::string out; | 220 | 8 | bool sep = false; | 221 | 8 | for (char const c : in) { | 222 | 8 | if (sep) { | 223 | 8 | out += c; | 224 | 8 | sep = false; | 225 | 8 | } else if (c == '_') { | 226 | 8 | sep = true; | 227 | 8 | } else { | 228 | 8 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 8 | } | 230 | 8 | } | 231 | 8 | return out; | 232 | 8 | }(); | 233 | 8 | return storage; | 234 | 8 | } |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:std::__1::basic_string_view<char, std::__1::char_traits<char> > (anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)2>() Line | Count | Source | 216 | 8 | { | 217 | 8 | static std::string storage = [] { | 218 | 8 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 8 | std::string out; | 220 | 8 | bool sep = false; | 221 | 8 | for (char const c : in) { | 222 | 8 | if (sep) { | 223 | 8 | out += c; | 224 | 8 | sep = false; | 225 | 8 | } else if (c == '_') { | 226 | 8 | sep = true; | 227 | 8 | } else { | 228 | 8 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 8 | } | 230 | 8 | } | 231 | 8 | return out; | 232 | 8 | }(); | 233 | 8 | return storage; | 234 | 8 | } |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:std::__1::basic_string_view<char, std::__1::char_traits<char> > (anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)3>() Line | Count | Source | 216 | 8 | { | 217 | 8 | static std::string storage = [] { | 218 | 8 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 8 | std::string out; | 220 | 8 | bool sep = false; | 221 | 8 | for (char const c : in) { | 222 | 8 | if (sep) { | 223 | 8 | out += c; | 224 | 8 | sep = false; | 225 | 8 | } else if (c == '_') { | 226 | 8 | sep = true; | 227 | 8 | } else { | 228 | 8 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 8 | } | 230 | 8 | } | 231 | 8 | return out; | 232 | 8 | }(); | 233 | 8 | return storage; | 234 | 8 | } |
cmCMakePresetsGraphReadJSONConfigurePresets.cxx:std::__1::basic_string_view<char, std::__1::char_traits<char> > (anonymous namespace)::GetJSONName<(cmDiagnostics::DiagnosticCategory)4>() Line | Count | Source | 216 | 8 | { | 217 | 8 | static std::string storage = [] { | 218 | 8 | cm::string_view const in = cmDiagnostics::GetCategoryString(C).substr(4); | 219 | 8 | std::string out; | 220 | 8 | bool sep = false; | 221 | 8 | for (char const c : in) { | 222 | 8 | if (sep) { | 223 | 8 | out += c; | 224 | 8 | sep = false; | 225 | 8 | } else if (c == '_') { | 226 | 8 | sep = true; | 227 | 8 | } else { | 228 | 8 | out += static_cast<char>(cmsysString_tolower(c)); | 229 | 8 | } | 230 | 8 | } | 231 | 8 | return out; | 232 | 8 | }(); | 233 | 8 | return storage; | 234 | 8 | } |
|
235 | | |
236 | | cm::string_view GetJSONName(cmDiagnosticCategory category) |
237 | 0 | { |
238 | 0 | static cm::string_view const names[] = { |
239 | 0 | "none"_s, // CMD_NONE |
240 | 0 | #define DIAGNOSTIC_JSON_NAME(C) GetJSONName<cmDiagnostics::C>(), |
241 | 0 | CM_FOR_EACH_DIAGNOSTIC_CATEGORY(DIAGNOSTIC_JSON_NAME) |
242 | 0 | #undef DIAGNOSTIC_JSON_NAME |
243 | 0 | }; |
244 | 0 | assert(category > 0 && category < cmDiagnostics::CategoryCount); |
245 | 0 | return names[category]; |
246 | 0 | } |
247 | | |
248 | | auto const PresetDiagnosticMapHelper = |
249 | | cmCMakePresetsGraphInternal::PresetMapToBoolHelper<cmDiagnosticCategory>; |
250 | | |
251 | | #define BIND_DIAGNOSTIC(C) \ |
252 | | .Bind(GetJSONName<cmDiagnostics::C>(), &DIAGNOSTIC_MEMBER, \ |
253 | | PresetDiagnosticMapHelper, cmDiagnostics::C, false) |
254 | | |
255 | | #define DIAGNOSTIC_MEMBER ConfigurePreset::Warnings |
256 | | auto const PresetWarningsHelper = |
257 | | JSONHelperBuilder::Object<ConfigurePreset>( |
258 | | JsonErrors::INVALID_NAMED_OBJECT_KEY, false) |
259 | | .Bind("dev"_s, &ConfigurePreset::WarnDev, |
260 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
261 | | CM_FOR_EACH_DIAGNOSTIC_CATEGORY(BIND_DIAGNOSTIC) |
262 | | .Bind("systemVars"_s, &ConfigurePreset::WarnSystemVars, |
263 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false); |
264 | | #undef DIAGNOSTIC_MEMBER |
265 | | |
266 | | #define DIAGNOSTIC_MEMBER ConfigurePreset::Errors |
267 | | auto const PresetErrorsHelper = |
268 | | JSONHelperBuilder::Object<ConfigurePreset>( |
269 | | JsonErrors::INVALID_NAMED_OBJECT_KEY, false) |
270 | | .Bind("dev"_s, &ConfigurePreset::ErrorDev, |
271 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
272 | | CM_FOR_EACH_DIAGNOSTIC_CATEGORY(BIND_DIAGNOSTIC); |
273 | | #undef DIAGNOSTIC_MEMBER |
274 | | |
275 | | #undef BIND_DIAGNOSTIC |
276 | | |
277 | | auto const PresetDebugHelper = |
278 | | JSONHelperBuilder::Object<ConfigurePreset>( |
279 | | JsonErrors::INVALID_NAMED_OBJECT_KEY, false) |
280 | | .Bind("output"_s, &ConfigurePreset::DebugOutput, |
281 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
282 | | .Bind("tryCompile"_s, &ConfigurePreset::DebugTryCompile, |
283 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false) |
284 | | .Bind("find"_s, &ConfigurePreset::DebugFind, |
285 | | cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false); |
286 | | |
287 | | auto const PresetTraceHelper = |
288 | | JSONHelperBuilder::Object<ConfigurePreset>( |
289 | | cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false) |
290 | | .Bind("mode"_s, &ConfigurePreset::TraceMode, TraceEnableModeHelper, false) |
291 | | .Bind("format"_s, &ConfigurePreset::TraceFormat, TraceOutputFormatHelper, |
292 | | false) |
293 | | .Bind("source"_s, &ConfigurePreset::TraceSource, |
294 | | cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper, |
295 | | false) |
296 | | .Bind("redirect"_s, &ConfigurePreset::TraceRedirect, |
297 | | cmCMakePresetsGraphInternal::PresetStringHelper, false); |
298 | | |
299 | | auto const ConfigurePresetHelper = |
300 | | JSONHelperBuilder::Object<ConfigurePreset>( |
301 | | cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false) |
302 | | .Bind("name"_s, &ConfigurePreset::Name, |
303 | | cmCMakePresetsGraphInternal::PresetNameHelper) |
304 | | .Bind("inherits"_s, &ConfigurePreset::Inherits, |
305 | | cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper, |
306 | | false) |
307 | | .Bind("hidden"_s, &ConfigurePreset::Hidden, |
308 | | cmCMakePresetsGraphInternal::PresetBoolHelper, false) |
309 | | .Bind<std::nullptr_t>("vendor"_s, nullptr, |
310 | | cmCMakePresetsGraphInternal::VendorHelper( |
311 | | cmCMakePresetsErrors::INVALID_PRESET), |
312 | | false) |
313 | | .Bind("displayName"_s, &ConfigurePreset::DisplayName, |
314 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
315 | | .Bind("description"_s, &ConfigurePreset::Description, |
316 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
317 | | .Bind("generator"_s, &ConfigurePreset::Generator, |
318 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
319 | | .Bind("architecture"_s, ArchitectureHelper, false) |
320 | | .Bind("toolset"_s, ToolsetHelper, false) |
321 | | .Bind("toolchainFile"_s, &ConfigurePreset::ToolchainFile, |
322 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
323 | | .Bind("graphviz"_s, &ConfigurePreset::GraphVizFile, |
324 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
325 | | .Bind("binaryDir"_s, &ConfigurePreset::BinaryDir, |
326 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
327 | | .Bind("installDir"_s, &ConfigurePreset::InstallDir, |
328 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
329 | | .Bind<std::string>("cmakeExecutable"_s, nullptr, |
330 | | cmCMakePresetsGraphInternal::PresetStringHelper, false) |
331 | | .Bind("cacheVariables"_s, &ConfigurePreset::CacheVariables, |
332 | | VariablesHelper, false) |
333 | | .Bind("environment"_s, &ConfigurePreset::Environment, |
334 | | cmCMakePresetsGraphInternal::EnvironmentMapHelper, false) |
335 | | .Bind("warnings"_s, PresetWarningsHelper, false) |
336 | | .Bind("errors"_s, PresetErrorsHelper, false) |
337 | | .Bind("debug"_s, PresetDebugHelper, false) |
338 | | .Bind("trace"_s, PresetTraceHelper, false) |
339 | | .Bind("condition"_s, &ConfigurePreset::ConditionEvaluator, |
340 | | cmCMakePresetsGraphInternal::PresetConditionHelper, false); |
341 | | } |
342 | | |
343 | | namespace cmCMakePresetsGraphInternal { |
344 | | bool ConfigurePresetsHelper(std::vector<ConfigurePreset>& out, |
345 | | Json::Value const* value, cmJSONState* state) |
346 | 0 | { |
347 | 0 | static auto const helper = JSONHelperBuilder::Vector<ConfigurePreset>( |
348 | 0 | cmCMakePresetsErrors::INVALID_PRESETS, ConfigurePresetHelper); |
349 | |
|
350 | 0 | return helper(out, value, state); |
351 | 0 | } |
352 | | |
353 | | bool CheckDiagnostics(cmJSONState* state, int version, |
354 | | std::map<cmDiagnosticCategory, bool> values, |
355 | | cm::string_view group) |
356 | 0 | { |
357 | | // NOLINTNEXTLINE(readability-use-anyofallof) |
358 | 0 | for (auto const& i : values) { |
359 | 0 | assert(i.first > 0 && i.first < cmDiagnostics::CategoryCount); |
360 | 0 | int const minVersion = cmDiagnostics::CategoryInfo[i.first].PresetVersion; |
361 | 0 | if (version < minVersion) { |
362 | 0 | cm::string_view dn = GetJSONName(i.first); |
363 | 0 | cmCMakePresetsErrors::DIAGNOSTIC_UNSUPPORTED(dn, group, minVersion, |
364 | 0 | state); |
365 | 0 | return false; |
366 | 0 | } |
367 | 0 | } |
368 | | |
369 | 0 | return true; |
370 | 0 | } |
371 | | |
372 | | bool CheckDiagnostics(cmJSONState* state, int version, |
373 | | cmCMakePresetsGraph::ConfigurePreset& preset) |
374 | 0 | { |
375 | | // Check for diagnostics added in later schemes. |
376 | 0 | if (!CheckDiagnostics(state, version, preset.Warnings, "warnings"_s) || |
377 | 0 | !CheckDiagnostics(state, version, preset.Errors, "errors"_s)) { |
378 | 0 | return false; |
379 | 0 | } |
380 | | |
381 | 0 | if (version < 12) { |
382 | | // Handle 'dev'. |
383 | 0 | if (preset.WarnDev) { |
384 | 0 | preset.Warnings.emplace(cmDiagnostics::CMD_AUTHOR, *preset.WarnDev); |
385 | 0 | } |
386 | 0 | if (preset.ErrorDev) { |
387 | 0 | preset.Errors.emplace(cmDiagnostics::CMD_AUTHOR, *preset.ErrorDev); |
388 | 0 | } |
389 | | |
390 | | // Check for diagnostics only present as warnings before v12. |
391 | 0 | constexpr cmDiagnosticCategory unsupportedErrors[] = { |
392 | 0 | cmDiagnostics::CMD_UNINITIALIZED, |
393 | 0 | cmDiagnostics::CMD_UNUSED_CLI, |
394 | 0 | }; |
395 | |
|
396 | 0 | for (cmDiagnosticCategory c : unsupportedErrors) { |
397 | 0 | if (cm::contains(preset.Errors, c)) { |
398 | 0 | cm::string_view dn = GetJSONName(c); |
399 | 0 | cmCMakePresetsErrors::DIAGNOSTIC_UNSUPPORTED(dn, "errors"_s, 12, |
400 | 0 | state); |
401 | 0 | return false; |
402 | 0 | } |
403 | 0 | } |
404 | 0 | } else { |
405 | | // Check for diagnostics removed in v12. |
406 | 0 | if (preset.WarnDev) { |
407 | 0 | cmCMakePresetsErrors::DIAGNOSTIC_REMOVED("dev"_s, "warnings"_s, 11, |
408 | 0 | state); |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | if (preset.ErrorDev) { |
412 | 0 | cmCMakePresetsErrors::DIAGNOSTIC_REMOVED("dev"_s, "errors"_s, 11, state); |
413 | 0 | return false; |
414 | 0 | } |
415 | 0 | } |
416 | | |
417 | 0 | return true; |
418 | 0 | } |
419 | | } |