mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 19:43:33 +01:00
vcpkg install
: Print install plan and add --dry-run option
This commit is contained in:
parent
c4d5763a53
commit
75838ddbcc
@ -12,6 +12,7 @@
|
|||||||
namespace vcpkg::Commands::Install
|
namespace vcpkg::Commands::Install
|
||||||
{
|
{
|
||||||
using Dependencies::PackageSpecWithInstallPlan;
|
using Dependencies::PackageSpecWithInstallPlan;
|
||||||
|
using Dependencies::RequestType;
|
||||||
using Dependencies::InstallPlanType;
|
using Dependencies::InstallPlanType;
|
||||||
|
|
||||||
static void install_and_write_listfile(const VcpkgPaths& paths, const BinaryParagraph& bpgh)
|
static void install_and_write_listfile(const VcpkgPaths& paths, const BinaryParagraph& bpgh)
|
||||||
@ -118,11 +119,11 @@ namespace vcpkg::Commands::Install
|
|||||||
const std::vector<fs::path> package_file_paths = Files::recursive_find_all_files_in_dir(package_dir);
|
const std::vector<fs::path> package_file_paths = Files::recursive_find_all_files_in_dir(package_dir);
|
||||||
const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash
|
const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash
|
||||||
auto package_files = Util::fmap(package_file_paths, [package_remove_char_count](const fs::path& path)
|
auto package_files = Util::fmap(package_file_paths, [package_remove_char_count](const fs::path& path)
|
||||||
{
|
{
|
||||||
std::string as_string = path.generic_string();
|
std::string as_string = path.generic_string();
|
||||||
as_string.erase(0, package_remove_char_count);
|
as_string.erase(0, package_remove_char_count);
|
||||||
return std::move(as_string);
|
return std::move(as_string);
|
||||||
});
|
});
|
||||||
|
|
||||||
return SortedVector<std::string>(std::move(package_files));
|
return SortedVector<std::string>(std::move(package_files));
|
||||||
}
|
}
|
||||||
@ -136,6 +137,51 @@ namespace vcpkg::Commands::Install
|
|||||||
return SortedVector<std::string>(std::move(installed_files));
|
return SortedVector<std::string>(std::move(installed_files));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_plan(const std::vector<PackageSpecWithInstallPlan>& plan)
|
||||||
|
{
|
||||||
|
std::vector<const PackageSpecWithInstallPlan*> already_installed;
|
||||||
|
std::vector<const PackageSpecWithInstallPlan*> build_and_install;
|
||||||
|
std::vector<const PackageSpecWithInstallPlan*> install;
|
||||||
|
|
||||||
|
for (const PackageSpecWithInstallPlan& i : plan)
|
||||||
|
{
|
||||||
|
switch (i.plan.plan_type)
|
||||||
|
{
|
||||||
|
case InstallPlanType::ALREADY_INSTALLED:
|
||||||
|
already_installed.push_back(&i);
|
||||||
|
continue;
|
||||||
|
case InstallPlanType::BUILD_AND_INSTALL:
|
||||||
|
build_and_install.push_back(&i);
|
||||||
|
continue;
|
||||||
|
case InstallPlanType::INSTALL:
|
||||||
|
install.push_back(&i);
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
Checks::unreachable(VCPKG_LINE_INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto print_lambda = [](const PackageSpecWithInstallPlan* p) { return to_output_string(p->plan.request_type, p->spec.to_string()); };
|
||||||
|
|
||||||
|
if (!already_installed.empty())
|
||||||
|
{
|
||||||
|
std::sort(already_installed.begin(), already_installed.end(), &PackageSpecWithInstallPlan::compare_by_name);
|
||||||
|
System::println("The following packages are already installed:\n%s", Strings::join("\n", already_installed, print_lambda));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!build_and_install.empty())
|
||||||
|
{
|
||||||
|
std::sort(build_and_install.begin(), build_and_install.end(), &PackageSpecWithInstallPlan::compare_by_name);
|
||||||
|
System::println("The following packages will be built and installed:\n%s", Strings::join("\n", build_and_install, print_lambda));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!install.empty())
|
||||||
|
{
|
||||||
|
std::sort(install.begin(), install.end(), &PackageSpecWithInstallPlan::compare_by_name);
|
||||||
|
System::println("The following packages will be installed:\n%s", Strings::join("\n", install, print_lambda));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void install_package(const VcpkgPaths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs* status_db)
|
void install_package(const VcpkgPaths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs* status_db)
|
||||||
{
|
{
|
||||||
const fs::path package_dir = paths.package_dir(binary_paragraph.spec);
|
const fs::path package_dir = paths.package_dir(binary_paragraph.spec);
|
||||||
@ -185,18 +231,21 @@ namespace vcpkg::Commands::Install
|
|||||||
|
|
||||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_target_triplet)
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_target_triplet)
|
||||||
{
|
{
|
||||||
|
static const std::string OPTION_DRY_RUN = "--dry-run";
|
||||||
|
|
||||||
// input sanitization
|
// input sanitization
|
||||||
static const std::string example = Commands::Help::create_example_string("install zlib zlib:x64-windows curl boost");
|
static const std::string example = Commands::Help::create_example_string("install zlib zlib:x64-windows curl boost");
|
||||||
args.check_min_arg_count(1, example);
|
args.check_min_arg_count(1, example);
|
||||||
|
|
||||||
auto specs = Util::fmap(args.command_arguments, [&](auto&& arg)
|
auto specs = Util::fmap(args.command_arguments, [&](auto&& arg)
|
||||||
{
|
{
|
||||||
auto spec = Input::check_and_get_package_spec(arg, default_target_triplet, example);
|
auto spec = Input::check_and_get_package_spec(arg, default_target_triplet, example);
|
||||||
Input::check_triplet(spec.target_triplet(), paths);
|
Input::check_triplet(spec.target_triplet(), paths);
|
||||||
return spec;
|
return spec;
|
||||||
});
|
});
|
||||||
|
|
||||||
args.check_and_get_optional_command_arguments({});
|
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_DRY_RUN });
|
||||||
|
const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend();
|
||||||
|
|
||||||
// create the plan
|
// create the plan
|
||||||
StatusParagraphs status_db = database_load_check(paths);
|
StatusParagraphs status_db = database_load_check(paths);
|
||||||
@ -212,6 +261,23 @@ namespace vcpkg::Commands::Install
|
|||||||
}
|
}
|
||||||
Metrics::track_property("installplan", specs_string);
|
Metrics::track_property("installplan", specs_string);
|
||||||
|
|
||||||
|
print_plan(install_plan);
|
||||||
|
|
||||||
|
const bool has_non_user_requested_packages = std::find_if(install_plan.cbegin(), install_plan.cend(), [](const PackageSpecWithInstallPlan& package)-> bool
|
||||||
|
{
|
||||||
|
return package.plan.request_type != RequestType::USER_REQUESTED;
|
||||||
|
}) != install_plan.cend();
|
||||||
|
|
||||||
|
if (has_non_user_requested_packages)
|
||||||
|
{
|
||||||
|
System::println(System::Color::warning, "Additional packages (*) need to be installed to complete this operation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dryRun)
|
||||||
|
{
|
||||||
|
Checks::exit_success(VCPKG_LINE_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
// execute the plan
|
// execute the plan
|
||||||
for (const PackageSpecWithInstallPlan& action : install_plan)
|
for (const PackageSpecWithInstallPlan& action : install_plan)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user