Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg-x-set-installed] Implement --dry-run #12132

Merged
merged 2 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 28 additions & 11 deletions toolsrc/src/vcpkg/commands.setinstalled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

namespace vcpkg::Commands::SetInstalled
{
static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run";

static constexpr CommandSwitch INSTALL_SWITCHES[] = {
{OPTION_DRY_RUN, "Do not actually build or install"},
};

const CommandStructure COMMAND_STRUCTURE = {
create_example_string(R"(x-set-installed <package>...)"),
1,
0,
SIZE_MAX,
{},
{INSTALL_SWITCHES},
nullptr,
};

Expand All @@ -39,6 +45,8 @@ namespace vcpkg::Commands::SetInstalled
auto binaryprovider =
create_binary_provider_from_configs(paths, args.binarysources).value_or_exit(VCPKG_LINE_INFO);

const bool dry_run = Util::Sets::contains(options.switches, OPTION_DRY_RUN);

const Build::BuildPackageOptions install_plan_options = {
Build::UseHeadVersion::NO,
Build::AllowDownloads::YES,
Expand Down Expand Up @@ -76,6 +84,7 @@ namespace vcpkg::Commands::SetInstalled
// currently (or once) installed specifications
auto status_db = database_load_check(paths);
std::vector<PackageSpec> specs_to_remove;
std::set<PackageSpec> specs_installed;
for (auto&& status_pgh : status_db)
{
if (!status_pgh->is_installed()) continue;
Expand All @@ -86,25 +95,33 @@ namespace vcpkg::Commands::SetInstalled
{
specs_to_remove.push_back(status_pgh->package.spec);
}
else
{
specs_installed.emplace(status_pgh->package.spec);
}
}

auto remove_plan = Dependencies::create_remove_plan(specs_to_remove, status_db);
action_plan.remove_actions = Dependencies::create_remove_plan(specs_to_remove, status_db);

for (const auto& action : remove_plan)
for (const auto& action : action_plan.remove_actions)
{
Remove::perform_remove_plan_action(paths, action, Remove::Purge::NO, &status_db);
// This should not technically be needed, however ensuring that all specs to be removed are not included in
// `specs_installed` acts as a sanity check
specs_installed.erase(action.spec);
}

auto real_action_plan = Dependencies::create_feature_install_plan(provider, *cmake_vars, specs, status_db);
Util::erase_remove_if(action_plan.install_actions, [&](const Dependencies::InstallPlanAction& ipa) {
return Util::Sets::contains(specs_installed, ipa.spec);
});

Dependencies::print_plan(action_plan, true, paths.ports);

for (auto& action : real_action_plan.install_actions)
if (dry_run)
{
action.build_options = install_plan_options;
Checks::exit_success(VCPKG_LINE_INFO);
}

Dependencies::print_plan(real_action_plan, true);

const auto summary = Install::perform(real_action_plan,
const auto summary = Install::perform(action_plan,
Install::KeepGoing::NO,
paths,
status_db,
Expand Down
20 changes: 19 additions & 1 deletion toolsrc/src/vcpkg/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,13 @@ namespace vcpkg::Dependencies

void print_plan(const ActionPlan& action_plan, const bool is_recursive, const fs::path& default_ports_dir)
{
if (action_plan.remove_actions.empty() && action_plan.already_installed.empty() &&
action_plan.install_actions.empty())
{
System::print2("All requested packages are currently installed.\n");
return;
}

std::vector<const RemovePlanAction*> remove_plans;
std::vector<const InstallPlanAction*> rebuilt_plans;
std::vector<const InstallPlanAction*> only_install_plans;
Expand All @@ -972,6 +979,7 @@ namespace vcpkg::Dependencies
[&](const RemovePlanAction* plan) { return plan->spec == install_action.spec; });
if (it != remove_plans.end())
{
remove_plans.erase(it);
rebuilt_plans.push_back(&install_action);
}
else
Expand Down Expand Up @@ -1019,6 +1027,16 @@ namespace vcpkg::Dependencies
'\n');
}

if (!remove_plans.empty())
{
std::string msg = "The following packages will be removed:\n";
for (auto action : remove_plans)
{
Strings::append(msg, to_output_string(RequestType::USER_REQUESTED, action->spec.to_string()), '\n');
}
System::print2(msg);
}

if (!rebuilt_plans.empty())
{
System::print2("The following packages will be rebuilt:\n", actions_to_output_string(rebuilt_plans), '\n');
Expand All @@ -1040,7 +1058,7 @@ namespace vcpkg::Dependencies
if (has_non_user_requested_packages)
System::print2("Additional packages (*) will be modified to complete this operation.\n");

if (!remove_plans.empty() && !is_recursive)
if ((!remove_plans.empty() || !rebuilt_plans.empty()) && !is_recursive)
{
System::print2(System::Color::warning,
"If you are sure you want to rebuild the above packages, run the command with the "
Expand Down