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

[vcpkg] Add SemVer and Date versioning schemes #14889

Merged
merged 16 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scripts/generateBaseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import json
import subprocess
import sys

SCRIPT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))


def generate_baseline(ports_path, output_filepath):
port_names = [item for item in os.listdir(
ports_path) if os.path.isdir(os.path.join(ports_path, item))]
port_names.sort()

total = len(port_names)
baseline_versions = {}
for counter, port_name in enumerate(port_names):
vcpkg_exe = os.path.join(SCRIPT_DIRECTORY, '../vcpkg')
print(f'[{counter + 1}/{total}] Getting package info for {port_name}')
output = subprocess.run(
[vcpkg_exe, 'x-package-info', '--x-json', port_name],
capture_output=True,
encoding='utf-8')

if output.returncode == 0:
package_info = json.loads(output.stdout)
port_info = package_info['results'][port_name]

version = {}
for scheme in ['version-string', 'version-semver', 'version-date', 'version']:
if scheme in port_info:
version[scheme] = package_info['results'][port_name][scheme]
break
version['port-version'] = 0
if 'port-version' in port_info:
version['port-version'] = port_info['port-version']
baseline_versions[port_name] = version
else:
print(f'x-package-info --x-json {port_name} failed: ', output.stdout.strip(), file=sys.stderr)

output = {}
output['default'] = baseline_versions

with open(output_filepath, 'r') as output_file:
json.dump(baseline_versions, output_file)
sys.exit(0)


if __name__ == '__main__':
generate_baseline(
ports_path=f'{SCRIPT_DIRECTORY}/../ports', output_filepath='baseline.json')
44 changes: 44 additions & 0 deletions toolsrc/include/vcpkg/versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ namespace vcpkg::Versions
{
using Version = VersionT;

enum class VerComp
{
unk,
lt,
eq,
gt,
};

enum class Scheme
{
Relaxed,
Expand All @@ -32,6 +40,42 @@ namespace vcpkg::Versions
std::size_t operator()(const VersionSpec& key) const;
};

struct RelaxedVersion
{
std::string original_string;
std::vector<uint64_t> version;

static ExpectedS<RelaxedVersion> from_string(const std::string& str);
};

struct SemanticVersion
{
std::string original_string;
std::string version_string;
std::string prerelease_string;

std::vector<uint64_t> version;
std::vector<std::string> identifiers;

static ExpectedS<SemanticVersion> from_string(const std::string& str);
};

struct DateVersion
{
std::string original_string;
std::string version_string;
std::string identifiers_string;

std::vector<uint64_t> identifiers;

static ExpectedS<DateVersion> from_string(const std::string& str);
};

VerComp compare(const std::string& a, const std::string& b, Scheme scheme);
VerComp compare(const RelaxedVersion& a, const RelaxedVersion& b);
VerComp compare(const SemanticVersion& a, const SemanticVersion& b);
VerComp compare(const DateVersion& a, const DateVersion& b);

struct Constraint
{
enum class Type
Expand Down
Loading