/src/CMake/Source/cmDebuggerVariablesHelper.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 | | |
4 | | #include "cmDebuggerVariablesHelper.h" |
5 | | |
6 | | #include <algorithm> |
7 | | #include <cstddef> |
8 | | #include <functional> |
9 | | #include <iomanip> |
10 | | #include <iterator> |
11 | | #include <map> |
12 | | #include <sstream> |
13 | | |
14 | | #include "cm_codecvt_Encoding.hxx" |
15 | | |
16 | | #include "cmDebuggerStackFrame.h" |
17 | | #include "cmDebuggerVariables.h" |
18 | | #include "cmFileSet.h" |
19 | | #include "cmGlobalGenerator.h" |
20 | | #include "cmList.h" |
21 | | #include "cmListFileCache.h" |
22 | | #include "cmMakefile.h" |
23 | | #include "cmPropertyMap.h" |
24 | | #include "cmState.h" |
25 | | #include "cmStateSnapshot.h" |
26 | | #include "cmStringAlgorithms.h" |
27 | | #include "cmTarget.h" |
28 | | #include "cmTest.h" |
29 | | #include "cmValue.h" |
30 | | #include "cmake.h" |
31 | | |
32 | | namespace cmDebugger { |
33 | | |
34 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create( |
35 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
36 | | std::string const& name, bool supportsVariableType, |
37 | | cmPolicies::PolicyMap const& policyMap) |
38 | 0 | { |
39 | 0 | static std::map<cmPolicies::PolicyStatus, std::string> policyStatusString = { |
40 | 0 | { cmPolicies::PolicyStatus::OLD, "OLD" }, |
41 | 0 | { cmPolicies::PolicyStatus::WARN, "WARN" }, |
42 | 0 | { cmPolicies::PolicyStatus::NEW, "NEW" }, |
43 | 0 | }; |
44 | |
|
45 | 0 | return std::make_shared<cmDebuggerVariables>( |
46 | 0 | variablesManager, name, supportsVariableType, [=]() { |
47 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
48 | 0 | ret.reserve(cmPolicies::CMPCOUNT); |
49 | 0 | for (int i = 0; i < cmPolicies::CMPCOUNT; ++i) { |
50 | 0 | if (policyMap.IsDefined(static_cast<cmPolicies::PolicyID>(i))) { |
51 | 0 | auto status = policyMap.Get(static_cast<cmPolicies::PolicyID>(i)); |
52 | 0 | std::ostringstream ss; |
53 | 0 | ss << "CMP" << std::setfill('0') << std::setw(4) << i; |
54 | 0 | ret.emplace_back(ss.str(), policyStatusString[status]); |
55 | 0 | } |
56 | 0 | } |
57 | 0 | return ret; |
58 | 0 | }); |
59 | 0 | } |
60 | | |
61 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
62 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
63 | | std::string const& name, bool supportsVariableType, |
64 | | std::vector<std::pair<std::string, std::string>> const& list) |
65 | 0 | { |
66 | 0 | if (list.empty()) { |
67 | 0 | return {}; |
68 | 0 | } |
69 | | |
70 | 0 | auto listVariables = std::make_shared<cmDebuggerVariables>( |
71 | 0 | variablesManager, name, supportsVariableType, [=]() { |
72 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
73 | 0 | ret.reserve(list.size()); |
74 | 0 | for (auto const& kv : list) { |
75 | 0 | ret.emplace_back(kv.first, kv.second); |
76 | 0 | } |
77 | 0 | return ret; |
78 | 0 | }); |
79 | |
|
80 | 0 | listVariables->SetValue(std::to_string(list.size())); |
81 | 0 | return listVariables; |
82 | 0 | } |
83 | | |
84 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
85 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
86 | | std::string const& name, bool supportsVariableType, cmBTStringRange entries) |
87 | 0 | { |
88 | 0 | if (entries.empty()) { |
89 | 0 | return {}; |
90 | 0 | } |
91 | | |
92 | 0 | auto sourceEntries = std::make_shared<cmDebuggerVariables>( |
93 | 0 | variablesManager, name, supportsVariableType); |
94 | |
|
95 | 0 | for (auto const& entry : entries) { |
96 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
97 | 0 | variablesManager, entry.Value, supportsVariableType, [=]() { |
98 | 0 | cmList items{ entry.Value }; |
99 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
100 | 0 | ret.reserve(items.size()); |
101 | 0 | int i = 0; |
102 | 0 | for (std::string const& item : items) { |
103 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), item); |
104 | 0 | } |
105 | 0 | return ret; |
106 | 0 | }); |
107 | 0 | arrayVariables->SetEnableSorting(false); |
108 | 0 | sourceEntries->AddSubVariables(arrayVariables); |
109 | 0 | } |
110 | |
|
111 | 0 | sourceEntries->SetValue(std::to_string(entries.size())); |
112 | 0 | return sourceEntries; |
113 | 0 | } |
114 | | |
115 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
116 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
117 | | std::string const& name, bool supportsVariableType, |
118 | | std::set<std::string> const& values) |
119 | 0 | { |
120 | 0 | if (values.empty()) { |
121 | 0 | return {}; |
122 | 0 | } |
123 | | |
124 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
125 | 0 | variablesManager, name, supportsVariableType, [=]() { |
126 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
127 | 0 | ret.reserve(values.size()); |
128 | 0 | int i = 0; |
129 | 0 | for (std::string const& value : values) { |
130 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), value); |
131 | 0 | } |
132 | 0 | return ret; |
133 | 0 | }); |
134 | 0 | arrayVariables->SetValue(std::to_string(values.size())); |
135 | 0 | arrayVariables->SetEnableSorting(false); |
136 | 0 | return arrayVariables; |
137 | 0 | } |
138 | | |
139 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
140 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
141 | | std::string const& name, bool supportsVariableType, |
142 | | std::vector<std::string> const& values) |
143 | 0 | { |
144 | 0 | if (values.empty()) { |
145 | 0 | return {}; |
146 | 0 | } |
147 | | |
148 | 0 | auto arrayVariables = std::make_shared<cmDebuggerVariables>( |
149 | 0 | variablesManager, name, supportsVariableType, [=]() { |
150 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
151 | 0 | ret.reserve(values.size()); |
152 | 0 | int i = 0; |
153 | 0 | for (std::string const& value : values) { |
154 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), value); |
155 | 0 | } |
156 | 0 | return ret; |
157 | 0 | }); |
158 | |
|
159 | 0 | arrayVariables->SetValue(std::to_string(values.size())); |
160 | 0 | arrayVariables->SetEnableSorting(false); |
161 | 0 | return arrayVariables; |
162 | 0 | } |
163 | | |
164 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
165 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
166 | | std::string const& name, bool supportsVariableType, |
167 | | std::vector<BT<std::string>> const& list) |
168 | 0 | { |
169 | 0 | if (list.empty()) { |
170 | 0 | return {}; |
171 | 0 | } |
172 | | |
173 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
174 | 0 | variablesManager, name, supportsVariableType, [=]() { |
175 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
176 | 0 | ret.reserve(list.size()); |
177 | 0 | int i = 0; |
178 | 0 | for (auto const& item : list) { |
179 | 0 | ret.emplace_back(cmStrCat('[', i++, ']'), item.Value); |
180 | 0 | } |
181 | |
|
182 | 0 | return ret; |
183 | 0 | }); |
184 | |
|
185 | 0 | variables->SetValue(std::to_string(list.size())); |
186 | 0 | variables->SetEnableSorting(false); |
187 | 0 | return variables; |
188 | 0 | } |
189 | | |
190 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
191 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
192 | | std::string const& name, bool supportsVariableType, cmFileSet* fileSet) |
193 | 0 | { |
194 | 0 | if (!fileSet) { |
195 | 0 | return {}; |
196 | 0 | } |
197 | | |
198 | 0 | static auto visibilityString = [](cmFileSetVisibility visibility) { |
199 | 0 | switch (visibility) { |
200 | 0 | case cmFileSetVisibility::Private: |
201 | 0 | return "Private"; |
202 | 0 | case cmFileSetVisibility::Public: |
203 | 0 | return "Public"; |
204 | 0 | case cmFileSetVisibility::Interface: |
205 | 0 | return "Interface"; |
206 | 0 | default: |
207 | 0 | return "Unknown"; |
208 | 0 | } |
209 | 0 | }; |
210 | |
|
211 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
212 | 0 | variablesManager, name, supportsVariableType, [=]() { |
213 | 0 | std::vector<cmDebuggerVariableEntry> ret{ |
214 | 0 | { "Name", fileSet->GetName() }, |
215 | 0 | { "Type", fileSet->GetType() }, |
216 | 0 | { "Visibility", visibilityString(fileSet->GetVisibility()) }, |
217 | 0 | }; |
218 | |
|
219 | 0 | return ret; |
220 | 0 | }); |
221 | |
|
222 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Directories", |
223 | 0 | supportsVariableType, |
224 | 0 | fileSet->GetDirectoryEntries())); |
225 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Files", |
226 | 0 | supportsVariableType, |
227 | 0 | fileSet->GetFileEntries())); |
228 | 0 | return variables; |
229 | 0 | } |
230 | | |
231 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
232 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
233 | | std::string const& name, bool supportsVariableType, |
234 | | std::vector<cmFileSet*> const& fileSets) |
235 | 0 | { |
236 | 0 | if (fileSets.empty()) { |
237 | 0 | return {}; |
238 | 0 | } |
239 | | |
240 | 0 | auto fileSetsVariables = std::make_shared<cmDebuggerVariables>( |
241 | 0 | variablesManager, name, supportsVariableType); |
242 | |
|
243 | 0 | for (auto const& fileSet : fileSets) { |
244 | 0 | fileSetsVariables->AddSubVariables(CreateIfAny( |
245 | 0 | variablesManager, fileSet->GetName(), supportsVariableType, fileSet)); |
246 | 0 | } |
247 | |
|
248 | 0 | return fileSetsVariables; |
249 | 0 | } |
250 | | |
251 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
252 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
253 | | std::string const& name, bool supportsVariableType, |
254 | | std::vector<cmTarget*> const& targets) |
255 | 0 | { |
256 | 0 | if (targets.empty()) { |
257 | 0 | return {}; |
258 | 0 | } |
259 | | |
260 | 0 | auto targetsVariables = std::make_shared<cmDebuggerVariables>( |
261 | 0 | variablesManager, name, supportsVariableType); |
262 | |
|
263 | 0 | for (auto const& target : targets) { |
264 | 0 | auto targetVariables = std::make_shared<cmDebuggerVariables>( |
265 | 0 | variablesManager, target->GetName(), supportsVariableType, [=]() { |
266 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
267 | 0 | { "InstallPath", target->GetInstallPath() }, |
268 | 0 | { "IsAIX", target->IsAIX() }, |
269 | 0 | { "IsAndroidGuiExecutable", target->IsAndroidGuiExecutable() }, |
270 | 0 | { "IsAppBundleOnApple", target->IsAppBundleOnApple() }, |
271 | 0 | { "IsDLLPlatform", target->IsDLLPlatform() }, |
272 | 0 | { "IsExecutableWithExports", target->IsExecutableWithExports() }, |
273 | 0 | { "IsFrameworkOnApple", target->IsFrameworkOnApple() }, |
274 | 0 | { "IsImported", target->IsImported() }, |
275 | 0 | { "IsImportedGloballyVisible", target->IsImportedGloballyVisible() }, |
276 | 0 | { "IsPerConfig", target->IsPerConfig() }, |
277 | 0 | { "Name", target->GetName() }, |
278 | 0 | { "RuntimeInstallPath", target->GetRuntimeInstallPath() }, |
279 | 0 | { "Type", cmState::GetTargetTypeName(target->GetType()) }, |
280 | 0 | }; |
281 | |
|
282 | 0 | return ret; |
283 | 0 | }); |
284 | 0 | targetVariables->SetValue(cmState::GetTargetTypeName(target->GetType())); |
285 | |
|
286 | 0 | targetVariables->AddSubVariables(Create(variablesManager, "PolicyMap", |
287 | 0 | supportsVariableType, |
288 | 0 | target->GetPolicyMap())); |
289 | 0 | targetVariables->AddSubVariables( |
290 | 0 | CreateIfAny(variablesManager, "Properties", supportsVariableType, |
291 | 0 | target->GetProperties().GetList())); |
292 | |
|
293 | 0 | targetVariables->AddSubVariables( |
294 | 0 | CreateIfAny(variablesManager, "IncludeDirectories", supportsVariableType, |
295 | 0 | target->GetIncludeDirectoriesEntries())); |
296 | 0 | targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Sources", |
297 | 0 | supportsVariableType, |
298 | 0 | target->GetSourceEntries())); |
299 | 0 | targetVariables->AddSubVariables( |
300 | 0 | CreateIfAny(variablesManager, "CompileDefinitions", supportsVariableType, |
301 | 0 | target->GetCompileDefinitionsEntries())); |
302 | 0 | targetVariables->AddSubVariables( |
303 | 0 | CreateIfAny(variablesManager, "CompileFeatures", supportsVariableType, |
304 | 0 | target->GetCompileFeaturesEntries())); |
305 | 0 | targetVariables->AddSubVariables( |
306 | 0 | CreateIfAny(variablesManager, "CompileOptions", supportsVariableType, |
307 | 0 | target->GetCompileOptionsEntries())); |
308 | 0 | targetVariables->AddSubVariables( |
309 | 0 | CreateIfAny(variablesManager, "CxxModuleSets", supportsVariableType, |
310 | 0 | target->GetCxxModuleSetsEntries())); |
311 | 0 | targetVariables->AddSubVariables( |
312 | 0 | CreateIfAny(variablesManager, "HeaderSets", supportsVariableType, |
313 | 0 | target->GetHeaderSetsEntries())); |
314 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
315 | 0 | variablesManager, "InterfaceHeaderSets", supportsVariableType, |
316 | 0 | target->GetInterfaceHeaderSetsEntries())); |
317 | 0 | targetVariables->AddSubVariables( |
318 | 0 | CreateIfAny(variablesManager, "LinkDirectories", supportsVariableType, |
319 | 0 | target->GetLinkDirectoriesEntries())); |
320 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
321 | 0 | variablesManager, "LinkImplementations", supportsVariableType, |
322 | 0 | target->GetLinkImplementationEntries())); |
323 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
324 | 0 | variablesManager, "LinkInterfaceDirects", supportsVariableType, |
325 | 0 | target->GetLinkInterfaceDirectEntries())); |
326 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
327 | 0 | variablesManager, "LinkInterfaceDirectExcludes", supportsVariableType, |
328 | 0 | target->GetLinkInterfaceDirectExcludeEntries())); |
329 | 0 | targetVariables->AddSubVariables( |
330 | 0 | CreateIfAny(variablesManager, "LinkInterfaces", supportsVariableType, |
331 | 0 | target->GetLinkInterfaceEntries())); |
332 | 0 | targetVariables->AddSubVariables( |
333 | 0 | CreateIfAny(variablesManager, "LinkOptions", supportsVariableType, |
334 | 0 | target->GetLinkOptionsEntries())); |
335 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
336 | 0 | variablesManager, "SystemIncludeDirectories", supportsVariableType, |
337 | 0 | target->GetSystemIncludeDirectories())); |
338 | 0 | targetVariables->AddSubVariables(CreateIfAny(variablesManager, "Makefile", |
339 | 0 | supportsVariableType, |
340 | 0 | target->GetMakefile())); |
341 | 0 | targetVariables->AddSubVariables( |
342 | 0 | CreateIfAny(variablesManager, "GlobalGenerator", supportsVariableType, |
343 | 0 | target->GetGlobalGenerator())); |
344 | |
|
345 | 0 | std::vector<cmFileSet*> allFileSets; |
346 | 0 | auto allFileSetNames = target->GetAllFileSetNames(); |
347 | 0 | allFileSets.reserve(allFileSetNames.size()); |
348 | 0 | for (auto const& fileSetName : allFileSetNames) { |
349 | 0 | allFileSets.emplace_back(target->GetFileSet(fileSetName)); |
350 | 0 | } |
351 | 0 | targetVariables->AddSubVariables(CreateIfAny( |
352 | 0 | variablesManager, "AllFileSets", supportsVariableType, allFileSets)); |
353 | |
|
354 | 0 | std::vector<cmFileSet*> allInterfaceFileSets; |
355 | 0 | auto allInterfaceFileSetNames = target->GetAllInterfaceFileSets(); |
356 | 0 | allInterfaceFileSets.reserve(allInterfaceFileSetNames.size()); |
357 | 0 | for (auto const& interfaceFileSetName : allInterfaceFileSetNames) { |
358 | 0 | allInterfaceFileSets.emplace_back( |
359 | 0 | target->GetFileSet(interfaceFileSetName)); |
360 | 0 | } |
361 | 0 | targetVariables->AddSubVariables( |
362 | 0 | CreateIfAny(variablesManager, "AllInterfaceFileSets", |
363 | 0 | supportsVariableType, allInterfaceFileSets)); |
364 | |
|
365 | 0 | targetVariables->SetIgnoreEmptyStringEntries(true); |
366 | 0 | targetsVariables->AddSubVariables(targetVariables); |
367 | 0 | } |
368 | |
|
369 | 0 | targetsVariables->SetValue(std::to_string(targets.size())); |
370 | 0 | return targetsVariables; |
371 | 0 | } |
372 | | |
373 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::Create( |
374 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
375 | | std::string const& name, bool supportsVariableType, |
376 | | std::shared_ptr<cmDebuggerStackFrame> const& frame) |
377 | 0 | { |
378 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
379 | 0 | variablesManager, name, supportsVariableType, [=]() { |
380 | 0 | return std::vector<cmDebuggerVariableEntry>{ { "CurrentLine", |
381 | 0 | frame->GetLine() } }; |
382 | 0 | }); |
383 | |
|
384 | 0 | auto closureKeys = frame->GetMakefile()->GetStateSnapshot().ClosureKeys(); |
385 | 0 | auto locals = std::make_shared<cmDebuggerVariables>( |
386 | 0 | variablesManager, "Locals", supportsVariableType, [=]() { |
387 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
388 | 0 | ret.reserve(closureKeys.size()); |
389 | 0 | for (auto const& key : closureKeys) { |
390 | 0 | ret.emplace_back( |
391 | 0 | key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key)); |
392 | 0 | } |
393 | 0 | return ret; |
394 | 0 | }); |
395 | 0 | locals->SetValue(std::to_string(closureKeys.size())); |
396 | 0 | variables->AddSubVariables(locals); |
397 | |
|
398 | 0 | std::function<bool(std::string const&)> isDirectory = |
399 | 0 | [](std::string const& key) { |
400 | 0 | size_t pos1 = key.rfind("_DIR"); |
401 | 0 | size_t pos2 = key.rfind("_DIRECTORY"); |
402 | 0 | return !((pos1 == std::string::npos || pos1 != key.size() - 4) && |
403 | 0 | (pos2 == std::string::npos || pos2 != key.size() - 10)); |
404 | 0 | }; |
405 | 0 | auto directorySize = |
406 | 0 | std::count_if(closureKeys.begin(), closureKeys.end(), isDirectory); |
407 | 0 | auto directories = std::make_shared<cmDebuggerVariables>( |
408 | 0 | variablesManager, "Directories", supportsVariableType, [=]() { |
409 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
410 | 0 | ret.reserve(directorySize); |
411 | 0 | for (auto const& key : closureKeys) { |
412 | 0 | if (isDirectory(key)) { |
413 | 0 | ret.emplace_back( |
414 | 0 | key, frame->GetMakefile()->GetStateSnapshot().GetDefinition(key)); |
415 | 0 | } |
416 | 0 | } |
417 | 0 | return ret; |
418 | 0 | }); |
419 | 0 | directories->SetValue(std::to_string(directorySize)); |
420 | 0 | variables->AddSubVariables(directories); |
421 | |
|
422 | 0 | auto cacheVariables = std::make_shared<cmDebuggerVariables>( |
423 | 0 | variablesManager, "CacheVariables", supportsVariableType); |
424 | 0 | auto* state = frame->GetMakefile()->GetCMakeInstance()->GetState(); |
425 | 0 | auto keys = state->GetCacheEntryKeys(); |
426 | 0 | for (auto const& key : keys) { |
427 | 0 | auto entry = std::make_shared<cmDebuggerVariables>( |
428 | 0 | variablesManager, |
429 | 0 | cmStrCat(key, ':', |
430 | 0 | cmState::CacheEntryTypeToString(state->GetCacheEntryType(key))), |
431 | 0 | supportsVariableType, [=]() { |
432 | 0 | std::vector<cmDebuggerVariableEntry> ret; |
433 | 0 | auto properties = state->GetCacheEntryPropertyList(key); |
434 | 0 | ret.reserve(properties.size() + 2); |
435 | 0 | for (auto const& propertyName : properties) { |
436 | 0 | ret.emplace_back(propertyName, |
437 | 0 | state->GetCacheEntryProperty(key, propertyName)); |
438 | 0 | } |
439 | |
|
440 | 0 | ret.emplace_back( |
441 | 0 | "TYPE", |
442 | 0 | cmState::CacheEntryTypeToString(state->GetCacheEntryType(key))); |
443 | 0 | ret.emplace_back("VALUE", state->GetCacheEntryValue(key)); |
444 | 0 | return ret; |
445 | 0 | }); |
446 | |
|
447 | 0 | entry->SetValue(state->GetCacheEntryValue(key)); |
448 | 0 | cacheVariables->AddSubVariables(entry); |
449 | 0 | } |
450 | |
|
451 | 0 | cacheVariables->SetValue(std::to_string(keys.size())); |
452 | 0 | variables->AddSubVariables(cacheVariables); |
453 | |
|
454 | 0 | auto targetVariables = |
455 | 0 | CreateIfAny(variablesManager, "Targets", supportsVariableType, |
456 | 0 | frame->GetMakefile()->GetOrderedTargets()); |
457 | |
|
458 | 0 | variables->AddSubVariables(targetVariables); |
459 | 0 | std::vector<cmTest*> tests; |
460 | 0 | frame->GetMakefile()->GetTests( |
461 | 0 | frame->GetMakefile()->GetDefaultConfiguration(), tests); |
462 | 0 | variables->AddSubVariables( |
463 | 0 | CreateIfAny(variablesManager, "Tests", supportsVariableType, tests)); |
464 | |
|
465 | 0 | return variables; |
466 | 0 | } |
467 | | |
468 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
469 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
470 | | std::string const& name, bool supportsVariableType, cmTest* test) |
471 | 0 | { |
472 | 0 | if (!test) { |
473 | 0 | return {}; |
474 | 0 | } |
475 | | |
476 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
477 | 0 | variablesManager, name, supportsVariableType, [=]() { |
478 | 0 | std::vector<cmDebuggerVariableEntry> ret{ |
479 | 0 | { "CommandExpandLists", test->GetCommandExpandLists() }, |
480 | 0 | { "Name", test->GetName() }, |
481 | 0 | { "OldStyle", test->GetOldStyle() }, |
482 | 0 | }; |
483 | |
|
484 | 0 | return ret; |
485 | 0 | }); |
486 | |
|
487 | 0 | variables->AddSubVariables(CreateIfAny( |
488 | 0 | variablesManager, "Command", supportsVariableType, test->GetCommand())); |
489 | |
|
490 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "Properties", |
491 | 0 | supportsVariableType, |
492 | 0 | test->GetProperties().GetList())); |
493 | 0 | return variables; |
494 | 0 | } |
495 | | |
496 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
497 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
498 | | std::string const& name, bool supportsVariableType, |
499 | | std::vector<cmTest*> const& tests) |
500 | 0 | { |
501 | 0 | if (tests.empty()) { |
502 | 0 | return {}; |
503 | 0 | } |
504 | | |
505 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
506 | 0 | variablesManager, name, supportsVariableType); |
507 | |
|
508 | 0 | for (auto const& test : tests) { |
509 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, test->GetName(), |
510 | 0 | supportsVariableType, test)); |
511 | 0 | } |
512 | 0 | variables->SetValue(std::to_string(tests.size())); |
513 | 0 | return variables; |
514 | 0 | } |
515 | | |
516 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
517 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
518 | | std::string const& name, bool supportsVariableType, cmMakefile* mf) |
519 | 0 | { |
520 | 0 | if (!mf) { |
521 | 0 | return {}; |
522 | 0 | } |
523 | | |
524 | 0 | auto AppleSDKTypeString = [&](cmMakefile::AppleSDK sdk) { |
525 | 0 | switch (sdk) { |
526 | 0 | case cmMakefile::AppleSDK::MacOS: |
527 | 0 | return "MacOS"; |
528 | 0 | case cmMakefile::AppleSDK::IPhoneOS: |
529 | 0 | return "IPhoneOS"; |
530 | 0 | case cmMakefile::AppleSDK::IPhoneSimulator: |
531 | 0 | return "IPhoneSimulator"; |
532 | 0 | case cmMakefile::AppleSDK::AppleTVOS: |
533 | 0 | return "AppleTVOS"; |
534 | 0 | case cmMakefile::AppleSDK::AppleTVSimulator: |
535 | 0 | return "AppleTVSimulator"; |
536 | 0 | default: |
537 | 0 | return "Unknown"; |
538 | 0 | } |
539 | 0 | }; |
540 | |
|
541 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
542 | 0 | variablesManager, name, supportsVariableType, [=]() { |
543 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
544 | 0 | { "DefineFlags", mf->GetDefineFlags() }, |
545 | 0 | { "DirectoryId", mf->GetDirectoryId().String }, |
546 | 0 | { "IsRootMakefile", mf->IsRootMakefile() }, |
547 | 0 | { "HomeDirectory", mf->GetHomeDirectory() }, |
548 | 0 | { "HomeOutputDirectory", mf->GetHomeOutputDirectory() }, |
549 | 0 | { "CurrentSourceDirectory", mf->GetCurrentSourceDirectory() }, |
550 | 0 | { "CurrentBinaryDirectory", mf->GetCurrentBinaryDirectory() }, |
551 | 0 | { "PlatformIs32Bit", mf->PlatformIs32Bit() }, |
552 | 0 | { "PlatformIs64Bit", mf->PlatformIs64Bit() }, |
553 | 0 | { "PlatformIsx32", mf->PlatformIsx32() }, |
554 | 0 | { "AppleSDKType", AppleSDKTypeString(mf->GetAppleSDKType()) }, |
555 | 0 | { "PlatformIsAppleEmbedded", mf->PlatformIsAppleEmbedded() } |
556 | 0 | }; |
557 | |
|
558 | 0 | return ret; |
559 | 0 | }); |
560 | |
|
561 | 0 | variables->AddSubVariables(CreateIfAny( |
562 | 0 | variablesManager, "ListFiles", supportsVariableType, mf->GetListFiles())); |
563 | 0 | variables->AddSubVariables(CreateIfAny(variablesManager, "OutputFiles", |
564 | 0 | supportsVariableType, |
565 | 0 | mf->GetOutputFiles())); |
566 | |
|
567 | 0 | variables->SetIgnoreEmptyStringEntries(true); |
568 | 0 | variables->SetValue(mf->GetDirectoryId().String); |
569 | 0 | return variables; |
570 | 0 | } |
571 | | |
572 | | std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny( |
573 | | std::shared_ptr<cmDebuggerVariablesManager> const& variablesManager, |
574 | | std::string const& name, bool supportsVariableType, cmGlobalGenerator* gen) |
575 | 0 | { |
576 | 0 | if (!gen) { |
577 | 0 | return {}; |
578 | 0 | } |
579 | | |
580 | 0 | auto makeFileEncodingString = [](codecvt_Encoding encoding) { |
581 | 0 | switch (encoding) { |
582 | 0 | case codecvt_Encoding::None: |
583 | 0 | return "None"; |
584 | 0 | case codecvt_Encoding::UTF8: |
585 | 0 | return "UTF8"; |
586 | 0 | case codecvt_Encoding::UTF8_WITH_BOM: |
587 | 0 | return "UTF8_WITH_BOM"; |
588 | 0 | case codecvt_Encoding::ANSI: |
589 | 0 | return "ANSI"; |
590 | 0 | case codecvt_Encoding::ConsoleOutput: |
591 | 0 | return "ConsoleOutput"; |
592 | 0 | default: |
593 | 0 | return "Unknown"; |
594 | 0 | } |
595 | 0 | }; |
596 | |
|
597 | 0 | auto variables = std::make_shared<cmDebuggerVariables>( |
598 | 0 | variablesManager, name, supportsVariableType, [=]() { |
599 | 0 | std::vector<cmDebuggerVariableEntry> ret = { |
600 | 0 | { "AllTargetName", gen->GetAllTargetName() }, |
601 | 0 | { "CleanTargetName", gen->GetCleanTargetName() }, |
602 | 0 | { "EditCacheCommand", gen->GetEditCacheCommand() }, |
603 | 0 | { "EditCacheTargetName", gen->GetEditCacheTargetName() }, |
604 | 0 | { "ExtraGeneratorName", gen->GetExtraGeneratorName() }, |
605 | 0 | { "ForceUnixPaths", gen->GetForceUnixPaths() }, |
606 | 0 | { "InstallLocalTargetName", gen->GetInstallLocalTargetName() }, |
607 | 0 | { "InstallStripTargetName", gen->GetInstallStripTargetName() }, |
608 | 0 | { "InstallTargetName", gen->GetInstallTargetName() }, |
609 | 0 | { "IsMultiConfig", gen->IsMultiConfig() }, |
610 | 0 | { "Name", gen->GetName() }, |
611 | 0 | { "MakefileEncoding", |
612 | 0 | makeFileEncodingString(gen->GetMakefileEncoding()) }, |
613 | 0 | { "PackageSourceTargetName", gen->GetPackageSourceTargetName() }, |
614 | 0 | { "PackageTargetName", gen->GetPackageTargetName() }, |
615 | 0 | { "PreinstallTargetName", gen->GetPreinstallTargetName() }, |
616 | 0 | { "NeedSymbolicMark", gen->GetNeedSymbolicMark() }, |
617 | 0 | { "RebuildCacheTargetName", gen->GetRebuildCacheTargetName() }, |
618 | 0 | { "TestTargetName", gen->GetTestTargetName() }, |
619 | 0 | { "UseLinkScript", gen->GetUseLinkScript() }, |
620 | 0 | }; |
621 | |
|
622 | 0 | return ret; |
623 | 0 | }); |
624 | |
|
625 | 0 | if (auto const* ic = gen->GetInstallComponents()) { |
626 | 0 | variables->AddSubVariables(CreateIfAny( |
627 | 0 | variablesManager, "InstallComponents", supportsVariableType, *ic)); |
628 | 0 | } |
629 | |
|
630 | 0 | variables->SetIgnoreEmptyStringEntries(true); |
631 | 0 | variables->SetValue(gen->GetName()); |
632 | |
|
633 | 0 | return variables; |
634 | 0 | } |
635 | | |
636 | | } // namespace cmDebugger |