Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2c310bb
[vcpkg] Add script to generate ports versions history
vicroms Sep 28, 2020
5e40036
[vcpkg] Fix formatting
vicroms Sep 28, 2020
59926f1
Fetch port versions from commit ID
vicroms Sep 28, 2020
394dccf
Use global --x-json switch
vicroms Sep 28, 2020
9fabe51
Use --no-checkout when cloning secondary instance
vicroms Sep 28, 2020
baa05ef
Clone from local repository instead of from GitHub
vicroms Sep 28, 2020
037471c
Use CmdLineBuilder to build git commands
vicroms Sep 29, 2020
9a7f298
Use CmdLineBuilder and reduce repeated code
vicroms Sep 30, 2020
c0117eb
Merge branch 'master' of github.com:microsoft/vcpkg into versioning/g…
vicroms Oct 1, 2020
b07099c
Fetch version at baseline and code cleanup
vicroms Oct 6, 2020
87fc6af
Guess version scheme from old CONTROL files
vicroms Oct 7, 2020
5ed80e0
Rename version db generator script
vicroms Oct 11, 2020
61043f5
Merge branch 'master' of github.com:microsoft/vcpkg into versioning/g…
vicroms Oct 11, 2020
2fe2a61
Simplify x-history json output
vicroms Oct 11, 2020
b98c92a
Merge branch 'master' of github.com:microsoft/vcpkg into versioning/g…
vicroms Oct 19, 2020
5c02c5b
Use CONTROL/manifest parsers on x-history
vicroms Oct 19, 2020
ee191eb
Use git-tree instaed of commit-id
vicroms Oct 20, 2020
7248364
Remove 'ports' field from root object
vicroms Oct 20, 2020
8b5245e
Clean up code
vicroms Oct 20, 2020
8c56121
More code cleanup
vicroms Oct 20, 2020
bca840d
Merge branch 'master' of github.com:microsoft/vcpkg into versioning/g…
vicroms Oct 20, 2020
91cb16b
Improve port version detection
vicroms Oct 21, 2020
42105e1
Improve generator logging
vicroms Oct 21, 2020
52559f4
Merge branch 'master' of https://github.com/microsoft/vcpkg into HEAD
ras0219-msft Oct 21, 2020
8ca07da
Do not ignore parsing errors in CONTROL files
vicroms Oct 22, 2020
e400b5a
Merge branch 'master' of github.com:microsoft/vcpkg into versioning/g…
vicroms Oct 22, 2020
08c5685
PR review comments in Python script
vicroms Oct 22, 2020
38504e7
Fix subprocess.run() calls
vicroms Oct 22, 2020
d27f294
Make `canonicalize()` return error instead of terminating
vicroms Oct 22, 2020
d664855
[vcpkg] Add tests for new test_parse_control_file paths
ras0219-msft Oct 22, 2020
0d077e3
Remove unnecessary std::move() calls
vicroms Oct 22, 2020
8a9115c
Merge branch 'dev/roschuma/cr' of https://github.com/ras0219/vcpkg in…
vicroms Oct 22, 2020
c312541
Fix formatting
vicroms Oct 23, 2020
0c7079e
Python formatting
vicroms Oct 26, 2020
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
71 changes: 71 additions & 0 deletions scripts/generatePortVersionsDb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os
import os.path
import sys
import subprocess
import json
import time

from subprocess import CalledProcessError
from json.decoder import JSONDecodeError
from pathlib import Path


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


def get_current_git_ref():
output = subprocess.run(['git.exe', '-C', SCRIPT_DIRECTORY, 'rev-parse', '--verify', 'HEAD'],
capture_output=True,
encoding='utf-8')
if output.returncode == 0:
return output.stdout.strip()
print(f"Failed to get git ref:", output.stderr.strip(), file=sys.stderr)
return None


def generate_port_versions_db(ports_path, db_path, revision):
start_time = time.time()
port_names = [item for item in os.listdir(ports_path) if os.path.isdir(os.path.join(ports_path, item))]
total_count = len(port_names)
for counter, port_name in enumerate(port_names):
containing_dir = os.path.join(db_path, f'{port_name[0]}-')
os.makedirs(containing_dir, exist_ok=True)
output_filepath = os.path.join(containing_dir, f'{port_name}.json')
if not os.path.exists(output_filepath):
output = subprocess.run(
[os.path.join(SCRIPT_DIRECTORY, '../vcpkg'), 'x-history', port_name, '--x-json'],
capture_output=True, encoding='utf-8')
if output.returncode == 0:
try:
versions_object = json.loads(output.stdout)
with open(output_filepath, 'w') as output_file:
json.dump(versions_object, output_file)
except JSONDecodeError:
print(f'Maformed JSON from vcpkg x-history {port_name}: ', output.stdout.strip(), file=sys.stderr)
else:
print(f'x-history {port_name} failed: ', output.stdout.strip(), file=sys.stderr)
# This should be replaced by a progress bar
if counter > 0 and counter % 100 == 0:
elapsed_time = time.time() - start_time
print(f'Processed {counter} out of {total_count}. Elapsed time: {elapsed_time:.2f} seconds')
rev_file = os.path.join(db_path, revision)
Path(rev_file).touch()
elapsed_time = time.time() - start_time
print(f'Processed {total_count} total ports. Elapsed time: {elapsed_time:.2f} seconds')


def main(ports_path, db_path):
revision = get_current_git_ref()
if not revision:
print('Couldn\'t fetch current Git revision', file=sys.stderr)
sys.exit(1)
rev_file = os.path.join(db_path, revision)
if os.path.exists(rev_file):
print(f'Database files already exist for commit {revision}')
sys.exit(0)
generate_port_versions_db(ports_path=ports_path, db_path=db_path, revision=revision)


if __name__ == "__main__":
main(ports_path=os.path.join(SCRIPT_DIRECTORY, '../ports'),
db_path=os.path.join(SCRIPT_DIRECTORY, '../port_versions'))
6 changes: 6 additions & 0 deletions toolsrc/include/vcpkg/paragraphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ namespace vcpkg::Paragraphs

ExpectedS<Paragraph> parse_single_paragraph(const std::string& str, const std::string& origin);
ExpectedS<Paragraph> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path);

ExpectedS<std::vector<Paragraph>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path);
ExpectedS<std::vector<Paragraph>> get_paragraphs_text(const std::string& text, const std::string& origin);

ExpectedS<std::vector<Paragraph>> parse_paragraphs(const std::string& str, const std::string& origin);

bool is_port_directory(const Files::Filesystem& fs, const fs::path& path);

Parse::ParseExpected<SourceControlFile> try_load_port(const Files::Filesystem& fs, const fs::path& path);
Parse::ParseExpected<SourceControlFile> try_load_port_text(const std::string& text,
const std::string& origin,
bool is_manifest);

ExpectedS<BinaryControlFile> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec);

Expand Down
5 changes: 4 additions & 1 deletion toolsrc/include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ namespace vcpkg
return ret;
}

static Parse::ParseExpected<SourceControlFile> parse_manifest_object(const std::string& origin,
const Json::Object& object);

static Parse::ParseExpected<SourceControlFile> parse_manifest_file(const fs::path& path_to_manifest,
const Json::Object& object);

static Parse::ParseExpected<SourceControlFile> parse_control_file(
const fs::path& path_to_control, std::vector<Parse::Paragraph>&& control_paragraphs);
const std::string& origin, std::vector<Parse::Paragraph>&& control_paragraphs);

// Always non-null in non-error cases
std::unique_ptr<SourceParagraph> core_paragraph;
Expand Down
6 changes: 2 additions & 4 deletions toolsrc/include/vcpkg/versions.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once

#include <vcpkg/fwd/vcpkgpaths.h>

namespace vcpkg::Versions
{
enum class Scheme
{
String,
Relaxed,
Semver,
Date
Date,
String
};
}
6 changes: 3 additions & 3 deletions toolsrc/src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Build-Depends: bzip
)",
"<testdata>");
REQUIRE(pghs.has_value());
auto maybe_scf = SourceControlFile::parse_control_file(fs::path(), std::move(*pghs.get()));
auto maybe_scf = SourceControlFile::parse_control_file(fs::u8string(fs::path()), std::move(*pghs.get()));
REQUIRE(maybe_scf.has_value());
SourceControlFileLocation scfl{std::move(*maybe_scf.get()), fs::path()};

Expand Down Expand Up @@ -255,7 +255,7 @@ Description: a spiffy compression library wrapper
)",
"<testdata>");
REQUIRE(pghs.has_value());
auto maybe_scf = SourceControlFile::parse_control_file(fs::path(), std::move(*pghs.get()));
auto maybe_scf = SourceControlFile::parse_control_file(fs::u8string(fs::path()), std::move(*pghs.get()));
REQUIRE(maybe_scf.has_value());
SourceControlFileLocation scfl{std::move(*maybe_scf.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
Expand All @@ -278,7 +278,7 @@ Description: a spiffy compression library wrapper
)",
"<testdata>");
REQUIRE(pghs2.has_value());
auto maybe_scf2 = SourceControlFile::parse_control_file(fs::path(), std::move(*pghs2.get()));
auto maybe_scf2 = SourceControlFile::parse_control_file(fs::u8string(fs::path()), std::move(*pghs2.get()));
REQUIRE(maybe_scf2.has_value());
SourceControlFileLocation scfl2{std::move(*maybe_scf2.get()), fs::path()};
plan.install_actions.push_back(Dependencies::InstallPlanAction());
Expand Down
6 changes: 3 additions & 3 deletions toolsrc/src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ TEST_CASE ("Serialize all the ports", "[manifests]")
auto pghs = Paragraphs::parse_paragraphs(contents, fs::u8string(control));
REQUIRE(pghs);

scfs.push_back(std::move(
*SourceControlFile::parse_control_file(control, std::move(pghs).value_or_exit(VCPKG_LINE_INFO))
.value_or_exit(VCPKG_LINE_INFO)));
scfs.push_back(std::move(*SourceControlFile::parse_control_file(
fs::u8string(control), std::move(pghs).value_or_exit(VCPKG_LINE_INFO))
.value_or_exit(VCPKG_LINE_INFO)));
}
else if (fs.exists(manifest))
{
Expand Down
50 changes: 50 additions & 0 deletions toolsrc/src/vcpkg-test/paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ TEST_CASE ("SourceParagraph construct minimum", "[paragraph]")
REQUIRE(pgh.core_paragraph->dependencies.size() == 0);
}

TEST_CASE ("SourceParagraph construct invalid", "[paragraph]")
{
auto m_pgh = test_parse_control_file({{
{"Source", "zlib"},
{"Version", "1.2.8"},
{"Build-Depends", "1.2.8"},
}});

REQUIRE(!m_pgh.has_value());

m_pgh = test_parse_control_file({{
{"Source", "zlib"},
{"Version", "1.2.8"},
{"Default-Features", "1.2.8"},
}});

REQUIRE(!m_pgh.has_value());

m_pgh = test_parse_control_file({
{
{"Source", "zlib"},
{"Version", "1.2.8"},
},
{
{"Feature", "a"},
{"Build-Depends", "1.2.8"},
},
});

REQUIRE(!m_pgh.has_value());
}

TEST_CASE ("SourceParagraph construct maximum", "[paragraph]")
{
auto m_pgh = test_parse_control_file({{
Expand All @@ -76,6 +108,24 @@ TEST_CASE ("SourceParagraph construct maximum", "[paragraph]")
REQUIRE(pgh.core_paragraph->default_features[0] == "df");
}

TEST_CASE ("SourceParagraph construct feature", "[paragraph]")
{
auto m_pgh = test_parse_control_file({
{
{"Source", "s"},
{"Version", "v"},
},
{{"Feature", "f"}, {"Description", "d2"}, {"Build-Depends", "bd2"}},
});
REQUIRE(m_pgh.has_value());
auto& pgh = **m_pgh.get();

REQUIRE(pgh.feature_paragraphs.size() == 1);
REQUIRE(pgh.feature_paragraphs[0]->name == "f");
REQUIRE(pgh.feature_paragraphs[0]->description == std::vector<std::string>{"d2"});
REQUIRE(pgh.feature_paragraphs[0]->dependencies.size() == 1);
}

TEST_CASE ("SourceParagraph two dependencies", "[paragraph]")
{
auto m_pgh = test_parse_control_file({{
Expand Down
4 changes: 2 additions & 2 deletions toolsrc/src/vcpkg/commands.format-manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ namespace
paragraphs.error());
return {};
}
auto scf_res =
SourceControlFile::parse_control_file(control_path, std::move(paragraphs).value_or_exit(VCPKG_LINE_INFO));
auto scf_res = SourceControlFile::parse_control_file(fs::u8string(control_path),
std::move(paragraphs).value_or_exit(VCPKG_LINE_INFO));
if (!scf_res)
{
System::printf(System::Color::error, "Failed to parse control file: %s\n", control_path_string);
Expand Down
Loading