-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptInfo.cpp
More file actions
312 lines (267 loc) · 10.4 KB
/
Copy pathScriptInfo.cpp
File metadata and controls
312 lines (267 loc) · 10.4 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
#include "runcpp2/Data/ScriptInfo.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "runcpp2/Data/ParseCommon.hpp"
#include "ssLogger/ssLog.hpp"
bool runcpp2::Data::ScriptInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
{
ssLOG_FUNC_DEBUG();
INTERNAL_RUNCPP2_SAFE_START();
std::vector<NodeRequirement> requirements =
{
NodeRequirement("PassScriptPath", ryml::NodeType_e::KEYVAL, false, true),
NodeRequirement("Language", ryml::NodeType_e::KEYVAL, false, true),
NodeRequirement("RequiredProfiles", ryml::NodeType_e::MAP, false, true),
NodeRequirement("OverrideCompileFlags", ryml::NodeType_e::MAP, false, true),
NodeRequirement("OverrideLinkFlags", ryml::NodeType_e::MAP, false, true),
NodeRequirement("OtherFilesToBeCompiled", ryml::NodeType_e::MAP, false, true),
NodeRequirement("Dependencies", ryml::NodeType_e::SEQ, false, true),
NodeRequirement("Defines", ryml::NodeType_e::MAP, false, true)
};
if(!CheckNodeRequirements(node, requirements))
{
ssLOG_ERROR("ScriptInfo: Failed to meet requirements");
return false;
}
if(ExistAndHasChild(node, "PassScriptPath"))
{
std::string passScriptPathStr = GetValue(node["PassScriptPath"]);
for(size_t i = 0; i < passScriptPathStr.length(); ++i)
passScriptPathStr[i] = std::tolower(passScriptPathStr[i]);
if(passScriptPathStr == "true" || passScriptPathStr == "1")
PassScriptPath = true;
else if(passScriptPathStr == "false" || passScriptPathStr == "0")
PassScriptPath = false;
else
{
ssLOG_ERROR("ScriptInfo: Invalid value for PassScriptPath: " << passScriptPathStr);
ssLOG_ERROR("Expected true/false or 1/0");
return false;
}
}
if(ExistAndHasChild(node, "Language"))
node["Language"] >> Language;
if(ExistAndHasChild(node, "RequiredProfiles"))
{
for(int i = 0; i < node["RequiredProfiles"].num_children(); ++i)
{
if(!INTERNAL_RUNCPP2_BIT_CONTANTS( node["RequiredProfiles"][i].type().type,
ryml::NodeType_e::SEQ))
{
ssLOG_ERROR("ScriptInfo: RequiredProfiles requires a sequence");
return false;
}
PlatformName platform = GetKey(node["RequiredProfiles"][i]);
std::vector<ProfileName> profiles;
for(int j = 0; j < node["RequiredProfiles"][i].num_children(); ++j)
profiles.push_back(GetValue(node["RequiredProfiles"][i][j]));
RequiredProfiles[platform] = profiles;
}
}
if(ExistAndHasChild(node, "OverrideCompileFlags"))
{
ryml::ConstNodeRef overrideCompileFlagsNode = node["OverrideCompileFlags"];
for(int i = 0; i < overrideCompileFlagsNode.num_children(); ++i)
{
PlatformName platform = GetKey(overrideCompileFlagsNode[i]);
ProfilesFlagsOverride compileFlags;
ryml::ConstNodeRef currentCompileFlagsNode = overrideCompileFlagsNode[i];
if(!compileFlags.ParseYAML_Node(currentCompileFlagsNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse OverrideCompileFlags.");
return false;
}
OverrideCompileFlags[platform] = compileFlags;
}
}
if(ExistAndHasChild(node, "OverrideLinkFlags"))
{
ryml::ConstNodeRef overrideLinkFlagsNode = node["OverrideLinkFlags"];
for(int i = 0; i < overrideLinkFlagsNode.num_children(); ++i)
{
PlatformName platform = GetKey(overrideLinkFlagsNode[i]);
ProfilesFlagsOverride linkFlags;
ryml::ConstNodeRef currentLinkFlagsNode = overrideLinkFlagsNode[i];
if(!linkFlags.ParseYAML_Node(currentLinkFlagsNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse OverrideLinkFlags.");
return false;
}
OverrideLinkFlags[platform] = linkFlags;
}
}
if(ExistAndHasChild(node, "OtherFilesToBeCompiled"))
{
for(int i = 0; i < node["OtherFilesToBeCompiled"].num_children(); ++i)
{
ProfilesCompilesFiles compilesFiles;
ryml::ConstNodeRef currentProfileMapNode = node["OtherFilesToBeCompiled"][i];
PlatformName platform = GetKey(currentProfileMapNode);
if(!compilesFiles.ParseYAML_Node(currentProfileMapNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse OtherFilesToBeCompiled.");
return false;
}
OtherFilesToBeCompiled[platform] = compilesFiles;
}
}
if(ExistAndHasChild(node, "Dependencies"))
{
for(int i = 0; i < node["Dependencies"].num_children(); ++i)
{
DependencyInfo info;
ryml::ConstNodeRef dependencyNode = node["Dependencies"][i];
if(!info.ParseYAML_Node(dependencyNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse DependencyInfo at index " << i);
return false;
}
Dependencies.push_back(info);
}
}
if(ExistAndHasChild(node, "Defines"))
{
ryml::ConstNodeRef definesNode = node["Defines"];
for(int i = 0; i < definesNode.num_children(); ++i)
{
PlatformName platform = GetKey(definesNode[i]);
ProfilesDefines profilesDefines;
ryml::ConstNodeRef currentDefinesNode = definesNode[i];
if(!profilesDefines.ParseYAML_Node(currentDefinesNode))
{
ssLOG_ERROR("ScriptInfo: Failed to parse Defines.");
return false;
}
Defines[platform] = profilesDefines;
}
}
return true;
INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}
std::string runcpp2::Data::ScriptInfo::ToString(std::string indentation) const
{
std::string out;
out += indentation + "PassScriptPath: " + (PassScriptPath ? "true" : "false") + "\n";
if(!Language.empty())
out += indentation + "Language: " + GetEscapedYAMLString(Language) + "\n";
if(!RequiredProfiles.empty())
{
out += indentation + "RequiredProfiles:\n";
for(auto it = RequiredProfiles.begin(); it != RequiredProfiles.end(); ++it)
{
if(it->second.empty())
out += indentation + " " + it->first + ": []\n";
else
{
out += indentation + " " + it->first + ":\n";
for(int i = 0; i < it->second.size(); ++i)
out += indentation + " - " + GetEscapedYAMLString(it->second[i]) + "\n";
}
}
}
if(!OverrideCompileFlags.empty())
{
out += indentation + "OverrideCompileFlags:\n";
for(auto it = OverrideCompileFlags.begin(); it != OverrideCompileFlags.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!OverrideLinkFlags.empty())
{
out += indentation + "OverrideLinkFlags:\n";
for(auto it = OverrideLinkFlags.begin(); it != OverrideLinkFlags.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!OtherFilesToBeCompiled.empty())
{
out += indentation + "OtherFilesToBeCompiled:\n";
for(auto it = OtherFilesToBeCompiled.begin(); it != OtherFilesToBeCompiled.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
if(!Dependencies.empty())
{
out += indentation + "Dependencies:\n";
for(int i = 0; i < Dependencies.size(); ++i)
{
int currentOutSize = out.size();
out += Dependencies[i].ToString(indentation + " ");
//Change character to yaml list
out.at(currentOutSize + indentation.size()) = '-';
}
}
if(!Defines.empty())
{
out += indentation + "Defines:\n";
for(auto it = Defines.begin(); it != Defines.end(); ++it)
{
out += indentation + " " + it->first + ":\n";
out += it->second.ToString(indentation + " ");
}
}
return out;
}
bool runcpp2::Data::ScriptInfo::Equals(const ScriptInfo& other) const
{
if( Language != other.Language ||
PassScriptPath != other.PassScriptPath ||
RequiredProfiles.size() != other.RequiredProfiles.size() ||
OverrideCompileFlags.size() != other.OverrideCompileFlags.size() ||
OverrideLinkFlags.size() != other.OverrideLinkFlags.size() ||
OtherFilesToBeCompiled.size() != other.OtherFilesToBeCompiled.size() ||
Dependencies.size() != other.Dependencies.size() ||
Defines.size() != other.Defines.size() ||
Populated != other.Populated)
{
return false;
}
for(const auto& it : RequiredProfiles)
{
if( other.RequiredProfiles.count(it.first) == 0 ||
other.RequiredProfiles.at(it.first) != it.second)
{
return false;
}
}
for(const auto& it : OverrideCompileFlags)
{
if( other.OverrideCompileFlags.count(it.first) == 0 ||
!other.OverrideCompileFlags.at(it.first).Equals(it.second))
{
return false;
}
}
for(const auto& it : OverrideLinkFlags)
{
if( other.OverrideLinkFlags.count(it.first) == 0 ||
!other.OverrideLinkFlags.at(it.first).Equals(it.second))
{
return false;
}
}
for(const auto& it : OtherFilesToBeCompiled)
{
if( other.OtherFilesToBeCompiled.count(it.first) == 0 ||
!other.OtherFilesToBeCompiled.at(it.first).Equals(it.second))
{
return false;
}
}
for(size_t i = 0; i < Dependencies.size(); ++i)
{
if(!Dependencies[i].Equals(other.Dependencies[i]))
return false;
}
for(const auto& it : Defines)
{
if(other.Defines.count(it.first) == 0 || !other.Defines.at(it.first).Equals(it.second))
return false;
}
return true;
}