[vcpkg] fix checking out git registry ports (#16009)

* [vcpkg] fix checking out git registry ports

* fix the new issues in builtinregistryentry

* fix tests

* fix tests boogaloo

* [vcpkg] Fix issue where baseline is requested for overlay during version resolution

* split BuiltinRegistryEntry into two types

Co-authored-by: Robert Schumacher <ras0219@outlook.com>
This commit is contained in:
nicole mazzuca 2021-02-03 10:03:44 -08:00 committed by GitHub
parent a84190e1de
commit dc4d1b735a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 24 deletions

View File

@ -68,8 +68,8 @@ try
$CurrentTest = 'git init .'
git @gitConfigOptions init .
Throw-IfFailed
Copy-Item -Recurse -LiteralPath "$PSScriptRoot/../../e2e_ports/versions" -Destination .
Copy-Item -Recurse -LiteralPath "$PSScriptRoot/../../e2e_ports/vcpkg-internal-e2e-test-port" -Destination .
New-Item -Path './vcpkg-internal-e2e-test-port/foobar' -Value 'this is just to get a distinct git tree'
$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
@ -77,6 +77,36 @@ try
$CurrentTest = 'git commit'
git @gitConfigOptions commit -m 'initial commit'
Throw-IfFailed
$vcpkgInternalE2eTestPortGitTree = git rev-parse 'HEAD:vcpkg-internal-e2e-test-port'
$vcpkgInternalE2eTestPortVersionsJson = @{
"versions" = @(
@{
"version-string" = "1.0.0";
"git-tree" = $vcpkgInternalE2eTestPortGitTree
}
)
}
$vcpkgBaseline = @{
"default" = @{
"vcpkg-internal-e2e-test-port" = @{
"baseline" = "1.0.0"
}
}
}
New-Item -Path './versions' -ItemType Directory
New-Item -Path './versions/v-' -ItemType Directory
New-Item -Path './versions/baseline.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgBaseline)
New-Item -Path './versions/v-/vcpkg-internal-e2e-test-port.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgInternalE2eTestPortVersionsJson)
$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
Throw-IfFailed
$CurrentTest = 'git commit'
git @gitConfigOptions commit --amend --no-edit
Throw-IfFailed
}
finally
{

View File

@ -344,6 +344,9 @@ namespace vcpkg::Build
"for more information.\n");
Checks::exit_maybe_upgrade(VCPKG_LINE_INFO);
#else
(void)target_architecture;
(void)toolset;
(void)all_toolsets;
Checks::exit_with_message(VCPKG_LINE_INFO,
"Error: vcvars-based toolchains are only usable on Windows platforms.");
#endif

View File

@ -1256,6 +1256,8 @@ namespace vcpkg::Dependencies
VersionSchemeInfo& vsi,
const std::string& feature);
Optional<Versions::Version> dep_to_version(const std::string& name, const DependencyConstraint& dc);
std::vector<std::string> m_errors;
};
@ -1452,17 +1454,31 @@ namespace vcpkg::Dependencies
const Dependency& dep,
const std::string& origin)
{
auto base_ver = m_base_provider.get_baseline_version(dep.name);
auto dep_ver = to_version(dep.constraint);
if (auto dv = dep_ver.get())
auto maybe_overlay = m_o_provider.get_control_file(ref.first.name());
auto over_it = m_overrides.find(ref.first.name());
if (auto p_overlay = maybe_overlay.get())
{
add_constraint(ref, *dv, origin);
auto overlay_version = to_version(*p_overlay->source_control_file);
add_constraint(ref, overlay_version, origin);
}
if (auto bv = base_ver.get())
else if (over_it != m_overrides.end())
{
add_constraint(ref, *bv, origin);
add_constraint(ref, over_it->second, origin);
}
else
{
auto base_ver = m_base_provider.get_baseline_version(dep.name);
auto dep_ver = to_version(dep.constraint);
if (auto dv = dep_ver.get())
{
add_constraint(ref, *dv, origin);
}
if (auto bv = base_ver.get())
{
add_constraint(ref, *bv, origin);
}
}
for (auto&& f : dep.features)
@ -1569,10 +1585,21 @@ namespace vcpkg::Dependencies
return *m_graph.emplace(spec, PackageNode{}).first;
}
static Optional<Versions::Version> dep_to_version(const std::string& name,
const DependencyConstraint& dc,
const PortFileProvider::IBaselineProvider& base_provider)
Optional<Versions::Version> VersionedPackageGraph::dep_to_version(const std::string& name,
const DependencyConstraint& dc)
{
auto maybe_overlay = m_o_provider.get_control_file(name);
if (auto p_overlay = maybe_overlay.get())
{
return to_version(*p_overlay->source_control_file);
}
auto over_it = m_overrides.find(name);
if (over_it != m_overrides.end())
{
return over_it->second;
}
auto maybe_cons = to_version(dc);
if (maybe_cons)
{
@ -1580,7 +1607,7 @@ namespace vcpkg::Dependencies
}
else
{
return base_provider.get_baseline_version(name);
return m_base_provider.get_baseline_version(name);
}
}
@ -1779,7 +1806,7 @@ namespace vcpkg::Dependencies
{
continue;
}
auto maybe_cons = dep_to_version(dep.name, dep.constraint, m_base_provider);
auto maybe_cons = dep_to_version(dep.name, dep.constraint);
if (auto cons = maybe_cons.get())
{

View File

@ -99,7 +99,7 @@ namespace
DelayedInit<Baseline> m_baseline;
};
struct BuiltinRegistryEntry final : RegistryEntry
struct BuiltinPortTreeRegistryEntry final : RegistryEntry
{
View<VersionT> get_port_versions() const override { return {&version, 1}; }
ExpectedS<fs::path> get_path_to_version(const VcpkgPaths&, const VersionT& v) const override
@ -108,6 +108,7 @@ namespace
{
return path;
}
return {Strings::format("Error: no version entry for %s at version %s.\n"
"We are currently using the version in the ports tree (%s).",
name,
@ -121,6 +122,19 @@ namespace
VersionT version;
};
struct BuiltinGitRegistryEntry final : RegistryEntry
{
View<VersionT> get_port_versions() const override { return port_versions; }
ExpectedS<fs::path> get_path_to_version(const VcpkgPaths&, const VersionT& version) const override;
std::string port_name;
// these two map port versions to git trees
// these shall have the same size, and git_trees[i] shall be the git tree for port_versions[i]
std::vector<VersionT> port_versions;
std::vector<std::string> git_trees;
};
struct FilesystemRegistryEntry final : RegistryEntry
{
explicit FilesystemRegistryEntry(std::string&& port_name) : port_name(port_name) { }
@ -248,14 +262,14 @@ namespace
VCPKG_LINE_INFO, maybe_version_entries.has_value(), "Error: " + maybe_version_entries.error());
auto version_entries = std::move(maybe_version_entries).value_or_exit(VCPKG_LINE_INFO);
auto gre = std::make_unique<GitRegistryEntry>();
gre->port_name = port_name.to_string();
auto res = std::make_unique<BuiltinGitRegistryEntry>();
res->port_name = port_name.to_string();
for (auto&& version_entry : version_entries)
{
gre->port_versions.push_back(version_entry.version);
gre->git_trees.push_back(version_entry.git_tree);
res->port_versions.push_back(version_entry.version);
res->git_trees.push_back(version_entry.git_tree);
}
return gre;
return res;
}
}
@ -275,10 +289,10 @@ namespace
if (scf->core_paragraph->name == port_name)
{
auto res = std::make_unique<BuiltinRegistryEntry>();
res->version = scf->core_paragraph->to_versiont();
res->path = std::move(port_directory);
auto res = std::make_unique<BuiltinPortTreeRegistryEntry>();
res->name = std::move(scf->core_paragraph->name);
res->path = std::move(port_directory);
res->version = scf->to_versiont();
return res;
}
Checks::exit_maybe_upgrade(VCPKG_LINE_INFO,
@ -583,6 +597,31 @@ namespace
// { RegistryEntry
// { BuiltinRegistryEntry::RegistryEntry
ExpectedS<fs::path> BuiltinGitRegistryEntry::get_path_to_version(const VcpkgPaths& paths,
const VersionT& version) const
{
auto it = std::find(port_versions.begin(), port_versions.end(), version);
if (it == port_versions.end())
{
return {Strings::concat("Error: No version entry for ",
port_name,
" at version ",
version,
". This may be fixed by updating vcpkg to the latest master via `git "
"pull`.\nAvailable versions:\n",
Strings::join("",
port_versions,
[](const VersionT& v) { return Strings::concat(" ", v, "\n"); }),
"\nSee `vcpkg help versioning` for more information."),
expected_right_tag};
}
const auto& git_tree = git_trees[it - port_versions.begin()];
return paths.git_checkout_port(port_name, git_tree, paths.root / fs::u8path(".git"));
}
// } BuiltinRegistryEntry::RegistryEntry
// { FilesystemRegistryEntry::RegistryEntry
ExpectedS<fs::path> FilesystemRegistryEntry::get_path_to_version(const VcpkgPaths&, const VersionT& version) const
{
@ -617,7 +656,7 @@ namespace
}
const auto& git_tree = git_trees[it - port_versions.begin()];
return paths.git_checkout_port(port_name, git_tree, paths.root / fs::u8path(".git"));
return paths.git_checkout_object_from_remote_registry(git_tree);
}
// } GitRegistryEntry::RegistryEntry