-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencySource.cpp
More file actions
119 lines (108 loc) · 3.58 KB
/
Copy pathDependencySource.cpp
File metadata and controls
119 lines (108 loc) · 3.58 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
#include "runcpp2/Data/DependencySource.hpp"
#include "runcpp2/Data/ParseCommon.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "ssLogger/ssLog.hpp"
bool runcpp2::Data::DependencySource::ParseYAML_Node(YAML::ConstNodePtr node)
{
if(ExistAndHasChild(node, "ImportPath"))
{
DS_UNWRAP_ASSIGN_ACT( ImportPath,
node->GetMapValueScalar<std::string>("ImportPath"),
ssLOG_ERROR(DS_TMP_ERROR.ToString()); return false);
if(ImportPath.is_absolute())
{
ssLOG_ERROR("DependencySource: ImportPath must be relative: " << ImportPath.string());
return false;
}
}
if(ExistAndHasChild(node, "Git"))
{
if(ExistAndHasChild(node, "Local"))
{
ssLOG_ERROR("DependencySource: Both Git and Local sources found");
return false;
}
GitSource gitSource;
YAML::ConstNodePtr gitNode = node->GetMapValueNode("Git");
if(!gitSource.ParseYAML_Node(gitNode))
return false;
Source = gitSource;
return true;
}
else if(ExistAndHasChild(node, "Local"))
{
if(ExistAndHasChild(node, "Git"))
{
ssLOG_ERROR("DependencySource: Both Git and Local sources found");
return false;
}
LocalSource localSource;
YAML::ConstNodePtr localNode = node->GetMapValueNode("Local");
if(!localSource.ParseYAML_Node(localNode))
return false;
Source = localSource;
return true;
}
//If no source is found, we need to check if it's an imported source.
//If so, we assume it's a local source with path "./"
else if(!ImportPath.empty())
{
LocalSource localSource;
localSource.Path = "./";
Source = localSource;
return true;
}
ssLOG_ERROR("DependencySource: Neither Git nor Local source found");
return false;
}
std::string runcpp2::Data::DependencySource::ToString(std::string indentation) const
{
std::string out;
if(!ImportPath.empty())
out += indentation + "ImportPath: " + GetEscapedYAMLString(ImportPath.string()) + "\n";
if(mpark::get_if<GitSource>(&Source))
{
const GitSource* git = mpark::get_if<GitSource>(&Source);
out += git->ToString(indentation);
}
else if(mpark::get_if<LocalSource>(&Source))
{
const LocalSource* local = mpark::get_if<LocalSource>(&Source);
out += local->ToString(indentation);
}
else
{
ssLOG_ERROR("Invalid DependencySource type");
return "";
}
return out;
}
bool runcpp2::Data::DependencySource::Equals(const DependencySource& other) const
{
if(ImportPath != other.ImportPath)
return false;
if(mpark::get_if<GitSource>(&Source))
{
if(mpark::get_if<GitSource>(&other.Source))
{
const GitSource* git = mpark::get_if<GitSource>(&Source);
const GitSource* otherGit = mpark::get_if<GitSource>(&other.Source);
return git->Equals(*otherGit);
}
else
return false;
}
else if(mpark::get_if<LocalSource>(&Source))
{
if(mpark::get_if<LocalSource>(&other.Source))
{
const LocalSource* local = mpark::get_if<LocalSource>(&Source);
const LocalSource* otherLocal = mpark::get_if<LocalSource>(&other.Source);
return local->Equals(*otherLocal);
}
else
return false;
}
ssLOG_ERROR("Invalid DependencySource type");
return false;
}