-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencySource.hpp
More file actions
147 lines (131 loc) · 4.92 KB
/
Copy pathDependencySource.hpp
File metadata and controls
147 lines (131 loc) · 4.92 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
#ifndef RUNCPP2_DATA_DEPENDENCY_SOURCE_HPP
#define RUNCPP2_DATA_DEPENDENCY_SOURCE_HPP
#include "runcpp2/Data/GitSource.hpp"
#include "runcpp2/Data/LocalSource.hpp"
#include "runcpp2/ParseUtil.hpp"
#include "runcpp2/LibYAML_Wrapper.hpp"
#include "ssLogger/ssLog.hpp"
#include "ghc/filesystem.hpp"
#include "mpark/variant.hpp"
#include "DSResult/DSResult.hpp"
#include <memory>
#include <vector>
#include <string>
namespace runcpp2
{
namespace Data
{
struct DependencySource
{
mpark::variant<GitSource, LocalSource> Source;
ghc::filesystem::path ImportPath;
std::vector<std::shared_ptr<DependencySource>> ImportedSources;
inline bool 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;
}
inline std::string 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;
}
inline bool 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;
}
};
}
}
#endif