-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsource.h
More file actions
270 lines (220 loc) · 7.27 KB
/
source.h
File metadata and controls
270 lines (220 loc) · 7.27 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
/*
* Copyright (C) 2016-2017, Egor Pugin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "property_tree.h"
#include "version.h"
#include <variant>
namespace YAML { class Node; }
using yaml = YAML::Node;
struct SourceUrl
{
String url;
SourceUrl() = default;
SourceUrl(const yaml &root, const String &name);
bool empty() const { return url.empty(); }
bool isValid(const String &name, String *error = nullptr) const;
bool isValidUrl() const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name) const;
String print() const;
void applyVersion(const Version &v);
void loadVersion(Version &v) const {}
protected:
template <typename ... Args>
bool checkValid(const String &name, String *error, Args && ... args) const;
};
struct Git : SourceUrl
{
String tag;
String branch;
String commit;
Git() = default;
Git(const yaml &root, const String &name = Git::getString());
void download() const;
bool isValid(String *error = nullptr) const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = Git::getString()) const;
String print() const;
String printCpp() const;
void applyVersion(const Version &v);
void loadVersion(Version &v) const;
bool operator==(const Git &rhs) const
{
return std::tie(url, tag, branch, commit) == std::tie(rhs.url, rhs.tag, rhs.branch, rhs.commit);
}
static String getString() { return "git"; }
};
struct Hg : Git
{
int64_t revision = -1;
Hg() = default;
Hg(const yaml &root, const String &name = Hg::getString());
void download() const;
bool isValid(String *error = nullptr) const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = Hg::getString()) const;
String print() const;
String printCpp() const;
void loadVersion(Version &v) const;
bool operator==(const Hg &rhs) const
{
return std::tie(url, tag, branch, commit, revision) == std::tie(rhs.url, rhs.tag, rhs.branch, rhs.commit, rhs.revision);
}
static String getString() { return "hg"; }
};
struct Bzr : SourceUrl
{
String tag;
int64_t revision = -1;
Bzr() = default;
Bzr(const yaml &root, const String &name = Bzr::getString());
void download() const;
bool isValid(String *error = nullptr) const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = Bzr::getString()) const;
String print() const;
String printCpp() const;
void loadVersion(Version &v) const;
bool operator==(const Bzr &rhs) const
{
return std::tie(url, tag, revision) == std::tie(rhs.url, rhs.tag, rhs.revision);
}
static String getString() { return "bzr"; }
};
struct Fossil : Git
{
Fossil() = default;
Fossil(const yaml &root, const String &name = Fossil::getString());
void download() const;
using Git::save;
void save(yaml &root, const String &name = Fossil::getString()) const;
void loadVersion(Version &v) const;
bool operator==(const Fossil &rhs) const
{
return std::tie(url, tag, branch, commit) == std::tie(rhs.url, rhs.tag, rhs.branch, rhs.commit);
}
static String getString() { return "fossil"; }
};
struct Cvs : SourceUrl
{
String tag;
String branch;
String revision;
String module;
Cvs() = default;
Cvs(const yaml &root, const String &name = Cvs::getString());
void download() const;
bool isValid(String *error = nullptr) const;
bool isValidUrl() const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = Cvs::getString()) const;
String print() const;
String printCpp() const;
void loadVersion(Version &v) const;
bool operator==(const Cvs &rhs) const
{
return std::tie(url, tag, branch, revision, module) == std::tie(rhs.url, rhs.tag, rhs.branch, rhs.revision, rhs.module);
}
static String getString() { return "cvs"; }
};
struct Svn : SourceUrl
{
String tag;
String branch;
int64_t revision = -1;
Svn() = default;
Svn(const yaml &root, const String &name = Svn::getString());
void download() const;
bool isValid(String *error = nullptr) const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = Svn::getString()) const;
String print() const;
String printCpp() const;
void applyVersion(const Version &v);
void loadVersion(Version &v) const;
bool operator==(const Svn &rhs) const
{
return std::tie(url, tag, branch, revision) == std::tie(rhs.url, rhs.tag, rhs.branch, rhs.revision);
}
static String getString() { return "svn"; }
};
struct RemoteFile : SourceUrl
{
RemoteFile() = default;
RemoteFile(const yaml &root, const String &name = RemoteFile::getString());
void download() const;
using SourceUrl::save;
void save(yaml &root, const String &name = RemoteFile::getString()) const;
String printCpp() const;
void applyVersion(const Version &v);
bool operator==(const RemoteFile &rhs) const
{
return url == rhs.url;
}
static String getString() { return "remote"; }
};
struct RemoteFiles
{
StringSet urls;
RemoteFiles() = default;
RemoteFiles(const yaml &root, const String &name = RemoteFiles::getString());
void download() const;
bool empty() const { return urls.empty(); }
bool isValidUrl() const;
bool load(const ptree &p);
bool save(ptree &p) const;
void save(yaml &root, const String &name = RemoteFiles::getString()) const;
String print() const;
String printCpp() const;
void applyVersion(const Version &v);
void loadVersion(Version &v) const {}
bool operator==(const RemoteFiles &rhs) const
{
return urls == rhs.urls;
}
static String getString() { return "files"; }
};
// TODO: add: svn, cvs, darcs, p4
// do not add local files
#define SOURCE_TYPES(f,d) \
f(Git) d \
f(Hg) d \
f(Bzr) d \
f(Fossil) d \
f(Cvs) d \
f(Svn) d \
f(RemoteFile) d \
f(RemoteFiles)
#define DELIM_COMMA ,
#define DELIM_SEMICOLON ;
#define SOURCE_TYPES_EMPTY(x) x
using Source = std::variant<SOURCE_TYPES(SOURCE_TYPES_EMPTY, DELIM_COMMA)>;
#undef SOURCE_TYPES_EMPTY
void download(const Source &source, int64_t max_file_size = 0);
bool load_source(const yaml &root, Source &source);
Source load_source(const ptree &p);
void save_source(yaml &root, const Source &source);
void save_source(ptree &p, const Source &source);
String print_source(const Source &source);
String print_source_cpp(const Source &source);
void applyVersionToUrl(Source &source, const Version &v);
bool isValidSourceUrl(const Source &source);