Rework vcpkg install (and vcpkg ci)
Refactor install-plan-execution code to reduce duplication
Add `vcpkg install --keep-going` option
Add elapsed time to each invidial package and total time
Add a counter to the install (e.g. Starting package 3/12: <name>)
MODIFY
include/vcpkg_Commands.h
include/vcpkg_Commands.h
@@ -33,6 +33,22 @@ namespace vcpkg::Commands
namespace Install
{
+ enum class KeepGoing
+ {
+ NO = 0,
+ YES
+ };
+
+ inline KeepGoing to_keep_going(const bool value) { return value ? KeepGoing::YES : KeepGoing::NO; }
+
+ enum class PrintSummary
+ {
+ NO = 0,
+ YES
+ };
+
+ inline PrintSummary to_print_summary(const bool value) { return value ? PrintSummary::YES : PrintSummary::NO; }
+
struct InstallDir
{
static InstallDir from_destination_root(const fs::path& destination_root,
@@ -67,6 +83,14 @@ namespace vcpkg::Commands
InstallResult install_package(const VcpkgPaths& paths,
const BinaryControlFile& binary_paragraph,
StatusParagraphs* status_db);
+
+ void perform_and_exit(const std::vector<Dependencies::AnyAction>& action_plan,
+ const Build::BuildPackageOptions& install_plan_options,
+ const KeepGoing keep_going,
+ const PrintSummary print_summary,
+ const VcpkgPaths& paths,
+ StatusParagraphs& status_db);
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet);
}

MODIFY
include/vcpkg_Dependencies.h
include/vcpkg_Dependencies.h
@@ -89,6 +89,8 @@ namespace vcpkg::Dependencies
Optional<InstallPlanAction> install_plan;
Optional<RemovePlanAction> remove_plan;
+
+ const PackageSpec& spec() const;
};
enum class ExportPlanType

MODIFY
src/commands_ci.cpp
src/commands_ci.cpp
@@ -41,57 +41,19 @@ namespace vcpkg::Commands::CI
StatusParagraphs status_db = database_load_check(paths);
const auto& paths_port_file = Dependencies::PathsPortFile(paths);
- const std::vector<InstallPlanAction> install_plan =
+ std::vector<InstallPlanAction> install_plan =
Dependencies::create_install_plan(paths_port_file, specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
- std::vector<BuildResult> results;
- std::vector<std::string> timing;
- const ElapsedTime timer = ElapsedTime::create_started();
- size_t counter = 0;
- const size_t package_count = install_plan.size();
const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
- for (const InstallPlanAction& action : install_plan)
- {
- const ElapsedTime build_timer = ElapsedTime::create_started();
- counter++;
- const std::string display_name = action.spec.to_string();
- System::println("Starting package %d/%d: %s", counter, package_count, display_name);
-
- timing.push_back("0");
- results.push_back(BuildResult::NULLVALUE);
-
- const BuildResult result =
- Install::perform_install_plan_action(paths, action, install_plan_options, status_db);
- timing.back() = build_timer.to_string();
- results.back() = result;
- System::println("Elapsed time for package %s: %s", action.spec, build_timer.to_string());
- }
-
- System::println("Total time taken: %s", timer.to_string());
-
- for (size_t i = 0; i < results.size(); i++)
- {
- System::println("%s: %s: %s", install_plan[i].spec, Build::to_string(results[i]), timing[i]);
- }
-
- std::map<BuildResult, int> summary;
- for (const BuildResult& v : Build::BUILD_RESULT_VALUES)
- {
- summary[v] = 0;
- }
-
- for (const BuildResult& r : results)
- {
- summary[r]++;
- }
+ const std::vector<Dependencies::AnyAction> action_plan =
+ Util::fmap(install_plan, [](InstallPlanAction& install_action) {
+ return Dependencies::AnyAction(std::move(install_action));
+ });
- System::println("\n\nSUMMARY");
- for (const std::pair<const BuildResult, int>& entry : summary)
- {
- System::println(" %s: %d", Build::to_string(entry.first), entry.second);
- }
+ Install::perform_and_exit(
+ action_plan, install_plan_options, Install::KeepGoing::YES, Install::PrintSummary::YES, paths, status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -442,12 +442,98 @@ namespace vcpkg::Commands::Install
}
}
+ void perform_and_exit(const std::vector<AnyAction>& action_plan,
+ const Build::BuildPackageOptions& install_plan_options,
+ const KeepGoing keep_going,
+ const PrintSummary print_summary,
+ const VcpkgPaths& paths,
+ StatusParagraphs& status_db)
+ {
+ std::vector<BuildResult> results;
+ std::vector<std::string> timing;
+ const ElapsedTime timer = ElapsedTime::create_started();
+ size_t counter = 0;
+ const size_t package_count = action_plan.size();
+
+ for (const auto& action : action_plan)
+ {
+ const ElapsedTime build_timer = ElapsedTime::create_started();
+ counter++;
+
+ if (counter > 2)
+ {
+ break;
+ }
+
+ const std::string display_name = action.spec().to_string();
+ System::println("Starting package %d/%d: %s", counter, package_count, display_name);
+
+ timing.push_back("0");
+ results.push_back(BuildResult::NULLVALUE);
+
+ if (const auto install_action = action.install_plan.get())
+ {
+ const BuildResult result =
+ perform_install_plan_action(paths, *install_action, install_plan_options, status_db);
+ if (result != BuildResult::SUCCEEDED && keep_going == KeepGoing::NO)
+ {
+ System::println(Build::create_user_troubleshooting_message(install_action->spec));
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
+
+ results.back() = result;
+ }
+ else if (const auto remove_action = action.remove_plan.get())
+ {
+ Checks::check_exit(VCPKG_LINE_INFO, GlobalState::feature_packages);
+ Remove::perform_remove_plan_action(paths, *remove_action, Remove::Purge::YES, status_db);
+ }
+ else
+ {
+ Checks::unreachable(VCPKG_LINE_INFO);
+ }
+
+ timing.back() = build_timer.to_string();
+ System::println("Elapsed time for package %s: %s", display_name, build_timer.to_string());
+ }
+
+ System::println("Total time taken: %s", timer.to_string());
+
+ if (print_summary == PrintSummary::YES)
+ {
+ for (size_t i = 0; i < results.size(); i++)
+ {
+ System::println("%s: %s: %s", action_plan[i].spec(), Build::to_string(results[i]), timing[i]);
+ }
+
+ std::map<BuildResult, int> summary;
+ for (const BuildResult& v : Build::BUILD_RESULT_VALUES)
+ {
+ summary[v] = 0;
+ }
+
+ for (const BuildResult& r : results)
+ {
+ summary[r]++;
+ }
+
+ System::println("\n\nSUMMARY");
+ for (const std::pair<const BuildResult, int>& entry : summary)
+ {
+ System::println(" %s: %d", Build::to_string(entry.first), entry.second);
+ }
+ }
+
+ Checks::exit_success(VCPKG_LINE_INFO);
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_DRY_RUN = "--dry-run";
static const std::string OPTION_USE_HEAD_VERSION = "--head";
static const std::string OPTION_NO_DOWNLOADS = "--no-downloads";
static const std::string OPTION_RECURSE = "--recurse";
+ static const std::string OPTION_KEEP_GOING = "--keep-going";
// input sanitization
static const std::string EXAMPLE =
@@ -469,11 +555,12 @@ namespace vcpkg::Commands::Install
}
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments(
- {OPTION_DRY_RUN, OPTION_USE_HEAD_VERSION, OPTION_NO_DOWNLOADS, OPTION_RECURSE});
+ {OPTION_DRY_RUN, OPTION_USE_HEAD_VERSION, OPTION_NO_DOWNLOADS, OPTION_RECURSE, OPTION_KEEP_GOING});
const bool dry_run = options.find(OPTION_DRY_RUN) != options.cend();
const bool use_head_version = options.find(OPTION_USE_HEAD_VERSION) != options.cend();
const bool no_downloads = options.find(OPTION_NO_DOWNLOADS) != options.cend();
const bool is_recursive = options.find(OPTION_RECURSE) != options.cend();
+ const KeepGoing keep_going = to_keep_going(options.find(OPTION_KEEP_GOING) != options.cend());
// create the plan
StatusParagraphs status_db = database_load_check(paths);
@@ -524,28 +611,7 @@ namespace vcpkg::Commands::Install
Checks::exit_success(VCPKG_LINE_INFO);
}
- for (const auto& action : action_plan)
- {
- if (const auto install_action = action.install_plan.get())
- {
- const BuildResult result =
- perform_install_plan_action(paths, *install_action, install_plan_options, status_db);
- if (result != BuildResult::SUCCEEDED)
- {
- System::println(Build::create_user_troubleshooting_message(install_action->spec));
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- }
- else if (const auto remove_action = action.remove_plan.get())
- {
- Checks::check_exit(VCPKG_LINE_INFO, GlobalState::feature_packages);
- Remove::perform_remove_plan_action(paths, *remove_action, Remove::Purge::YES, status_db);
- }
- else
- {
- Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
+ perform_and_exit(action_plan, install_plan_options, keep_going, PrintSummary::NO, paths, status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}

MODIFY
src/vcpkg_Dependencies.cpp
src/vcpkg_Dependencies.cpp
@@ -213,6 +213,21 @@ namespace vcpkg::Dependencies
{
}
+ const PackageSpec& AnyAction::spec() const
+ {
+ if (const auto p = install_plan.get())
+ {
+ return p->spec;
+ }
+
+ if (const auto p = remove_plan.get())
+ {
+ return p->spec;
+ }
+
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Null action");
+ }
+
bool ExportPlanAction::compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right)
{
return left->spec.name() < right->spec.name();

Rework vcpkg install (and vcpkg ci)

- Refactor install-plan-execution code to reduce duplication
- Add `vcpkg install --keep-going` option
- Add elapsed time to each invidial package and total time
- Add a counter to the install (e.g. Starting package 3/12: <name>)