forked from microsoft/vcpkg-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourceparagraph.h
217 lines (174 loc) · 8.86 KB
/
sourceparagraph.h
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
#pragma once
#include <vcpkg/fwd/configuration.h>
#include <vcpkg/fwd/packagespec.h>
#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/base/expected.h>
#include <vcpkg/base/json.h>
#include <vcpkg/base/path.h>
#include <vcpkg/base/span.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/paragraphparser.h>
#include <vcpkg/platform-expression.h>
#include <vcpkg/versions.h>
namespace vcpkg
{
struct ManifestAndPath
{
Json::Object manifest;
Path path;
};
struct DependencyConstraint
{
VersionConstraintKind type = VersionConstraintKind::None;
std::string value;
int port_version = 0;
friend bool operator==(const DependencyConstraint& lhs, const DependencyConstraint& rhs);
friend bool operator!=(const DependencyConstraint& lhs, const DependencyConstraint& rhs)
{
return !(lhs == rhs);
}
Optional<Version> try_get_minimum_version() const;
};
struct DependencyRequestedFeature
{
std::string name;
PlatformExpression::Expr platform;
friend bool operator==(const DependencyRequestedFeature& lhs, const DependencyRequestedFeature& rhs);
friend bool operator!=(const DependencyRequestedFeature& lhs, const DependencyRequestedFeature& rhs);
};
struct Dependency
{
std::string name;
// a list of "real" features without "core" or "default". Use member default_features instead.
std::vector<DependencyRequestedFeature> features;
PlatformExpression::Expr platform;
DependencyConstraint constraint;
bool host = false;
bool default_features = true;
bool has_platform_expressions() const;
Json::Object extra_info;
/// @param id adds "default" if `default_features` is false.
FullPackageSpec to_full_spec(View<std::string> features, Triplet target, Triplet host) const;
friend bool operator==(const Dependency& lhs, const Dependency& rhs);
friend bool operator!=(const Dependency& lhs, const Dependency& rhs) { return !(lhs == rhs); }
};
struct DependencyOverride
{
std::string name;
Version version;
VersionScheme scheme;
Json::Object extra_info;
friend bool operator==(const DependencyOverride& lhs, const DependencyOverride& rhs);
friend bool operator!=(const DependencyOverride& lhs, const DependencyOverride& rhs) { return !(lhs == rhs); }
};
std::vector<FullPackageSpec> filter_dependencies(const std::vector<Dependency>& deps,
Triplet t,
Triplet host,
const std::unordered_map<std::string, std::string>& cmake_vars);
/// <summary>
/// Port metadata of additional feature in a package (part of CONTROL file)
/// </summary>
struct FeatureParagraph
{
std::string name;
std::vector<std::string> description;
std::vector<Dependency> dependencies;
PlatformExpression::Expr supports_expression;
// there are two distinct "empty" states here
// "user did not provide a license" -> nullopt
// "user provided license = null" -> {""}
Optional<std::string> license; // SPDX license expression
Json::Object extra_info;
friend bool operator==(const FeatureParagraph& lhs, const FeatureParagraph& rhs);
friend bool operator!=(const FeatureParagraph& lhs, const FeatureParagraph& rhs) { return !(lhs == rhs); }
};
/// <summary>
/// Port metadata of the core feature of a package (part of CONTROL file)
/// </summary>
struct SourceParagraph
{
std::string name;
VersionScheme version_scheme = VersionScheme::String;
std::string raw_version;
int port_version = 0;
std::vector<std::string> description;
std::vector<std::string> summary;
std::vector<std::string> maintainers;
std::string homepage;
std::string documentation;
std::vector<Dependency> dependencies;
std::vector<DependencyOverride> overrides;
std::vector<DependencyRequestedFeature> default_features;
// there are two distinct "empty" states here
// "user did not provide a license" -> nullopt
// "user provided license = null" -> {""}
Optional<std::string> license; // SPDX license expression
Optional<std::string> builtin_baseline;
Optional<Json::Object> vcpkg_configuration;
// Currently contacts is only a Json::Object but it will eventually be unified with maintainers
Json::Object contacts;
PlatformExpression::Expr supports_expression;
Json::Object extra_info;
Version to_version() const { return Version{raw_version, port_version}; }
friend bool operator==(const SourceParagraph& lhs, const SourceParagraph& rhs);
friend bool operator!=(const SourceParagraph& lhs, const SourceParagraph& rhs) { return !(lhs == rhs); }
};
/// <summary>
/// Full metadata of a package: core and other features.
/// </summary>
struct SourceControlFile
{
SourceControlFile clone() const;
static ParseExpected<SourceControlFile> parse_project_manifest_object(StringView origin,
const Json::Object& object,
MessageSink& warnings_sink);
static ParseExpected<SourceControlFile> parse_port_manifest_object(StringView origin,
const Json::Object& object,
MessageSink& warnings_sink);
static ParseExpected<SourceControlFile> parse_control_file(StringView origin,
std::vector<Paragraph>&& control_paragraphs);
// Always non-null in non-error cases
std::unique_ptr<SourceParagraph> core_paragraph;
std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs;
Json::Object extra_features_info;
Optional<const FeatureParagraph&> find_feature(StringView featurename) const;
Optional<const std::vector<Dependency>&> find_dependencies_for_feature(const std::string& featurename) const;
bool has_qualified_dependencies() const;
ExpectedL<Unit> check_against_feature_flags(const Path& origin,
const FeatureFlagSettings& flags,
bool is_default_builtin_registry = true) const;
Version to_version() const { return core_paragraph->to_version(); }
SchemedVersion to_schemed_version() const
{
return SchemedVersion{core_paragraph->version_scheme, core_paragraph->to_version()};
}
VersionSpec to_version_spec() const { return {core_paragraph->name, core_paragraph->to_version()}; }
friend bool operator==(const SourceControlFile& lhs, const SourceControlFile& rhs);
friend bool operator!=(const SourceControlFile& lhs, const SourceControlFile& rhs) { return !(lhs == rhs); }
};
Json::Object serialize_manifest(const SourceControlFile& scf);
ExpectedL<ManifestConfiguration> parse_manifest_configuration(const Json::Object& manifest,
StringView origin,
MessageSink& warningsSink);
/// <summary>
/// Named pair of a SourceControlFile and the location of this file
/// </summary>
struct SourceControlFileAndLocation
{
Version to_version() const { return source_control_file->to_version(); }
VersionScheme scheme() const { return source_control_file->core_paragraph->version_scheme; }
SchemedVersion schemed_version() const { return {scheme(), to_version()}; }
std::unique_ptr<SourceControlFile> source_control_file;
Path source_location;
/// Should model SPDX PackageDownloadLocation. Empty implies NOASSERTION.
/// See https://spdx.github.io/spdx-spec/package-information/#77-package-download-location-field
std::string registry_location;
};
void print_error_message(const LocalizedString& message);
void print_error_message(const std::unique_ptr<ParseControlErrorInfo>& error_info_list);
std::string parse_spdx_license_expression(StringView sv, ParseMessages& messages);
// Exposed for testing
ExpectedL<std::vector<Dependency>> parse_dependencies_list(const std::string& str,
StringView origin = "<unknown>",
TextRowCol textrowcol = {});
}