Skip to content
Draft
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
14 changes: 14 additions & 0 deletions include/vcpkg/commands.format-port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands::FormatPort
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct FormatPortCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
22 changes: 22 additions & 0 deletions include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/view.h>

#include <vcpkg/build.h>
#include <vcpkg/versiondeserializers.h>
#include <vcpkg/versions.h>

Expand Down Expand Up @@ -196,4 +197,25 @@ namespace vcpkg
private:
VersionDbEntryDeserializer underlying;
};

struct CommandRegistryPaths
{
Path root_path;
Path git_directory_path;
Path ports_directory_path;
Path version_directory_path;
};

CommandRegistryPaths resolve_command_registry_paths(const Filesystem& fs,
const VcpkgPaths& paths,
const VcpkgCmdArguments& args,
Build::Editable is_editable);

ExpectedS<std::vector<std::pair<SchemedVersion, std::string>>> get_registry_versions(
const VcpkgPaths& paths, const CommandRegistryPaths& registry_paths, StringView port_name);

ExpectedS<std::map<std::string, Version, std::less<>>> get_registry_baseline(
const VcpkgPaths& paths, const CommandRegistryPaths& registry_paths);

GitConfig get_registry_git_config(const VcpkgPaths& paths, const CommandRegistryPaths& registry_paths);
}
2 changes: 2 additions & 0 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ namespace vcpkg

const DownloadManager& get_download_manager() const;

ExpectedS<std::map<std::string, std::string, std::less<>>> git_get_registry_port_treeish_map(
const Path& ports_dir) const;
ExpectedS<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map() const;

// Git manipulation for remote registries
Expand Down
47 changes: 30 additions & 17 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vcpkg/base/json.h>
#include <vcpkg/base/system.print.h>

#include <vcpkg/build.h>
#include <vcpkg/commands.add-version.h>
#include <vcpkg/configuration.h>
#include <vcpkg/paragraphs.h>
Expand Down Expand Up @@ -274,16 +275,20 @@ namespace
return UpdateResult::Updated;
}

static UpdateResult update_version_db_file(const VcpkgPaths& paths,
static UpdateResult update_version_db_file(const CommandRegistryPaths& registry_paths,
const VcpkgPaths& paths,
const std::string& port_name,
const SchemedVersion& port_version,
const std::string& git_tree,
const Path& version_db_file_path,
bool overwrite_version,
bool print_success,
bool keep_going,
bool skip_version_format_check)
{
char prefix[] = {port_name[0], '-', '\0'};
auto version_db_file_path =
registry_paths.version_directory_path / prefix / Strings::concat(port_name, ".json");

auto& fs = paths.get_filesystem();
if (!fs.exists(version_db_file_path, IgnoreErrors{}))
{
Expand All @@ -305,7 +310,7 @@ namespace
return UpdateResult::Updated;
}

auto maybe_versions = get_builtin_versions(paths, port_name);
auto maybe_versions = get_registry_versions(paths, registry_paths, port_name);
if (auto versions = maybe_versions.get())
{
const auto& versions_end = versions->end();
Expand Down Expand Up @@ -431,12 +436,21 @@ namespace vcpkg::Commands::AddVersion
const bool verbose = !add_all || Util::Sets::contains(parsed_args.switches, OPTION_VERBOSE);

auto& fs = paths.get_filesystem();
auto baseline_path = paths.builtin_registry_versions / "baseline.json";
CommandRegistryPaths registry_paths = resolve_command_registry_paths(fs, paths, args, Build::Editable::YES);

auto baseline_path = registry_paths.version_directory_path / "baseline.json";
if (!fs.exists(baseline_path, IgnoreErrors{}))
{
Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgAddVersionFileNotFound, msg::path = baseline_path);
}

auto git_config = get_registry_git_config(paths, registry_paths);
if (!fs.exists(git_config.git_dir, VCPKG_LINE_INFO))
{
vcpkg::printf(Color::error, "Error: Couldn't find required directory `%s`\n.", git_config.git_dir);
Checks::exit_fail(VCPKG_LINE_INFO);
}

std::vector<std::string> port_names;
if (!args.command_arguments.empty())
{
Expand All @@ -454,7 +468,8 @@ namespace vcpkg::Commands::AddVersion
msg::command_name = "x-add-version",
msg::option = OPTION_ALL);

for (auto&& port_dir : fs.get_directories_non_recursive(paths.builtin_ports_directory(), VCPKG_LINE_INFO))
for (auto&& port_dir :
fs.get_directories_non_recursive(registry_paths.ports_directory_path, VCPKG_LINE_INFO))
{
port_names.emplace_back(port_dir.stem().to_string());
}
Expand All @@ -466,17 +481,16 @@ namespace vcpkg::Commands::AddVersion
std::map<std::string, vcpkg::Version, std::less<>> ret;
return ret;
}
auto maybe_baseline_map = vcpkg::get_builtin_baseline(paths);
auto maybe_baseline_map = get_registry_baseline(paths, registry_paths);
return maybe_baseline_map.value_or_exit(VCPKG_LINE_INFO);
}();

// Get tree-ish from local repository state.
auto maybe_git_tree_map = paths.git_get_local_port_treeish_map();
auto maybe_git_tree_map = paths.git_get_registry_port_treeish_map(registry_paths.ports_directory_path);
auto git_tree_map = maybe_git_tree_map.value_or_exit(VCPKG_LINE_INFO);

// Find ports with uncommited changes
std::set<std::string> changed_ports;
auto git_config = paths.git_builtin_config();
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
if (auto changes = maybe_changes.get())
{
Expand All @@ -489,7 +503,7 @@ namespace vcpkg::Commands::AddVersion

for (auto&& port_name : port_names)
{
auto port_dir = paths.builtin_ports_directory() / port_name;
auto port_dir = registry_paths.ports_directory_path / port_name;

if (!fs.exists(port_dir, IgnoreErrors{}))
{
Expand All @@ -498,7 +512,8 @@ namespace vcpkg::Commands::AddVersion
continue;
}

auto maybe_scf = Paragraphs::try_load_port(fs, paths.builtin_ports_directory() / port_name);
// Get version information of the local port
auto maybe_scf = Paragraphs::try_load_port(fs, registry_paths.ports_directory_path / port_name);
if (!maybe_scf.has_value())
{
msg::print_error(msgAddVersionLoadPortFailed, msg::package_name = port_name);
Expand All @@ -512,15 +527,15 @@ namespace vcpkg::Commands::AddVersion
if (!skip_formatting_check)
{
// check if manifest file is property formatted
const auto path_to_manifest = paths.builtin_ports_directory() / port_name / "vcpkg.json";
const auto path_to_manifest = registry_paths.ports_directory_path / port_name / "vcpkg.json";
if (fs.exists(path_to_manifest, IgnoreErrors{}))
{
const auto current_file_content = fs.read_contents(path_to_manifest, VCPKG_LINE_INFO);
const auto json = serialize_manifest(*scf);
const auto formatted_content = Json::stringify(json, {});
if (current_file_content != formatted_content)
{
auto command_line = fmt::format("vcpkg format-manifest ports/{}/vcpkg.json", port_name);
auto command_line = fmt::format("vcpkg format-port {}", port_name);
msg::print_error(
msg::format(msgAddVersionPortHasImproperFormat, msg::package_name = port_name)
.appendnl()
Expand Down Expand Up @@ -556,15 +571,13 @@ namespace vcpkg::Commands::AddVersion
Checks::check_exit(VCPKG_LINE_INFO, !add_all);
continue;
}
const auto& git_tree = git_tree_it->second;

char prefix[] = {port_name[0], '-', '\0'};
auto port_versions_path = paths.builtin_registry_versions / prefix / Strings::concat(port_name, ".json");
auto updated_versions_file = update_version_db_file(paths,
const auto& git_tree = git_tree_it->second;
auto updated_versions_file = update_version_db_file(registry_paths,
paths,
port_name,
schemed_version,
git_tree,
port_versions_path,
overwrite_version,
verbose,
add_all,
Expand Down
3 changes: 3 additions & 0 deletions src/vcpkg/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vcpkg/commands.fetch.h>
#include <vcpkg/commands.find.h>
#include <vcpkg/commands.format-manifest.h>
#include <vcpkg/commands.format-port.h>
#include <vcpkg/commands.generate-message-map.h>
#include <vcpkg/commands.h>
#include <vcpkg/commands.hash.h>
Expand Down Expand Up @@ -93,6 +94,7 @@ namespace vcpkg::Commands
static const Fetch::FetchCommand fetch{};
static const FindCommand find_{};
static const FormatManifest::FormatManifestCommand format_manifest{};
static const FormatPort::FormatPortCommand format_port{};
static const Help::HelpCommand help{};
static const Info::InfoCommand info{};
static const Integrate::IntegrateCommand integrate{};
Expand Down Expand Up @@ -121,6 +123,7 @@ namespace vcpkg::Commands
{"fetch", &fetch},
{"find", &find_},
{"format-manifest", &format_manifest},
{"format-port", &format_port},
{"integrate", &integrate},
{"list", &list},
{"new", &new_},
Expand Down
2 changes: 2 additions & 0 deletions src/vcpkg/commands.format-manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ namespace vcpkg::Commands::FormatManifest
{
if (path.is_relative())
{
// TODO: Handle consistent port access
path = paths.original_cwd / path;
}

Expand All @@ -237,6 +238,7 @@ namespace vcpkg::Commands::FormatManifest

if (format_all)
{
// TODO: Handle consistent port access
for (const auto& dir : fs.get_directories_non_recursive(paths.builtin_ports_directory(), VCPKG_LINE_INFO))
{
auto control_path = dir / "CONTROL";
Expand Down
Loading