-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInfo.cpp
More file actions
336 lines (283 loc) · 10.8 KB
/
Copy pathDependencyInfo.cpp
File metadata and controls
336 lines (283 loc) · 10.8 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
#include "runcpp2/Data/DependencyInfo.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "runcpp2/Data/ParseCommon.hpp"
#include "ssLogger/ssLog.hpp"
bool runcpp2::Data::DependencyInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
{
INTERNAL_RUNCPP2_SAFE_START();
//If import is needed, we only need to parse the Source section
do
{
if(!ExistAndHasChild(node, "Source"))
{
ssLOG_ERROR("DependencyInfo: Missing Source");
return false;
}
ryml::ConstNodeRef sourceNode = node["Source"];
if(!ExistAndHasChild(sourceNode, "ImportPath"))
break;
if(!Source.ParseYAML_Node(sourceNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse Source");
return false;
}
ssLOG_DEBUG("DependencyInfo: Importing from " << Source.ImportPath.string());
ssLOG_DEBUG("Skipping the rest of the DependencyInfo");
return true;
}
while(false);
std::vector<NodeRequirement> requirements =
{
NodeRequirement("Name", ryml::NodeType_e::KEYVAL, true, false),
NodeRequirement("Platforms", ryml::NodeType_e::SEQ, true, false),
NodeRequirement("Source", ryml::NodeType_e::MAP, true, false),
NodeRequirement("LibraryType", ryml::NodeType_e::KEYVAL, true, false),
NodeRequirement("IncludePaths", ryml::NodeType_e::SEQ, false, true),
NodeRequirement("LinkProperties", ryml::NodeType_e::MAP, false, false),
NodeRequirement("Setup", ryml::NodeType_e::MAP, false, true),
NodeRequirement("Cleanup", ryml::NodeType_e::MAP, false, true),
NodeRequirement("Build", ryml::NodeType_e::MAP, false, true),
NodeRequirement("FilesToCopy", ryml::NodeType_e::MAP, false, true)
};
if(!CheckNodeRequirements(node, requirements))
{
ssLOG_ERROR("DependencyInfo: Failed to meet requirements");
return false;
}
node["Name"] >> Name;
for(int i = 0; i < node["Platforms"].num_children(); ++i)
Platforms.insert(GetValue(node["Platforms"][i]));
ryml::ConstNodeRef sourceNode = node["Source"];
if(!Source.ParseYAML_Node(sourceNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse Source");
return false;
}
static_assert((int)DependencyLibraryType::COUNT == 4, "");
if(node["LibraryType"].val() == "Static")
LibraryType = DependencyLibraryType::STATIC;
else if(node["LibraryType"].val() == "Shared")
LibraryType = DependencyLibraryType::SHARED;
else if(node["LibraryType"].val() == "Object")
LibraryType = DependencyLibraryType::OBJECT;
else if(node["LibraryType"].val() == "Header")
LibraryType = DependencyLibraryType::HEADER;
else
{
ssLOG_ERROR("DependencyInfo: LibraryType is invalid");
return false;
}
if(ExistAndHasChild(node, "IncludePaths"))
{
ryml::ConstNodeRef includePathsNode = node["IncludePaths"];
for(int i = 0; i < includePathsNode.num_children(); i++)
IncludePaths.push_back(GetValue(includePathsNode[i]));
}
if(ExistAndHasChild(node, "LinkProperties"))
{
ryml::ConstNodeRef linkPropertiesNode = node["LinkProperties"];
for(int i = 0; i < linkPropertiesNode.num_children(); ++i)
{
PlatformName platform = GetKey(linkPropertiesNode[i]);
ryml::ConstNodeRef platformNode = linkPropertiesNode[i];
//Insert an empty DependencyLinkProperty and get a reference to it
DependencyLinkProperty& linkProperty = LinkProperties[platform];
if(!linkProperty.ParseYAML_Node(platformNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse LinkProperties for platform " <<
platform);
return false;
}
}
}
else if(LibraryType != DependencyLibraryType::HEADER)
{
ssLOG_ERROR("DependencyInfo: Missing LinkProperties with library type " <<
Data::DependencyLibraryTypeToString(LibraryType));
return false;
}
if(ExistAndHasChild(node, "Setup"))
{
for(int i = 0; i < node["Setup"].num_children(); ++i)
{
ProfilesCommands currentSetup;
ryml::ConstNodeRef currentSetupNode = node["Setup"][i];
if(!currentSetup.ParseYAML_Node(currentSetupNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse Setup");
return false;
}
Setup[GetKey(node["Setup"][i])] = currentSetup;
}
}
if(ExistAndHasChild(node, "Cleanup"))
{
for(int i = 0; i < node["Cleanup"].num_children(); ++i)
{
ProfilesCommands currentCleanup;
ryml::ConstNodeRef currentCleanupNode = node["Cleanup"][i];
if(!currentCleanup.ParseYAML_Node(currentCleanupNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse Cleanup");
return false;
}
Cleanup[GetKey(node["Cleanup"][i])] = currentCleanup;
}
}
if(ExistAndHasChild(node, "Build"))
{
for(int i = 0; i < node["Build"].num_children(); ++i)
{
ProfilesCommands currentBuild;
ryml::ConstNodeRef currentBuildNode = node["Build"][i];
if(!currentBuild.ParseYAML_Node(currentBuildNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse Build");
return false;
}
Build[GetKey(node["Build"][i])] = currentBuild;
}
}
if(ExistAndHasChild(node, "FilesToCopy"))
{
for(int i = 0; i < node["FilesToCopy"].num_children(); ++i)
{
FilesToCopyInfo currentFilesToCopy;
ryml::ConstNodeRef currentFilesToCopyNode = node["FilesToCopy"][i];
PlatformName platform = GetKey(currentFilesToCopyNode);
if(!currentFilesToCopy.ParseYAML_Node(currentFilesToCopyNode))
{
ssLOG_ERROR("DependencyInfo: Failed to parse FilesToCopy");
return false;
}
FilesToCopy[platform] = currentFilesToCopy;
}
}
return true;
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}
std::string runcpp2::Data::DependencyInfo::ToString(std::string indentation) const
{
std::string out;
out += indentation + "Name: " + GetEscapedYAMLString(Name) + "\n";
out += indentation + "Platforms:\n";
for(auto it = Platforms.begin(); it != Platforms.end(); ++it)
out += indentation + "- " + GetEscapedYAMLString(*it) + "\n";
out += indentation + "Source:\n";
out += Source.ToString(indentation + " ");
static_assert((int)DependencyLibraryType::COUNT == 4, "");
if(LibraryType == DependencyLibraryType::STATIC)
out += indentation + "LibraryType: Static\n";
else if(LibraryType == DependencyLibraryType::SHARED)
out += indentation + "LibraryType: Shared\n";
else if(LibraryType == DependencyLibraryType::OBJECT)
out += indentation + "LibraryType: Object\n";
else if(LibraryType == DependencyLibraryType::HEADER)
out += indentation + "LibraryType: Header\n";
if(!IncludePaths.empty())
{
out += indentation + "IncludePaths:\n";
for(auto it = IncludePaths.begin(); it != IncludePaths.end(); ++it)
out += indentation + "- " + GetEscapedYAMLString(*it) + "\n";
}
if(!LinkProperties.empty())
{
out += indentation + "LinkProperties:\n";
for(auto it = LinkProperties.begin(); it != LinkProperties.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!Setup.empty())
{
out += indentation + "Setup:\n";
for(auto it = Setup.begin(); it != Setup.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!Cleanup.empty())
{
out += indentation + "Cleanup:\n";
for(auto it = Cleanup.begin(); it != Cleanup.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!Build.empty())
{
out += indentation + "Build:\n";
for(auto it = Build.begin(); it != Build.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!FilesToCopy.empty())
{
out += indentation + "FilesToCopy:\n";
for(auto it = FilesToCopy.begin(); it != FilesToCopy.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
return out;
}
bool runcpp2::Data::DependencyInfo::Equals(const DependencyInfo& other) const
{
if( Name != other.Name ||
Platforms.size() != other.Platforms.size() ||
!Source.Equals(other.Source) ||
LibraryType != other.LibraryType ||
IncludePaths != other.IncludePaths ||
AbsoluteIncludePaths != other.AbsoluteIncludePaths ||
LinkProperties.size() != other.LinkProperties.size() ||
Setup.size() != other.Setup.size() ||
Cleanup.size() != other.Cleanup.size() ||
Build.size() != other.Build.size() ||
FilesToCopy.size() != other.FilesToCopy.size())
{
return false;
}
for(const std::string& it : Platforms)
{
if(other.Platforms.count(it) == 0)
return false;
}
for(const auto& it : LinkProperties)
{
if( other.LinkProperties.count(it.first) == 0 ||
!other.LinkProperties.at(it.first).Equals(it.second))
{
return false;
}
}
for(const auto& it : Setup)
{
if(other.Setup.count(it.first) == 0 || !other.Setup.at(it.first).Equals(it.second))
return false;
}
for(const auto& it : Cleanup)
{
if(other.Cleanup.count(it.first) == 0 || !other.Cleanup.at(it.first).Equals(it.second))
return false;
}
for(const auto& it : Build)
{
if(other.Build.count(it.first) == 0 || !other.Build.at(it.first).Equals(it.second))
return false;
}
for(const auto& it : FilesToCopy)
{
if( other.FilesToCopy.count(it.first) == 0 ||
!other.FilesToCopy.at(it.first).Equals(it.second))
{
return false;
}
}
return true;
}