Skip to content

Commit

Permalink
Apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort committed Jul 2, 2021
1 parent d3d21c6 commit 2b0efc6
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 58 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines/end-to-end-tests-dir/create.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$Script:CurrentTest = "create zlib"
Write-Host $Script:CurrentTest
$RegistryRoot = Join-Path $TestingRoot 'registry_for_create'
& $GitExe init $RegistryRoot
& git init $RegistryRoot
Throw-IfFailed
Run-Vcpkg x-init-registry $RegistryRoot
Throw-IfFailed
Expand Down
12 changes: 6 additions & 6 deletions azure-pipelines/end-to-end-tests-dir/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ $versionFilesPath = "$PSScriptRoot/../e2e_ports/version-files"

# create custom registry for testing
$RegistryRootComplete = Join-Path $TestingRoot 'registry_for_versions_complete'
& $GitExe init $RegistryRootComplete
& git init $RegistryRootComplete
Throw-IfFailed
$RegistryRootIncomplete = Join-Path $TestingRoot 'registry_for_versions_incomplete'
& $GitExe init $RegistryRootIncomplete
& git init $RegistryRootIncomplete
Throw-IfFailed

# Test verify versions
Copy-Item -Recurse "$versionFilesPath/versions" "$RegistryRootComplete/versions"
Copy-Item -Recurse "$versionFilesPath/ports" "$RegistryRootComplete/ports"
& $GitExe -C "$RegistryRootComplete" add -A
& git -C "$RegistryRootComplete" add -A
Throw-IfFailed
& $GitExe -C "$RegistryRootComplete" -c user.name='vcpkg-tool' -c user.email='[email protected]' commit -m "add files"
& git -C "$RegistryRootComplete" -c user.name='vcpkg-tool' -c user.email='[email protected]' commit -m "add files"
Throw-IfFailed
Copy-Item -Recurse "$versionFilesPath/versions_incomplete" "$RegistryRootIncomplete/versions"
Copy-Item -Recurse "$versionFilesPath/ports_incomplete" "$RegistryRootIncomplete/ports"
& $GitExe -C "$RegistryRootIncomplete" add -A
& git -C "$RegistryRootIncomplete" add -A
Throw-IfFailed
& $GitExe -C "$RegistryRootIncomplete" -c user.name='vcpkg-tool' -c user.email='[email protected]' commit -m "add files"
& git -C "$RegistryRootIncomplete" -c user.name='vcpkg-tool' -c user.email='[email protected]' commit -m "add files"
Throw-IfFailed
$portsRedirectArgsOK = @(
"--feature-flags=versions",
Expand Down
8 changes: 0 additions & 8 deletions azure-pipelines/end-to-end-tests-prelude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ $commonArgs = @(
)
$Script:CurrentTest = 'unassigned'
$env:X_VCPKG_REGISTRIES_CACHE = Join-Path $TestingRoot 'registries'
if ($IsWindows)
{
$GitExe = 'git.exe'
}
else
{
$GitExe = 'git'
}

function Refresh-TestRoot {
Remove-Item -Recurse -Force $TestingRoot -ErrorAction SilentlyContinue
Expand Down
10 changes: 5 additions & 5 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ namespace vcpkg

// the directory of the builtin ports
// this should be used only for helper commands, not core commands like `install`.
path builtin_ports_directory() const { return this->root / u8path("ports"); }
path builtin_versions_directory() const { return this->root / u8path("versions"); }
path builtin_registry_ports_dir() const { return this->root / u8path("ports"); }
path builtin_registry_versions_dir() const { return this->root / u8path("versions"); }

path current_git_directory() const { return current_registry_root / u8path(".git"); }
path current_ports_directory() const { return current_registry_root / u8path("ports"); }
path current_versions_directory() const { return current_registry_root / u8path("versions"); }
path current_registry_dot_git_dir() const { return current_registry_root / u8path(".git"); }
path current_registry_ports_dir() const { return current_registry_root / u8path("ports"); }
path current_registry_versions_dir() const { return current_registry_root / u8path("versions"); }

private:
std::unique_ptr<details::VcpkgPathsImpl> m_pimpl;
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ TEST_CASE ("Serialize all the ports", "[manifests]")

std::vector<SourceControlFile> scfs;

for (auto dir : stdfs::directory_iterator(paths.builtin_ports_directory()))
for (auto dir : stdfs::directory_iterator(paths.builtin_registry_ports_dir()))
{
const auto control = dir / vcpkg::u8path("CONTROL");
const auto manifest = dir / vcpkg::u8path("vcpkg.json");
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ namespace vcpkg::Build
}

auto u8portdir = vcpkg::u8string(scfl.source_location);
if (!Strings::case_insensitive_ascii_starts_with(u8portdir, vcpkg::u8string(paths.builtin_ports_directory())))
if (!Strings::case_insensitive_ascii_starts_with(u8portdir, vcpkg::u8string(paths.builtin_registry_ports_dir())))
{
vcpkg::printf("-- Installing port from location: %s\n", u8portdir);
}
Expand Down
14 changes: 7 additions & 7 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace
return;
}

auto maybe_versions = get_versions(paths.get_filesystem(), paths.current_versions_directory(), port_name);
auto maybe_versions = get_versions(paths.get_filesystem(), paths.current_registry_versions_dir(), port_name);
if (auto versions = maybe_versions.get())
{
const auto& versions_end = versions->end();
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace vcpkg::Commands::AddVersion
const bool verbose = Util::Sets::contains(parsed_args.switches, OPTION_VERBOSE);

auto& fs = paths.get_filesystem();
auto baseline_path = paths.current_versions_directory() / u8path("baseline.json");
auto baseline_path = paths.current_registry_versions_dir() / u8path("baseline.json");
if (!fs.exists(VCPKG_LINE_INFO, baseline_path))
{
vcpkg::printf(Color::error, "Error: Couldn't find required file `%s`\n.", vcpkg::u8string(baseline_path));
Expand Down Expand Up @@ -316,7 +316,7 @@ namespace vcpkg::Commands::AddVersion
Checks::exit_fail(VCPKG_LINE_INFO);
}

for (auto&& port_dir : stdfs::directory_iterator(paths.current_ports_directory()))
for (auto&& port_dir : stdfs::directory_iterator(paths.current_registry_ports_dir()))
{
port_names.emplace_back(vcpkg::u8string(port_dir.path().stem()));
}
Expand All @@ -333,13 +333,13 @@ namespace vcpkg::Commands::AddVersion
}();

// Get tree-ish from local repository state.
auto maybe_git_tree_map = paths.git_get_port_treeish_map(paths.current_ports_directory());
auto maybe_git_tree_map = paths.git_get_port_treeish_map(paths.current_registry_ports_dir());
auto git_tree_map = maybe_git_tree_map.value_or_exit(VCPKG_LINE_INFO);

for (auto&& port_name : port_names)
{
// Get version information of the local port
auto maybe_scf = Paragraphs::try_load_port(fs, paths.current_ports_directory() / u8path(port_name));
auto maybe_scf = Paragraphs::try_load_port(fs, paths.current_registry_ports_dir() / u8path(port_name));
if (!maybe_scf.has_value())
{
if (add_all) continue;
Expand All @@ -353,7 +353,7 @@ namespace vcpkg::Commands::AddVersion
{
// check if manifest file is property formatted
const auto path_to_manifest =
paths.current_ports_directory() / u8path(port_name) / u8path("vcpkg.json");
paths.current_registry_ports_dir() / u8path(port_name) / u8path("vcpkg.json");
if (fs.exists(path_to_manifest))
{
const auto current_file_content = fs.read_contents(path_to_manifest, VCPKG_LINE_INFO);
Expand Down Expand Up @@ -386,7 +386,7 @@ namespace vcpkg::Commands::AddVersion
}
const auto& git_tree = git_tree_it->second;

auto port_versions_path = paths.current_versions_directory() / u8path({port_name[0], '-'}) /
auto port_versions_path = paths.current_registry_versions_dir() / u8path({port_name[0], '-'}) /
u8path(Strings::concat(port_name, ".json"));
update_version_db_file(
paths, port_name, schemed_version, git_tree, port_versions_path, overwrite_version, verbose, add_all);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace vcpkg::Commands::Autocomplete

// TODO: Support autocomplete for ports in --overlay-ports
auto maybe_port =
Paragraphs::try_load_port(paths.get_filesystem(), paths.builtin_ports_directory() / port_name);
Paragraphs::try_load_port(paths.get_filesystem(), paths.builtin_registry_ports_dir() / port_name);
if (maybe_port.error())
{
Checks::exit_success(VCPKG_LINE_INFO);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ namespace vcpkg::Commands::CI

if (is_dry_run)
{
Dependencies::print_plan(action_plan, true, paths.builtin_ports_directory());
Dependencies::print_plan(action_plan, true, paths.builtin_registry_ports_dir());
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/vcpkg/commands.civerifyversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace vcpkg::Commands::CIVerifyVersions
bool verify_git_trees)
{
auto maybe_versions =
vcpkg::get_versions(paths.get_filesystem(), paths.current_versions_directory(), port_name);
vcpkg::get_versions(paths.get_filesystem(), paths.current_registry_versions_dir(), port_name);
if (!maybe_versions.has_value())
{
return {
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace vcpkg::Commands::CIVerifyVersions
for (const std::string& control_file : {"CONTROL", "vcpkg.json"})
{
auto treeish = Strings::concat(version_entry.second, ':', control_file);
auto maybe_file = paths.git_show(Strings::concat(treeish), paths.current_git_directory());
auto maybe_file = paths.git_show(Strings::concat(treeish), paths.current_registry_dot_git_dir());
if (!maybe_file.has_value()) continue;

const auto& file = maybe_file.value_or_exit(VCPKG_LINE_INFO);
Expand Down Expand Up @@ -302,7 +302,7 @@ namespace vcpkg::Commands::CIVerifyVersions
exclusion_set.insert(exclusions.begin(), exclusions.end());
}

auto maybe_port_git_tree_map = paths.git_get_port_treeish_map(paths.current_ports_directory());
auto maybe_port_git_tree_map = paths.git_get_port_treeish_map(paths.current_registry_ports_dir());
Checks::check_exit(VCPKG_LINE_INFO,
maybe_port_git_tree_map.has_value(),
"Fatal error: Failed to obtain git SHAs for local ports.\n%s",
Expand All @@ -313,7 +313,7 @@ namespace vcpkg::Commands::CIVerifyVersions
auto baseline = get_baseline(paths, paths.current_registry_root).value_or_exit(VCPKG_LINE_INFO);
auto& fs = paths.get_filesystem();
std::set<std::string> errors;
for (const auto& dir : stdfs::directory_iterator(paths.current_ports_directory()))
for (const auto& dir : stdfs::directory_iterator(paths.current_registry_ports_dir()))
{
const auto& port_path = dir.path();

Expand Down Expand Up @@ -368,7 +368,7 @@ namespace vcpkg::Commands::CIVerifyVersions
continue;
}

auto versions_file_path = paths.current_versions_directory() / vcpkg::u8path({port_name[0], '-'}) /
auto versions_file_path = paths.current_registry_versions_dir() / vcpkg::u8path({port_name[0], '-'}) /
vcpkg::u8path(Strings::concat(port_name, ".json"));
if (!fs.exists(versions_file_path))
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace vcpkg::Commands::Create
std::vector<CMakeVariable> cmake_args{
{"CMD", "CREATE"},
{"PORT", port_name},
{"PORT_PATH", vcpkg::generic_u8string(paths.current_ports_directory() / vcpkg::u8path(port_name))},
{"PORT_PATH", vcpkg::generic_u8string(paths.current_registry_ports_dir() / vcpkg::u8path(port_name))},
{"URL", url},
{"VCPKG_BASE_VERSION", Commands::Version::base_version()},
};
Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg/commands.edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace vcpkg::Commands::Edit

// TODO: Support edit for --overlay-ports
return Util::fmap(ports, [&](const std::string& port_name) -> std::string {
const auto portpath = paths.builtin_ports_directory() / port_name;
const auto portpath = paths.builtin_registry_ports_dir() / port_name;
const auto portfile = portpath / "portfile.cmake";
const auto buildtrees_current_dir = paths.build_dir(port_name);
const auto pattern = port_name + "_";
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace vcpkg::Commands::Edit
}

return Util::fmap(ports, [&](const std::string& port_name) -> std::string {
const auto portpath = paths.builtin_ports_directory() / port_name;
const auto portpath = paths.builtin_registry_ports_dir() / port_name;
const auto portfile = portpath / "portfile.cmake";
return Strings::format(R"###("%s" "%s")###", vcpkg::u8string(portpath), vcpkg::u8string(portfile));
});
Expand All @@ -160,7 +160,7 @@ namespace vcpkg::Commands::Edit
const std::vector<std::string>& ports = args.command_arguments;
for (auto&& port_name : ports)
{
const path portpath = paths.builtin_ports_directory() / port_name;
const path portpath = paths.builtin_registry_ports_dir() / port_name;
Checks::check_maybe_upgrade(
VCPKG_LINE_INFO, fs.is_directory(portpath), R"(Could not find port named "%s")", port_name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.format-manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace vcpkg::Commands::FormatManifest

if (format_all)
{
for (const auto& dir : stdfs::directory_iterator(paths.current_ports_directory()))
for (const auto& dir : stdfs::directory_iterator(paths.current_registry_ports_dir()))
{
auto control_path = dir.path() / vcpkg::u8path("CONTROL");
auto manifest_path = dir.path() / vcpkg::u8path("vcpkg.json");
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.portsdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace vcpkg::Commands::PortsDiff
std::error_code ec;
auto& fs = paths.get_filesystem();
const path dot_git_dir = paths.root / ".git";
const std::string ports_dir_name_as_string = vcpkg::u8string(paths.builtin_ports_directory().filename());
const std::string ports_dir_name_as_string = vcpkg::u8string(paths.builtin_registry_ports_dir().filename());
const path temp_checkout_path = paths.root / Strings::format("%s-%s", ports_dir_name_as_string, git_commit_id);
fs.create_directory(temp_checkout_path, ec);
const auto checkout_this_dir =
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.setinstalled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace vcpkg::Commands::SetInstalled
return Util::Sets::contains(specs_installed, ipa.spec);
});

Dependencies::print_plan(action_plan, true, paths.builtin_ports_directory());
Dependencies::print_plan(action_plan, true, paths.builtin_registry_ports_dir());

if (auto p_pkgsconfig = maybe_pkgsconfig.get())
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace vcpkg::Commands::Upgrade
action.build_options = vcpkg::Build::default_build_package_options;
}

Dependencies::print_plan(action_plan, true, paths.builtin_ports_directory());
Dependencies::print_plan(action_plan, true, paths.builtin_registry_ports_dir());

if (!no_dry_run)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ namespace vcpkg::Install
}
#endif // defined(_WIN32)

Dependencies::print_plan(action_plan, is_recursive, paths.builtin_ports_directory());
Dependencies::print_plan(action_plan, is_recursive, paths.builtin_registry_ports_dir());

auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG);
if (it_pkgsconfig != options.settings.end())
Expand Down
18 changes: 9 additions & 9 deletions src/vcpkg/registries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ namespace
const auto& fs = paths.get_filesystem();
if (!m_baseline_identifier.empty())
{
auto versions_path = paths.builtin_versions_directory() / relative_path_to_versions(port_name);
auto versions_path = paths.builtin_registry_versions_dir() / relative_path_to_versions(port_name);
if (fs.exists(versions_path))
{
auto maybe_version_entries =
load_versions_file(fs, VersionDbType::Git, paths.builtin_versions_directory(), port_name);
load_versions_file(fs, VersionDbType::Git, paths.builtin_registry_versions_dir(), port_name);
Checks::check_maybe_upgrade(
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);
Expand All @@ -328,7 +328,7 @@ namespace
}

// Fall back to current available version
auto port_directory = paths.builtin_ports_directory() / vcpkg::u8path(port_name);
auto port_directory = paths.builtin_registry_ports_dir() / vcpkg::u8path(port_name);
if (fs.exists(port_directory))
{
auto found_scf = Paragraphs::try_load_port(fs, port_directory);
Expand Down Expand Up @@ -437,7 +437,7 @@ namespace
}

// if a baseline is not specified, use the ports directory version
auto port_path = paths.builtin_ports_directory() / vcpkg::u8path(port_name);
auto port_path = paths.builtin_registry_ports_dir() / vcpkg::u8path(port_name);
auto maybe_scf = Paragraphs::try_load_port(paths.get_filesystem(), port_path);
if (auto pscf = maybe_scf.get())
{
Expand All @@ -452,16 +452,16 @@ namespace
{
const auto& fs = paths.get_filesystem();

if (!m_baseline_identifier.empty() && fs.exists(paths.builtin_versions_directory()))
if (!m_baseline_identifier.empty() && fs.exists(paths.builtin_registry_versions_dir()))
{
load_all_port_names_from_registry_versions(out, paths, paths.builtin_versions_directory());
load_all_port_names_from_registry_versions(out, paths, paths.builtin_registry_versions_dir());
}
std::error_code ec;
stdfs::directory_iterator dir_it(paths.builtin_ports_directory(), ec);
stdfs::directory_iterator dir_it(paths.builtin_registry_ports_dir(), ec);
Checks::check_exit(VCPKG_LINE_INFO,
!ec,
"Error: failed while enumerating the builtin ports directory %s: %s",
vcpkg::u8string(paths.builtin_ports_directory()),
vcpkg::u8string(paths.builtin_registry_ports_dir()),
ec.message());
for (auto port_directory : dir_it)
{
Expand Down Expand Up @@ -1313,7 +1313,7 @@ namespace vcpkg
ExpectedS<std::vector<std::pair<SchemedVersion, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name)
{
return get_versions(paths.get_filesystem(), paths.builtin_versions_directory(), port_name);
return get_versions(paths.get_filesystem(), paths.builtin_registry_versions_dir(), port_name);
}

ExpectedS<std::vector<std::pair<SchemedVersion, std::string>>> get_versions(const Filesystem& fs,
Expand Down
9 changes: 5 additions & 4 deletions src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,10 @@ namespace vcpkg
for (auto& dir_name : {".git", "ports", "versions"})
{
Checks::check_exit(VCPKG_LINE_INFO,
!(current_registry_root / u8path(dir_name)).empty(),
"Error: There is no " + std::string(dir_name) + " dir for current registry at " +
u8string(current_registry_root));
get_filesystem().exists(VCPKG_LINE_INFO, current_registry_root / u8path(dir_name)),
"Error: There is no %s directory for current registry at %s",
dir_name,
u8string(current_registry_root));
}
}

Expand Down Expand Up @@ -751,7 +752,7 @@ namespace vcpkg

ExpectedS<std::map<std::string, std::string, std::less<>>> VcpkgPaths::git_get_local_port_treeish_map() const
{
return git_get_port_treeish_map(builtin_ports_directory());
return git_get_port_treeish_map(builtin_registry_ports_dir());
}

ExpectedS<path> VcpkgPaths::git_checkout_baseline(const path& registry_root, StringView commit_sha) const
Expand Down

0 comments on commit 2b0efc6

Please sign in to comment.