Install continue
MODIFY
include/vcpkg_Build.h
include/vcpkg_Build.h
namespace vcpkg::Build
{
+ enum class UseHeadVersion
+ {
+ NO = 0,
+ YES
+ };
+
+ inline UseHeadVersion to_use_head_version(const bool value)
+ {
+ return value ? UseHeadVersion::YES : UseHeadVersion::NO;
+ }
+
+ inline bool to_bool(const UseHeadVersion value) { return value == UseHeadVersion::YES; }
+
+ enum class AllowDownloads
+ {
+ NO = 0,
+ YES
+ };
+
+ inline AllowDownloads to_allow_downloads(const bool value)
+ {
+ return value ? AllowDownloads::YES : AllowDownloads::NO;
+ }
+
+ inline bool to_bool(const AllowDownloads value) { return value == AllowDownloads::YES; }
+
+ struct BuildPackageOptions
+ {
+ UseHeadVersion use_head_version;
+ AllowDownloads allow_downloads;
+ };
+
enum class BuildResult
{
NULLVALUE = 0,
@@ -59,17 +91,18 @@ namespace vcpkg::Build
struct BuildPackageConfig
{
- BuildPackageConfig(const SourceParagraph& src, const Triplet& triplet, fs::path&& port_dir)
- : src(src), triplet(triplet), port_dir(std::move(port_dir)), use_head_version(false), no_downloads(false)
+ BuildPackageConfig(const SourceParagraph& src,
+ const Triplet& triplet,
+ fs::path&& port_dir,
+ const BuildPackageOptions& build_package_options)
+ : src(src), triplet(triplet), port_dir(std::move(port_dir)), build_package_options(build_package_options)
{
}
const SourceParagraph& src;
const Triplet& triplet;
fs::path port_dir;
-
- bool use_head_version;
- bool no_downloads;
+ const BuildPackageOptions& build_package_options;
};
ExtendedBuildResult build_package(const VcpkgPaths& paths,

MODIFY
include/vcpkg_Commands.h
include/vcpkg_Commands.h
#include "VcpkgCmdArguments.h"
#include "VcpkgPaths.h"
#include "VersionT.h"
+#include "vcpkg_Build.h"
+#include "vcpkg_Dependencies.h"
#include <array>
namespace vcpkg::Commands
@@ -48,6 +50,11 @@ namespace vcpkg::Commands
const fs::path& listfile() const;
};
+ Build::BuildResult perform_install_plan_action(const VcpkgPaths& paths,
+ const Dependencies::InstallPlanAction& action,
+ const Build::BuildPackageOptions& install_plan_options,
+ StatusParagraphs& status_db);
+
void install_files_and_write_listfile(Files::Filesystem& fs,
const fs::path& source_dir,
const InstallDir& dirs);

MODIFY
src/commands_build.cpp
src/commands_build.cpp
@@ -50,9 +50,8 @@ namespace vcpkg::Commands::BuildCommand
spec.name());
StatusParagraphs status_db = database_load_check(paths);
- const Build::BuildPackageConfig build_config{
- spgh, spec.triplet(), paths.port_dir(spec),
- };
+ Build::BuildPackageOptions build_package_options{Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
+ const Build::BuildPackageConfig build_config{spgh, spec.triplet(), paths.port_dir(spec), build_package_options};
const auto result = Build::build_package(paths, build_config, status_db);
if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES)
{

MODIFY
src/commands_ci.cpp
src/commands_ci.cpp
@@ -50,6 +50,8 @@ namespace vcpkg::Commands::CI
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();
@@ -60,55 +62,10 @@ namespace vcpkg::Commands::CI
timing.push_back("0");
results.push_back(BuildResult::NULLVALUE);
- try
- {
- switch (action.plan_type)
- {
- case InstallPlanType::ALREADY_INSTALLED:
- results.back() = BuildResult::SUCCEEDED;
- System::println(System::Color::success, "Package %s is already installed", display_name);
- break;
- case InstallPlanType::BUILD_AND_INSTALL:
- {
- System::println("Building package %s... ", display_name);
- auto&& source_paragraph = action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO);
- const Build::BuildPackageConfig build_config{
- source_paragraph, action.spec.triplet(), paths.port_dir(action.spec),
- };
- const auto result_ex = Build::build_package(paths, build_config, status_db);
- const auto result = result_ex.code;
-
+ const BuildResult result =
+ Install::perform_install_plan_action(paths, action, install_plan_options, status_db);
timing.back() = build_timer.to_string();
results.back() = result;
- if (result != BuildResult::SUCCEEDED)
- {
- System::println(System::Color::error, Build::create_error_message(result, action.spec));
- continue;
- }
- System::println(System::Color::success, "Building package %s... done", display_name);
-
- const BinaryParagraph bpgh =
- Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name);
- Install::install_package(paths, bpgh, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- }
- case InstallPlanType::INSTALL:
- results.back() = BuildResult::SUCCEEDED;
- System::println("Installing package %s... ", display_name);
- Install::install_package(
- paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
- catch (const std::exception& e)
- {
- System::println(System::Color::error, "Error: Could not install package %s: %s", action.spec, e.what());
- results.back() = BuildResult::NULLVALUE;
- }
System::println("Elapsed time for package %s: %s", action.spec, build_timer.to_string());
}

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -263,6 +263,77 @@ namespace vcpkg::Commands::Install
status_db->insert(std::make_unique<StatusParagraph>(source_paragraph));
}
+ using Build::BuildResult;
+
+ BuildResult perform_install_plan_action(const VcpkgPaths& paths,
+ const InstallPlanAction& action,
+ const Build::BuildPackageOptions& build_package_options,
+ StatusParagraphs& status_db)
+ {
+ const InstallPlanType& plan_type = action.plan_type;
+ const std::string display_name = action.spec.to_string();
+
+ const bool is_user_requested = action.request_type == RequestType::USER_REQUESTED;
+ const bool use_head_version = to_bool(build_package_options.use_head_version);
+
+ if (plan_type == InstallPlanType::ALREADY_INSTALLED)
+ {
+ if (use_head_version && is_user_requested)
+ {
+ System::println(
+ System::Color::warning, "Package %s is already installed -- not building from HEAD", display_name);
+ }
+ else
+ {
+ System::println(System::Color::success, "Package %s is already installed", display_name);
+ }
+ return BuildResult::SUCCEEDED;
+ }
+
+ if (plan_type == InstallPlanType::BUILD_AND_INSTALL)
+ {
+ if (use_head_version)
+ System::println("Building package %s from HEAD... ", display_name);
+ else
+ System::println("Building package %s... ", display_name);
+
+ const Build::BuildPackageConfig build_config{
+ action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
+ action.spec.triplet(),
+ paths.port_dir(action.spec),
+ build_package_options};
+ const auto result = Build::build_package(paths, build_config, status_db);
+ if (result.code != Build::BuildResult::SUCCEEDED)
+ {
+ System::println(System::Color::error, Build::create_error_message(result.code, action.spec));
+ return result.code;
+ }
+ System::println("Building package %s... done", display_name);
+
+ const BinaryParagraph bpgh =
+ Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
+ System::println("Installing package %s... ", display_name);
+ install_package(paths, bpgh, &status_db);
+ System::println(System::Color::success, "Installing package %s... done", display_name);
+ return BuildResult::SUCCEEDED;
+ }
+
+ if (plan_type == InstallPlanType::INSTALL)
+ {
+ if (use_head_version && is_user_requested)
+ {
+ System::println(
+ System::Color::warning, "Package %s is already built -- not building from HEAD", display_name);
+ }
+ System::println("Installing package %s... ", display_name);
+ install_package(paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
+ System::println(System::Color::success, "Installing package %s... done", display_name);
+ return BuildResult::SUCCEEDED;
+ }
+
+ Checks::unreachable(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";
@@ -315,82 +386,18 @@ namespace vcpkg::Commands::Install
Checks::exit_success(VCPKG_LINE_INFO);
}
+ const Build::BuildPackageOptions install_plan_options = {Build::to_use_head_version(use_head_version),
+ Build::to_allow_downloads(!no_downloads)};
+
// execute the plan
for (const InstallPlanAction& action : install_plan)
{
- const std::string display_name = action.spec.to_string();
-
- try
- {
- switch (action.plan_type)
- {
- case InstallPlanType::ALREADY_INSTALLED:
- if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
- {
- System::println(System::Color::warning,
- "Package %s is already installed -- not building from HEAD",
- display_name);
- }
- else
- {
- System::println(System::Color::success, "Package %s is already installed", display_name);
- }
- break;
- case InstallPlanType::BUILD_AND_INSTALL:
- {
- Build::BuildPackageConfig build_config{
- action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
- action.spec.triplet(),
- paths.port_dir(action.spec),
- };
-
- build_config.use_head_version =
- use_head_version && action.request_type == RequestType::USER_REQUESTED;
- build_config.no_downloads = no_downloads;
-
- if (build_config.use_head_version)
- System::println("Building package %s from HEAD... ", display_name);
- else
- System::println("Building package %s... ", display_name);
-
- const auto result = Build::build_package(paths, build_config, status_db);
- if (result.code != Build::BuildResult::SUCCEEDED)
+ const BuildResult result = perform_install_plan_action(paths, action, install_plan_options, status_db);
+ if (result != BuildResult::SUCCEEDED)
{
- System::println(System::Color::error,
- Build::create_error_message(result.code, action.spec));
System::println(Build::create_user_troubleshooting_message(action.spec));
Checks::exit_fail(VCPKG_LINE_INFO);
}
- System::println("Building package %s... done", display_name);
-
- const BinaryParagraph bpgh =
- Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name);
- install_package(paths, bpgh, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- }
- case InstallPlanType::INSTALL:
- if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
- {
- System::println(System::Color::warning,
- "Package %s is already built -- not building from HEAD",
- display_name);
- }
- System::println("Installing package %s... ", display_name);
- install_package(
- paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- case InstallPlanType::UNKNOWN:
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
- catch (const std::exception& e)
- {
- System::println(System::Color::error, "Error: Could not install package %s: %s", action.spec, e.what());
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
}
Checks::exit_success(VCPKG_LINE_INFO);

MODIFY
src/vcpkg_Build.cpp
src/vcpkg_Build.cpp
@@ -132,16 +132,16 @@ namespace vcpkg::Build
const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset);
const auto cmd_set_environment = make_build_env_cmd(pre_build_info, toolset);
- const std::wstring cmd_launch_cmake =
- make_cmake_cmd(cmake_exe_path,
+ const std::wstring cmd_launch_cmake = make_cmake_cmd(
+ cmake_exe_path,
ports_cmake_script_path,
{{L"CMD", L"BUILD"},
{L"PORT", config.src.name},
{L"CURRENT_PORT_DIR", config.port_dir / "/."},
{L"TARGET_TRIPLET", triplet.canonical_name()},
{L"VCPKG_PLATFORM_TOOLSET", toolset.version},
- {L"VCPKG_USE_HEAD_VERSION", config.use_head_version ? L"1" : L"0"},
- {L"_VCPKG_NO_DOWNLOADS", config.no_downloads ? L"1" : L"0"},
+ {L"VCPKG_USE_HEAD_VERSION", to_bool(config.build_package_options.use_head_version) ? L"1" : L"0"},
+ {L"_VCPKG_NO_DOWNLOADS", !to_bool(config.build_package_options.allow_downloads) ? L"1" : L"0"},
{L"GIT", git_exe_path}});
const std::wstring command = Strings::wformat(LR"(%s && %s)", cmd_set_environment, cmd_launch_cmake);

Install continue