forked from Open-CMSIS-Pack/devtools
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRteItem.cpp
More file actions
1113 lines (969 loc) · 28.3 KB
/
Copy pathRteItem.cpp
File metadata and controls
1113 lines (969 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* RTE - CMSIS Run-Time Environment */
/******************************************************************************/
/** @file RteItem.cpp
* @brief CMSIS RTE Data Model
*/
/******************************************************************************/
/*
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
/******************************************************************************/
#include "RteItem.h"
#include "RteCondition.h"
#include "RtePackage.h"
#include "RteProject.h"
#include "RteModel.h"
#include "RteGenerator.h"
#include "RteConstants.h"
#include "RteFsUtils.h"
#include "VersionCmp.h"
#include "XMLTree.h"
#include "CrossPlatformUtils.h"
using namespace std;
RteItem RteItem::EMPTY_RTE_ITEM(nullptr);
const std::string& RteItem::ConditionResultToString(RteItem::ConditionResult res)
{
static vector<string> CONDITION_RESULT_STRINGS{
"UNDEFINED", // not evaluated yet
"R_ERROR", // error evaluating condition ( recursion detected, condition is missing)
"FAILED", // HW or compiler not match
"MISSING", // no component is installed
"MISSING_API", // no required api is installed
"MISSING_API_VERSION", // no api of required version is installed
"UNAVAILABLE", // component is installed, but filtered out
"UNAVAILABLE_PACK", // component is installed, pack is not selected
"INCOMPATIBLE", // incompatible component is selected
"INCOMPATIBLE_VERSION", // incompatible version of component is selected
"INCOMPATIBLE_VARIANT", // incompatible variant of component is selected
"CONFLICT", // several exclusive or incompatible components are selected
"INSTALLED", // matching component is installed, but not selectable because not in active bundle
"SELECTABLE", // matching component is installed, but not selected
"FULFILLED", // required component selected or no dependency exists
"IGNORED" // condition/expression is irrelevant for the current context
};
if (res < R_ERROR || res > IGNORED) {
res = UNDEFINED;
}
return CONDITION_RESULT_STRINGS[res];
}
RteItem::RteItem(RteItem* parent) :
XmlTreeItem<RteItem>(parent),
m_bValid(false)
{
}
RteItem::RteItem(const std::string& tag, RteItem* parent):
XmlTreeItem<RteItem>(parent, tag),
m_bValid(false)
{
}
RteItem::RteItem(const std::map<std::string, std::string>& attributes, RteItem* parent) :
XmlTreeItem<RteItem>(parent, attributes),
m_bValid(true)
{
};
RteItem::~RteItem()
{
RteItem::Clear(); // must be so: explicit call to this class implementation!
}
void RteItem::Clear()
{
m_bValid = false;
m_errors.clear();
XmlTreeItem::Clear();
}
RteCallback* RteItem::GetCallback() const
{
if (m_parent) {
RteCallback* callback = m_parent->GetCallback();
if(callback) {
return callback;
}
}
return RteCallback::GetGlobal(); // return global one: never nullptr
}
RteModel* RteItem::GetModel() const
{
if (m_parent) {
return m_parent->GetModel();
}
return nullptr;
}
RtePackage* RteItem::GetPackage() const
{
if (m_parent)
return m_parent->GetPackage();
return nullptr;
}
bool RteItem::IsDeprecated() const
{
const string& val = GetItemValue("deprecated");
if (val == "1" || val == "true")
return true;
RtePackage* pack = GetPackage();
if (pack && pack != this)
return pack->IsDeprecated();
return false;
}
RteProject* RteItem::GetProject() const
{
for (RteItem* pItem = GetParent(); pItem != nullptr; pItem = pItem->GetParent()) {
RteProject* pInstance = dynamic_cast<RteProject*>(pItem);
if (pInstance)
return pInstance;
}
return nullptr;
}
RteComponent* RteItem::GetComponent() const
{
if (m_parent)
return m_parent->GetComponent();
return nullptr;
}
const string& RteItem::GetID() const
{
return m_ID;
}
string RteItem::GetDependencyExpressionID() const
{
return GetTag() + " " + GetComponentID(true);
}
string RteItem::GetComponentID(bool withVersion) const // to use in filtered list
{
if (IsApi()) {
return GetApiID(withVersion);
}
return ConstructComponentID(withVersion);
}
string RteItem::GetComponentUniqueID() const
{
if (IsApi()) {
return GetApiID(true);
}
string id = ConstructComponentID(true);
id += RteConstants::OBRACE_STR;
id += GetConditionID();
id += RteConstants::CBRACE_STR;
id += RteConstants::OSQBRACE_STR;
id += GetPackageID(false);
id += RteConstants::CSQBRACE_STR;
return id;
}
string RteItem::GetComponentAggregateID() const
{
const auto& vendor = GetVendorString();
const vector<pair<const char*, const string&>> elements = {
{"", vendor},
{vendor.empty() ? "" :
RteConstants::SUFFIX_CVENDOR, GetCclassName()},
{RteConstants::PREFIX_CBUNDLE, GetCbundleName()},
{RteConstants::PREFIX_CGROUP, GetCgroupName()},
{RteConstants::PREFIX_CSUB, GetCsubName()},
};
return RteUtils::ConstructID(elements);
}
string RteItem::GetPartialComponentID(bool bWithBundle) const {
const vector<pair<const char*, const string&>> elements = {
{"", GetCclassName()},
{RteConstants::PREFIX_CBUNDLE, bWithBundle ? GetCbundleName() : RteUtils::EMPTY_STRING},
{RteConstants::PREFIX_CGROUP, GetCgroupName()},
{RteConstants::PREFIX_CSUB, GetCsubName()},
{RteConstants::PREFIX_CVARIANT, GetCvariantName()},
};
return RteUtils::ConstructID(elements);
}
string RteItem::GetApiID(bool withVersion) const
{
string id;
id += GetCclassName();
id += RteConstants::PREFIX_CGROUP;
id += GetCgroupName();
id += "(API)";
if (withVersion) {
const string& ver = GetAttribute("Capiversion");
if (!ver.empty()) {
id += RteConstants::PREFIX_CVERSION;
id += ver;
}
}
return id;
}
string RteItem::ConcatenateCclassCgroupCsub(char delimiter) const
{
string str = GetCclassName();
str += delimiter;
str += GetCgroupName();
// optional subgroup
if (!GetCsubName().empty()) {
str += delimiter;
str += GetCsubName();
}
return str;
}
void RteItem::SetAttributesFomComponentId(const std::string& componentId)
{
ClearAttributes();
if (componentId.empty()) {
return;
}
string id = componentId;
if (componentId.find(RteConstants::SUFFIX_CVENDOR) != string::npos) {
string vendor = RteUtils::ExtractPrefix(id, RteConstants::SUFFIX_CVENDOR);
AddAttribute("Cvendor", vendor);
SetAttribute("explicitVendor", true);
id = RteUtils::StripPrefix(componentId, RteConstants::SUFFIX_CVENDOR);
}
auto explicitVersion = RteUtils::GetSuffix(id, RteConstants::PREFIX_CVERSION_CHAR, true);
AddAttribute("explicitVersion", explicitVersion);
AddAttribute("Cversion", RteUtils::GetSuffix(explicitVersion, RteConstants::PREFIX_CVERSION_CHAR));
id = RteUtils::GetPrefix(id, RteConstants::PREFIX_CVERSION_CHAR);
list<string> segments;
RteUtils::SplitString(segments, id, RteConstants::COLON_CHAR);
size_t index = 0;
for (auto s : segments) {
switch (index) {
case 0: // Cclass[&Cbundle]
AddAttribute("Cclass", RteUtils::GetPrefix(s, RteConstants::PREFIX_CBUNDLE_CHAR));
AddAttribute("Cbundle", RteUtils::GetSuffix(s, RteConstants::PREFIX_CBUNDLE_CHAR), false);
break;
case 1: // Cgroup[&Cvariant]
AddAttribute("Cgroup", RteUtils::GetPrefix(s, RteConstants::PREFIX_CVARIANT_CHAR));
AddAttribute("Cvariant", RteUtils::GetSuffix(s, RteConstants::PREFIX_CVARIANT_CHAR), false);
break;
case 2: // Csub
AddAttribute("Csub", RteUtils::GetPrefix(s, RteConstants::PREFIX_CVARIANT_CHAR));
AddAttribute("Cvariant", RteUtils::GetSuffix(s, RteConstants::PREFIX_CVARIANT_CHAR), false);
break;
default:
break;
};
index++;
}
}
string RteItem::ConstructComponentID(bool bVersion) const
{
const auto& vendor = GetVendorString();
const auto& version = bVersion ? GetVersionString() : EMPTY_STRING;
const vector<pair<const char*, const string&>> elements = {
{"", vendor},
{vendor.empty() ? "" :
RteConstants::SUFFIX_CVENDOR, GetCclassName()},
{RteConstants::PREFIX_CBUNDLE, GetCbundleName()},
{RteConstants::PREFIX_CGROUP, GetCgroupName()},
{RteConstants::PREFIX_CSUB, GetCsubName()},
{RteConstants::PREFIX_CVARIANT, GetCvariantName()},
{RteConstants::PREFIX_CVERSION, version},
};
return RteUtils::ConstructID(elements);
}
string RteItem::ConstructComponentDisplayName(bool bClass, bool bVariant, bool bVersion, char delimiter) const
{
string id;
if (bClass) {
id += GetCclassName();
id += delimiter;
}
id += GetCgroupName();
// optional subgroup
if (!GetCsubName().empty()) {
id += delimiter;
id += GetCsubName();
}
// optional variant
if (bVariant && !GetCvariantName().empty()) {
id += RteConstants::PREFIX_CVARIANT;
id += GetCvariantName();
}
if (bVersion) {
const string& ver = GetVersionString();
if (!ver.empty()) {
id += RteConstants::PREFIX_CVERSION;
id += ver;
}
}
return id;
}
const Collection<RteItem*>& RteItem::GetItemChildren(RteItem* item)
{
if (item && item->GetChildCount() > 0)
return item->GetChildren();
static const Collection<RteItem*> EMPTY_ITEM_LIST;
return EMPTY_ITEM_LIST;
}
const Collection<RteItem*>& RteItem::GetItemGrandChildren(RteItem* item, const string& tag)
{
RteItem* child = 0;
if (item) {
child = item->GetItemByTag(tag);
}
return GetItemChildren(child);
}
RteItem* RteItem::GetChildByTagAndAttribute(const string& tag, const string& attribute, const string& value) const
{
for (auto child : GetChildren()) {
if ((child->GetTag() == tag) && (child->GetAttribute(attribute) == value))
return child;
}
return nullptr;
}
Collection<RteItem*>& RteItem::GetChildrenByTag(const std::string& tag, Collection<RteItem*>& items) const
{
for (auto child : GetChildren()) {
if ((child->GetTag() == tag)) {
items.push_back(child);
}
}
return items;
}
RteItem* RteItem::GetItem(const string& id) const
{
for (auto item : m_children) {
if (item->GetID() == id)
return item;
}
return nullptr;
}
bool RteItem::HasItem(RteItem* item) const
{
for (auto child : m_children) {
if (item == child)
return true;
}
return false;
}
RteItem* RteItem::GetItemByTag(const string& tag) const
{
return GetFirstChild(tag);
}
const string& RteItem::GetDocValue() const
{
const string& doc = GetItemValue("doc");
if (!doc.empty())
return doc;
return GetDocAttribute();
}
const string& RteItem::GetDocAttribute() const
{
const string& doc = GetAttribute("doc");
if (!doc.empty())
return doc;
return GetAttribute("name");
}
const string& RteItem::GetRteFolder() const
{
const string& rtePath = GetAttribute("rtedir");
return rtePath;
}
const string& RteItem::GetVendorString() const
{
if (IsApi())
return EMPTY_STRING;
const string& cv = GetAttribute("Cvendor");
if (!cv.empty())
return cv;
return GetItemValue("vendor");
}
string RteItem::GetVendorName() const
{
const string& vendor = GetVendorString();
return DeviceVendor::GetCanonicalVendorName(vendor);
};
const string& RteItem::GetVersionString() const
{
if (IsApi())
return GetApiVersionString();
const string& ver = GetAttribute("Cversion");
if (!ver.empty())
return ver;
return GetAttribute("version");
}
const std::string RteItem::GetSemVer(bool returnZeroStringIfEmpty) const
{
return VersionCmp::ToSemVer(GetVersionString(), returnZeroStringIfEmpty);
}
void RteItem::RemoveItem(RteItem* item)
{
RemoveChild(item, false);
}
string RteItem::ConstructID()
{
string id = GetAttribute("id");
if (!id.empty()) {
return id;
}
id = GetName();
if (!GetVersionString().empty()) {
id += ".";
id += GetVersionString();
}
return id;
}
string RteItem::CreateErrorString(const char* severity, const char* errNum, const char* message) const
{
string msg = GetPackageID() + ": " + GetTag() + " '" + GetID() + "': " + severity + " #" + errNum + ": " + message;
return msg;
}
string RteItem::GetDisplayName() const
{
return GetID();
}
string RteItem::GetFullDeviceName() const
{
string fullDeviceName;
const string& variant = GetDeviceVariantName();
if (!variant.empty())
fullDeviceName = variant;
else
fullDeviceName = GetDeviceName();
const string& processor = GetProcessorName();
if (!processor.empty()) {
fullDeviceName += ":";
fullDeviceName += processor;
}
return fullDeviceName;
}
const std::string& RteItem::GetYamlDeviceAttribute(const string& rteName, const string& defaultValue)
{
const string& rteValue = GetAttribute(rteName);
if(rteValue.empty()) {
return defaultValue;
}
const string& yamlValue = RteConstants::GetDeviceAttribute(rteName, rteValue);
return !yamlValue.empty() ? yamlValue : rteValue;
}
string RteItem::GetProjectGroupName() const
{
const string& cclass = GetCclassName();
if(!cclass.empty()) {
return string(RteConstants::SUFFIX_CVENDOR) + GetCclassName();
}
return RteUtils::EMPTY_STRING;
}
string RteItem::GetBundleShortID() const
{
return GetBundleID(false);
};
string RteItem::GetBundleID(bool bWithVersion) const
{
if (!GetCbundleName().empty()) {
string s = GetVendorString();
if (!s.empty()) {
s += RteConstants::SUFFIX_CVENDOR;
}
s += GetCclassName() + RteConstants::PREFIX_CBUNDLE + GetCbundleName();
if (bWithVersion && !GetVersionString().empty()) {
s += RteConstants::PREFIX_CVERSION;
s += GetVersionString();
}
return s;
}
return EMPTY_STRING;
}
string RteItem::GetTaxonomyDescriptionID() const
{
return RteItem::GetTaxonomyDescriptionID(*this);
}
string RteItem::GetTaxonomyDescriptionID(const XmlItem& attributes)
{
string taxonomyId = attributes.GetAttribute("Cclass"); // taxonomy must have at least Cclass attribute
if (!taxonomyId.empty()) {
const string& group = attributes.GetAttribute("Cgroup");
if (!group.empty()) {
taxonomyId += RteConstants::PREFIX_CGROUP + group;
const string& sub = attributes.GetAttribute("Csub");
if (!sub.empty()) {
taxonomyId += RteConstants::PREFIX_CSUB + sub;
}
}
}
return taxonomyId;
}
string RteItem::GetPackageID(bool withVersion) const
{
RtePackage* package = GetPackage();
if (!package || package == this) {
return RtePackage::GetPackageIDfromAttributes(*this, withVersion);
}
return package->GetPackageID(withVersion);
}
string RteItem::GetPackagePath(bool withVersion) const
{
string path = EMPTY_STRING;
RtePackage* package = GetPackage();
if (package) {
path = package->GetPackagePath(withVersion);
}
return path;
}
PackageState RteItem::GetPackageState() const
{
RtePackage* package = GetPackage();
if (package) {
return package->GetPackageState();
}
return PackageState::PS_UNKNOWN;
}
const string& RteItem::GetPackageFileName() const
{
return GetRootFileName();
}
bool RteItem::MatchesHost() const
{
return MatchesHost(CrossPlatformUtils::GetHostType());
}
bool RteItem::MatchesHost(const string& hostType) const
{
const string& host = GetAttribute("host");
return (host.empty() || host == "all" ||
host == (hostType.empty() ? CrossPlatformUtils::GetHostType() : hostType));
}
RteComponent* RteItem::FindComponents(const RteItem& item, list<RteComponent*>& components) const
{
for (auto child : GetChildren()) {
if (child->GetTag() == "bundle" && item.GetCbundleName() == child->GetCbundleName()) {
return child->FindComponents(item, components);
}
RteComponent* c = dynamic_cast<RteComponent*>(child);
if (c && c->MatchComponent(item)) {
components.push_back(c);
}
}
return components.empty() ? nullptr : *(components.begin());
}
bool RteItem::MatchComponent(const RteItem& item) const
{
if (!item.GetConditionID().empty() && item.GetConditionID() != GetConditionID()) {
return false;
}
return MatchComponentAttributes(item.GetAttributes());
}
bool RteItem::MatchComponentAttributes(const map<string, string>& attributes, bool bRespectVersion) const
{
if (attributes.empty()) // no limiting attributes
return true;
for (auto [ a, v] : attributes) {
if (a.empty() || a.at(0) != 'C')
continue; // we are interested only in Cclass, Cgroup, etc.
auto it = m_attributes.find(a);
if (it == m_attributes.end()) { // no such attribute in the component
if (v.empty() || a == "Capiversion")
continue; // ok: it is required that this attribute is not set or empty
else
return false;
}
if (a == "Cversion" || a == "Capiversion") { // version of this component should match supplied version range
int verCompareResult = bRespectVersion? VersionCmp::CompatibleRangeCompare(it->second, v) : 0;
if (verCompareResult != 0)
return false;
} else {
if (!WildCards::Match(v, it->second))
return false;
}
}
return true; // no other checks
}
bool RteItem::MatchApiAttributes(const map<string, string>& attributes, bool bRespectVersion) const
{
if (attributes.empty())
return false;
for (auto [a, v] : m_attributes) {
if (!a.empty() && a[0] == 'C' && a != "Cvendor") {
auto ita = attributes.find(a);
if (a == "Capiversion") { // version of this api should be >= supplied version, but less than next major
if (ita == attributes.end())
continue; // version is not set => accept any
if (bRespectVersion && VersionCmp::CompatibleRangeCompare(v, ita->second) != 0) // this version is within supplied range
return false;
} else {
if (ita == attributes.end()) // no api attribute in supplied map
return false;
if (!WildCards::Match(v, ita->second))
return false;
}
}
}
return true; // no other checks
}
bool RteItem::MatchDeviceAttributes(const map<string, string>& attributes) const
{
if (attributes.empty())
return false;
map<string, string>::const_iterator itm, ita;
for (auto [a, v] : m_attributes) {
if (!a.empty() && a[0] == 'D') {
auto ita = attributes.find(a);
if (ita == attributes.end()) // no attribute in supplied map
return false;
const string& va = ita->second;
if (a == "Dvendor") {
if (!DeviceVendor::Match(va, v))
return false;
} else if (!WildCards::Match(v, ita->second)) {
return false;
}
}
}
return true; // all attributes are found in supplied map
}
bool RteItem::MatchDevice(const map<string, string>& attributes) const
{
if (attributes.empty())
return false;
for (auto [a, v] : m_attributes) {
if (a == "Dname" || a == "Pname" || a == "Dvendor") {
auto ita = attributes.find(a);
if (ita == attributes.end()) // no attribute in supplied map
return false;
const string& va = ita->second;
if (a == "Dvendor") {
if (!DeviceVendor::Match(va, v))
return false;
} else if (!WildCards::Match(v, ita->second)) {
return false;
}
}
}
return true; // all attributes are found in supplied map
}
bool RteItem::HasMaxInstances() const
{
return !GetAttribute("maxInstances").empty();
}
int RteItem::GetMaxInstances() const
{
int n = GetAttributeAsInt("maxInstances", 1);
if (n > 1)
return n;
return 1; // not specified, single instance : default is always one
}
const string& RteItem::GetDescription() const {
const string& description = GetItemValue("description");
if (!description.empty())
return description;
return GetText();
}
string RteItem::GetDocFile() const
{
const string& doc = GetDocValue();
if (doc.empty()) {
return doc;
}
if (doc.find(":") != string::npos || doc.find("www.") == 0 || doc.find("\\\\") == 0) { // a url or absolute?
return doc;
}
RtePackage* p = GetPackage();
if (p) {
return p->GetAbsolutePackagePath() + doc;
}
return EMPTY_STRING;
}
string RteItem::GetAccessPermissions() const
{
string access = GetAccess();
if (access.empty()) {
access = string(IsReadAccess() ? "r" : "") + (IsWriteAccess() ? "w" : "") + (IsExecuteAccess() ? "x" : "");
}
return access;
}
std::pair<std::string, std::string> RteItem::GetAccessAttributes() const
{
return {
string(IsReadAccess() ? "r" : "") +
(IsWriteAccess() ? "w" : "") +
(IsExecuteAccess() ? "x" : ""),
string(IsPeripheralAccess() ? "p" : "") +
(IsSecureAccess() ? "s" : "") +
(IsNonSecureAccess() ? "n" : "") +
(IsCallableAccess() ? "c" : "")
};
}
bool RteItem::IsReadAccess() const
{
if (HasAttribute("id")) {
return true;
}
const string& access = GetAccess();
return access.empty() || access.find('r') != string::npos;
}
bool RteItem::IsWriteAccess() const
{
const string& id = GetAttribute("id");
if (!id.empty()) {
return id.find("IRAM") == 0;
}
const string& access = GetAccess();
return access.find('w') != string::npos;
}
bool RteItem::IsExecuteAccess() const
{
const string& id = GetAttribute("id");
if (!id.empty()) {
return id.find("IROM") == 0 || id.find("IRAM") == 0;
}
const string& access = GetAccess();
return access.find('x') != string::npos;
}
bool RteItem::IsSecureAccess() const
{
if (HasAttribute("id")) {
return true;
}
const string& access = GetAccess();
return access.find('s') != string::npos && access.find('n') == string::npos;
}
bool RteItem::IsNonSecureAccess() const
{
if (HasAttribute("id")) {
return false;
}
const string& access = GetAccess();
return access.find('n') != string::npos && access.find('s') == string::npos;
}
bool RteItem::IsCallableAccess() const
{
if (HasAttribute("id")) {
return false;
}
const string& access = GetAccess();
return access.find('c') != string::npos;
}
bool RteItem::IsPeripheralAccess() const
{
if (HasAttribute("id")) {
return false;
}
const string& access = GetAccess();
return access.find('p') != string::npos;
}
string RteItem::GetOriginalAbsolutePath() const
{
return GetOriginalAbsolutePath(GetName());
}
string RteItem::GetOriginalAbsolutePath(const string& name) const
{
if (name.empty() || name.find(":") != string::npos || name.find("www.") == 0 || name.find("\\\\") == 0) { // a url or absolute?
return name;
}
RtePackage* p = GetPackage();
string absPath;
if (p) {
absPath = p->GetAbsolutePackagePath();
}
absPath += name;
return RteFsUtils::MakePathCanonical(absPath);
}
string RteItem::GetInstancePathName(const RteTarget* target, int instanceIndex, const string& rteFolder) const
{
if(target && IsConfig()) {
// construct RTE/Device/Dname/fileName.ext
string pathName = rteFolder + "/";
auto deviceName = target->GetFullDeviceName();
if(!deviceName.empty() && IsDeviceDependent()) {
pathName += "Device/";
string device = WildCards::ToX(deviceName);
if(!device.empty()) {
pathName += device;
pathName += "/";
}
}
return pathName + RteUtils::ExtractFileName(GetName());
}
// return absolute path in pack repo
return GetOriginalAbsolutePath();
}
string RteItem::ExpandString(const string& str, bool bUseAccessSequences, RteItem* context) const
{
if (str.empty())
return str;
if(context && context != this) {
return context->ExpandString(str, bUseAccessSequences, context);
}
RteCallback* pCallback = GetCallback();
if (pCallback)
return pCallback->ExpandString(str);
return str;
}
string RteItem::GetDownloadUrl(bool withVersion, const char* extension) const
{
string url = EMPTY_STRING;
RtePackage* package = GetPackage();
if (package && package != this) {
url = package->GetDownloadUrl(withVersion, extension);
}
return url;
}
RteCondition* RteItem::GetCondition() const
{
return GetCondition(GetConditionID());
}
RteCondition* RteItem::GetCondition(const string& id) const
{
if (m_parent && !id.empty())
return m_parent->GetCondition(id);
return nullptr;
}
RteItem* RteItem::GetLicenseSet() const
{
RtePackage* pack = GetPackage();
if(pack) {
return pack->GetLicenseSet(GetAttribute("licenseSet"));
}
return nullptr;
}
RteItem* RteItem::GetDefaultChild() const
{
for (auto item : GetChildren()) {
if (item->IsDefault()) {
return item;
}
}
return nullptr;
}
bool RteItem::IsConfig() const
{
return GetAttribute("attr") == "config";
}
bool RteItem::IsDeviceDependent() const
{
RteCondition *condition = GetCondition();
return condition && condition->IsDeviceDependent();
}
bool RteItem::IsBoardDependent() const
{
RteCondition* condition = GetCondition();
return condition && condition->IsBoardDependent();
}
RteItem::ConditionResult RteItem::Evaluate(RteConditionContext* context)
{
RteCondition* condition = GetCondition();
if (condition) {
if (context->IsVerbose()) {
GetCallback()->OutputMessage(GetID());
}
return context->Evaluate(condition);
}
return IGNORED;
}
RteItem::ConditionResult RteItem::GetConditionResult(RteConditionContext* context) const
{
RteCondition* condition = GetCondition();
if (condition)
return context->GetConditionResult(condition);
return IGNORED;
}
RteItem::ConditionResult RteItem::GetDepsResult(map<const RteItem*, RteDependencyResult>& results, RteTarget* target) const
{
ConditionResult r = RteDependencyResult::GetResult(this, results);
if (r != UNDEFINED)
return r;
ConditionResult result = GetConditionResult(target->GetDependencySolver());
if (result < FULFILLED && result > FAILED && result != CONFLICT) { // CONFLICT is reported by corresponding API
RteCondition* condition = GetCondition();
if (condition) {
RteDependencyResult depRes(this, result);
result = condition->GetDepsResult(depRes.Results(), target);
results[this] = depRes;
}
}