aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorras0219 <533828+ras0219@users.noreply.github.com>2020-12-04 12:57:13 -0800
committerGitHub <noreply@github.com>2020-12-04 12:57:13 -0800
commit60aa143e59687ed4b689d24d80a6f93ae123da86 (patch)
treeda874cbe00f8c14a47a71801df9045381aed7a96 /toolsrc/include
parent99cfc38036f330a035b57aa67f661526153e31c7 (diff)
downloadvcpkg-60aa143e59687ed4b689d24d80a6f93ae123da86.tar.gz
vcpkg-60aa143e59687ed4b689d24d80a6f93ae123da86.zip
[vcpkg] Error on '#' in version strings to avoid confusion (#14927)
* [vcpkg] Refactor deserializers to reduce duplicate functionality * [vcpkg] Error on '#' in version strings to avoid confusion with port-version * [vcpkg] Improve error message * [vcpkg] Reorder field output * [vcpkg] Fix tests Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/jsonreader.h3
-rw-r--r--toolsrc/include/vcpkg/base/util.h10
-rw-r--r--toolsrc/include/vcpkg/versiondeserializers.h31
-rw-r--r--toolsrc/include/vcpkg/versiont.h2
4 files changed, 35 insertions, 11 deletions
diff --git a/toolsrc/include/vcpkg/base/jsonreader.h b/toolsrc/include/vcpkg/base/jsonreader.h
index 02c1936e2..bea60e7ce 100644
--- a/toolsrc/include/vcpkg/base/jsonreader.h
+++ b/toolsrc/include/vcpkg/base/jsonreader.h
@@ -33,13 +33,14 @@ namespace vcpkg::Json
virtual Optional<Type> visit_object(Reader&, const Object&);
virtual View<StringView> valid_fields() const;
+ virtual ~IDeserializer() = default;
+
protected:
IDeserializer() = default;
IDeserializer(const IDeserializer&) = default;
IDeserializer& operator=(const IDeserializer&) = default;
IDeserializer(IDeserializer&&) = default;
IDeserializer& operator=(IDeserializer&&) = default;
- virtual ~IDeserializer() = default;
};
struct Reader
diff --git a/toolsrc/include/vcpkg/base/util.h b/toolsrc/include/vcpkg/base/util.h
index ca5104c23..b5ad1d04f 100644
--- a/toolsrc/include/vcpkg/base/util.h
+++ b/toolsrc/include/vcpkg/base/util.h
@@ -1,6 +1,7 @@
#pragma once
#include <vcpkg/base/optional.h>
+#include <vcpkg/base/view.h>
#include <algorithm>
#include <functional>
@@ -28,6 +29,15 @@ namespace vcpkg::Util
{
return std::find(container.begin(), container.end(), item) != container.end();
}
+ template<class T>
+ std::vector<T> concat(View<T> r1, View<T> r2)
+ {
+ std::vector<T> v;
+ v.reserve(r1.size() + r2.size());
+ v.insert(v.end(), r1.begin(), r1.end());
+ v.insert(v.end(), r2.begin(), r2.end());
+ return v;
+ }
}
namespace Sets
diff --git a/toolsrc/include/vcpkg/versiondeserializers.h b/toolsrc/include/vcpkg/versiondeserializers.h
index f5ffda101..249d685cb 100644
--- a/toolsrc/include/vcpkg/versiondeserializers.h
+++ b/toolsrc/include/vcpkg/versiondeserializers.h
@@ -13,19 +13,32 @@ namespace vcpkg
struct VersionDbEntry
{
VersionT version;
- Versions::Scheme scheme;
+ Versions::Scheme scheme = Versions::Scheme::String;
std::string git_tree;
-
- VersionDbEntry(const std::string& version_string,
- int port_version,
- Versions::Scheme scheme,
- const std::string& git_tree)
- : version(VersionT(version_string, port_version)), scheme(scheme), git_tree(git_tree)
- {
- }
};
Json::IDeserializer<VersionT>& get_versiont_deserializer_instance();
+ std::unique_ptr<Json::IDeserializer<std::string>> make_version_deserializer(StringLiteral type_name);
+
+ struct SchemedVersion
+ {
+ Versions::Scheme scheme = Versions::Scheme::String;
+ VersionT versiont;
+ };
+
+ Optional<SchemedVersion> visit_optional_schemed_deserializer(StringView parent_type,
+ Json::Reader& r,
+ const Json::Object& obj);
+ SchemedVersion visit_required_schemed_deserializer(StringView parent_type,
+ Json::Reader& r,
+ const Json::Object& obj);
+ View<StringView> schemed_deserializer_fields();
+
+ void serialize_schemed_version(Json::Object& out_obj,
+ Versions::Scheme scheme,
+ const std::string& version,
+ int port_version,
+ bool always_emit_port_version = false);
ExpectedS<std::map<std::string, VersionT, std::less<>>> parse_baseline_file(Files::Filesystem& fs,
StringView baseline_name,
diff --git a/toolsrc/include/vcpkg/versiont.h b/toolsrc/include/vcpkg/versiont.h
index 7819f9875..910183b9d 100644
--- a/toolsrc/include/vcpkg/versiont.h
+++ b/toolsrc/include/vcpkg/versiont.h
@@ -23,7 +23,7 @@ namespace vcpkg
private:
std::string m_text;
- int m_port_version;
+ int m_port_version = 0;
};
struct VersionDiff