Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Version instead of {raw_version,port_version} in more places. #1253

Merged
merged 9 commits into from
Nov 7, 2023
3 changes: 2 additions & 1 deletion include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <vcpkg/archives.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/versions.h>

#include <chrono>
#include <iterator>
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace vcpkg
explicit BinaryPackageReadInfo(const InstallPlanAction& action);
std::string package_abi;
PackageSpec spec;
std::string raw_version;
Version version;
Path package_dir;
};

Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/binarycaching.private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace vcpkg
// - v?<X>.<Y><whatever> -> <X>.<Y>.0-vcpkg<abitag>
// - v?<X>.<Y>.<Z><whatever> -> <X>.<Y>.<Z>-vcpkg<abitag>
// - anything else -> 0.0.0-vcpkg<abitag>
std::string format_version_for_nugetref(StringView version, StringView abi_tag);
std::string format_version_for_nugetref(StringView version_text, StringView abi_tag);

struct NugetReference
{
Expand Down
5 changes: 1 addition & 4 deletions include/vcpkg/binaryparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ namespace vcpkg

bool is_feature() const { return !feature.empty(); }

Version get_version() const { return {version, port_version}; }

PackageSpec spec;
std::string version;
int port_version = 0;
Version version;
std::vector<std::string> description;
std::vector<std::string> maintainers;
std::string feature;
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/commands.build.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace vcpkg
LinkageType crt_linkage = LinkageType::DYNAMIC;
LinkageType library_linkage = LinkageType::DYNAMIC;

Optional<std::string> detected_head_version;
Optional<Version> detected_head_version;

BuildPolicies policies;
};
Expand Down
37 changes: 37 additions & 0 deletions include/vcpkg/fwd/versions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

namespace vcpkg
{
struct Version;
struct VersionDiff;
struct VersionMapLess;
struct SchemedVersion;
struct VersionSpec;
struct VersionSpecHasher;
struct DotVersion;
struct DateVersion;
struct ParsedExternalVersion;

enum class VerComp
{
unk = -2,
lt = -1, // these values are chosen to align with traditional -1/0/1 for less/equal/greater
eq = 0,
gt = 1,
};

enum class VersionScheme
{
Missing,
Relaxed,
Semver,
Date,
String
};

enum class VersionConstraintKind
{
None,
Minimum
};
}
16 changes: 6 additions & 10 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace vcpkg
struct DependencyConstraint
{
VersionConstraintKind type = VersionConstraintKind::None;
std::string value;
int port_version = 0;
Version version;

friend bool operator==(const DependencyConstraint& lhs, const DependencyConstraint& rhs);
friend bool operator!=(const DependencyConstraint& lhs, const DependencyConstraint& rhs)
Expand Down Expand Up @@ -111,8 +110,7 @@ namespace vcpkg
{
std::string name;
VersionScheme version_scheme = VersionScheme::String;
std::string raw_version;
int port_version = 0;
Version version;
std::vector<std::string> description;
std::vector<std::string> summary;
std::vector<std::string> maintainers;
Expand All @@ -136,8 +134,6 @@ namespace vcpkg

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); }
};
Expand Down Expand Up @@ -172,12 +168,12 @@ namespace vcpkg
const FeatureFlagSettings& flags,
bool is_default_builtin_registry = true) const;

Version to_version() const { return core_paragraph->to_version(); }
const Version& to_version() const { return core_paragraph->version; }
SchemedVersion to_schemed_version() const
{
return SchemedVersion{core_paragraph->version_scheme, core_paragraph->to_version()};
return SchemedVersion{core_paragraph->version_scheme, core_paragraph->version};
}
VersionSpec to_version_spec() const { return {core_paragraph->name, core_paragraph->to_version()}; }
VersionSpec to_version_spec() const { return {core_paragraph->name, core_paragraph->version}; }

friend bool operator==(const SourceControlFile& lhs, const SourceControlFile& rhs);
friend bool operator!=(const SourceControlFile& lhs, const SourceControlFile& rhs) { return !(lhs == rhs); }
Expand All @@ -194,7 +190,7 @@ namespace vcpkg
/// </summary>
struct SourceControlFileAndLocation
{
Version to_version() const { return source_control_file->to_version(); }
const 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()}; }

Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/statusparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace vcpkg
std::vector<PackageSpec> dependencies() const;
std::map<std::string, std::vector<FeatureSpec>> feature_dependencies() const;
InternalFeatureSet feature_list() const;
Version version() const;
const Version& version() const;

std::vector<StatusParagraph> all_status_paragraphs() const;

Expand Down
4 changes: 3 additions & 1 deletion include/vcpkg/versiondeserializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <vcpkg/base/fwd/stringview.h>

#include <vcpkg/fwd/versions.h>

#include <vcpkg/base/jsonreader.h>

#include <vcpkg/versions.h>
Expand All @@ -22,7 +24,7 @@ namespace vcpkg
bool allow_hash_portversion = false);
View<StringView> schemed_deserializer_fields();

void serialize_schemed_version(Json::Object& out_obj, VersionScheme scheme, StringView version, int port_version);
void serialize_schemed_version(Json::Object& out_obj, VersionScheme scheme, const Version& version);

struct VersionConstraintStringDeserializer : Json::StringDeserializer
{
Expand Down
47 changes: 16 additions & 31 deletions include/vcpkg/versions.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
#pragma once

#include <vcpkg/base/fwd/format.h>
#include <vcpkg/base/fwd/optional.h>
#include <vcpkg/base/fwd/stringview.h>

#include <vcpkg/fwd/versions.h>

#include <vcpkg/base/expected.h>
#include <vcpkg/base/optional.h>

namespace vcpkg
{
struct Version
{
Version() noexcept;
Version(std::string&& value, int port_version);
Version(const std::string& value, int port_version);
Version(std::string&& value, int port_version) noexcept;
Version(StringView value, int port_version);
template<int N>
Version(const char (&str)[N], int port_version) : Version(StringLiteral{str}, port_version)
{
}

std::string to_string() const;
void to_string(std::string& out) const;

// Attempts to parse `content` as a version or empty [^#]+#\d+
// If the port-version can't be parsed as a nonnegative integer, returns nullopt.
static Optional<Version> parse(StringView content);

friend bool operator==(const Version& left, const Version& right);
friend bool operator!=(const Version& left, const Version& right);

// Version has no operator< because without a scheme it is not necessarily semantically comparable;
// VersionMapLess is provided as a less than comparison for use in std::map.
friend struct VersionMapLess;

const std::string& text() const { return m_text; }
int port_version() const { return m_port_version; }

private:
std::string m_text;
int m_port_version = 0;
std::string text;
int port_version = 0;
};

struct VersionDiff
Expand All @@ -47,26 +55,9 @@ namespace vcpkg
bool operator()(const Version& left, const Version& right) const;
};

enum class VerComp
{
unk = -2,
lt = -1, // these values are chosen to align with traditional -1/0/1 for less/equal/greater
eq = 0,
gt = 1,
};

// converts a strcmp <0/0/>0 style integer into a VerComp
VerComp int_to_vercomp(int comparison_result);

enum class VersionScheme
{
Missing,
Relaxed,
Semver,
Date,
String
};

struct SchemedVersion
{
VersionScheme scheme;
Expand Down Expand Up @@ -149,12 +140,6 @@ namespace vcpkg
VerComp compare_versions(const SchemedVersion& a, const SchemedVersion& b);
VerComp compare_versions(VersionScheme sa, const Version& a, VersionScheme sb, const Version& b);

enum class VersionConstraintKind
{
None,
Minimum
};

// this is for version parsing that isn't in vcpkg ports
// stuff like tools, nuget, etc.
struct ParsedExternalVersion
Expand Down
Loading