[vcpkg] Deduplicate code from feature packages
MODIFY
include/vcpkg_Build.h
include/vcpkg_Build.h
@@ -52,6 +52,7 @@ namespace vcpkg::Build
SUCCEEDED,
BUILD_FAILED,
POST_BUILD_CHECKS_FAILED,
+ FILE_CONFLICTS,
CASCADED_DUE_TO_MISSING_DEPENDENCIES
};

MODIFY
include/vcpkg_Commands.h
include/vcpkg_Commands.h
@@ -55,10 +55,16 @@ namespace vcpkg::Commands
const Build::BuildPackageOptions& install_plan_options,
StatusParagraphs& status_db);
+ enum class InstallResult
+ {
+ FILE_CONFLICTS,
+ SUCCESS,
+ };
+
void install_files_and_write_listfile(Files::Filesystem& fs,
const fs::path& source_dir,
const InstallDir& dirs);
- void install_package(const VcpkgPaths& paths,
+ InstallResult install_package(const VcpkgPaths& paths,
const BinaryControlFile& binary_paragraph,
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
@@ -23,7 +23,7 @@ namespace vcpkg::Dependencies
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
Optional<StatusParagraph> status_paragraph;
- Optional<BinaryParagraph> binary_paragraph;
+ Optional<BinaryControlFile> binary_control_file;
Optional<SourceParagraph> source_paragraph;
Optional<const SourceControlFile*> source_control_file;
};

MODIFY
include/vcpkg_Util.h
include/vcpkg_Util.h
@@ -12,9 +12,7 @@ namespace vcpkg::Util
template<class Cont, class Func, class Out = FmapOut<Cont, Func>>
std::vector<Out> fmap(Cont&& xs, Func&& f)
{
- using O = decltype(f(*begin(xs)));
-
- std::vector<O> ret;
+ std::vector<Out> ret;
ret.reserve(xs.size());
for (auto&& x : xs)
@@ -23,6 +21,21 @@ namespace vcpkg::Util
return ret;
}
+ template<class Cont, class Func>
+ using FmapFlattenOut = std::decay_t<decltype(*begin(std::declval<Func>()(*begin(std::declval<Cont>()))))>;
+
+ template<class Cont, class Func, class Out = FmapFlattenOut<Cont, Func>>
+ std::vector<Out> fmap_flatten(Cont&& xs, Func&& f)
+ {
+ std::vector<Out> ret;
+
+ for (auto&& x : xs)
+ for (auto&& y : f(x))
+ ret.push_back(std::move(y));
+
+ return ret;
+ }
+
template<class Container, class Pred>
void unstable_keep_if(Container& cont, Pred pred)
{

MODIFY
src/commands_export.cpp
src/commands_export.cpp
namespace vcpkg::Commands::Export
{
- using Install::InstallDir;
using Dependencies::ExportPlanAction;
- using Dependencies::RequestType;
using Dependencies::ExportPlanType;
+ using Dependencies::RequestType;
+ using Install::InstallDir;
static std::string create_nuspec_file_contents(const std::string& raw_exported_dir,
const std::string& targets_redirect_path,
@@ -235,10 +235,15 @@ namespace vcpkg::Commands::Export
const auto options = args.check_and_get_optional_command_arguments(
{
- OPTION_DRY_RUN, OPTION_RAW, OPTION_NUGET, OPTION_ZIP, OPTION_7ZIP,
+ OPTION_DRY_RUN,
+ OPTION_RAW,
+ OPTION_NUGET,
+ OPTION_ZIP,
+ OPTION_7ZIP,
},
{
- OPTION_NUGET_ID, OPTION_NUGET_VERSION,
+ OPTION_NUGET_ID,
+ OPTION_NUGET_VERSION,
});
const bool dryRun = options.switches.find(OPTION_DRY_RUN) != options.switches.cend();
const bool raw = options.switches.find(OPTION_RAW) != options.switches.cend();
@@ -323,7 +328,7 @@ namespace vcpkg::Commands::Export
System::println("Exporting package %s... ", display_name);
const BinaryParagraph& binary_paragraph =
- action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO);
+ action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
const InstallDir dirs = InstallDir::from_destination_root(
raw_exported_dir_path / "installed",
action.spec.triplet().to_string(),

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -172,7 +172,7 @@ namespace vcpkg::Commands::Install
return SortedVector<std::string>(std::move(installed_files));
}
- void install_package(const VcpkgPaths& paths, const BinaryControlFile& bcf, StatusParagraphs* status_db)
+ InstallResult install_package(const VcpkgPaths& paths, const BinaryControlFile& bcf, StatusParagraphs* status_db)
{
const fs::path package_dir = paths.package_dir(bcf.core_paragraph.spec);
const Triplet& triplet = bcf.core_paragraph.spec.triplet();
@@ -199,7 +199,7 @@ namespace vcpkg::Commands::Install
System::print("\n ");
System::println(Strings::join("\n ", intersection));
System::println("");
- Checks::exit_fail(VCPKG_LINE_INFO);
+ return InstallResult::FILE_CONFLICTS;
}
StatusParagraph source_paragraph;
@@ -239,6 +239,8 @@ namespace vcpkg::Commands::Install
write_update(paths, feature_paragraph);
status_db->insert(std::make_unique<StatusParagraph>(feature_paragraph));
}
+
+ return InstallResult::SUCCESS;
}
using Build::BuildResult;
@@ -250,6 +252,7 @@ namespace vcpkg::Commands::Install
{
const InstallPlanType& plan_type = action.plan_type;
const std::string display_name = action.spec.to_string();
+ const std::string display_name_with_features = g_feature_packages ? action.displayname() : display_name;
const bool is_user_requested = action.request_type == RequestType::USER_REQUESTED;
const bool use_head_version = to_bool(build_package_options.use_head_version);
@@ -257,76 +260,65 @@ namespace vcpkg::Commands::Install
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 && !g_feature_packages)
+ if (plan_type == InstallPlanType::BUILD_AND_INSTALL)
{
if (use_head_version)
- System::println("Building package %s from HEAD... ", display_name);
+ System::println("Building package %s from HEAD... ", display_name_with_features);
else
- System::println("Building package %s... ", display_name);
+ System::println("Building package %s... ", display_name_with_features);
+ const auto result = [&]() -> Build::ExtendedBuildResult {
+ if (g_feature_packages)
+ {
const Build::BuildPackageConfig build_config{
- action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
+ *action.any_paragraph.source_control_file.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 BinaryControlFile bpgh =
- Paragraphs::try_load_cached_control_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;
+ build_package_options,
+ action.feature_list};
+ return Build::build_package(paths, build_config, status_db);
}
-
- if (plan_type == InstallPlanType::BUILD_AND_INSTALL && g_feature_packages)
- {
- const std::string display_name_feature = action.displayname();
- if (use_head_version)
- System::println("Building package %s from HEAD... ", display_name_feature);
else
- System::println("Building package %s... ", display_name_feature);
-
+ {
const Build::BuildPackageConfig build_config{
- *action.any_paragraph.source_control_file.value_or_exit(VCPKG_LINE_INFO),
+ action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
action.spec.triplet(),
paths.port_dir(action.spec),
- build_package_options,
- action.feature_list};
- const auto result = Build::build_package(paths, build_config, status_db);
+ build_package_options};
+ return 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_feature);
+
+ System::println("Building package %s... done", display_name_with_features);
const BinaryControlFile bcf =
Paragraphs::try_load_cached_control_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name_feature);
- install_package(paths, bcf, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name_feature);
+ System::println("Installing package %s... ", display_name_with_features);
+ auto install_result = install_package(paths, bcf, &status_db);
+ switch (install_result)
+ {
+ case InstallResult::SUCCESS:
+ System::println(System::Color::success, "Installing package %s... done", display_name);
return BuildResult::SUCCEEDED;
+ case InstallResult::FILE_CONFLICTS: return BuildResult::FILE_CONFLICTS;
+ default: Checks::unreachable(VCPKG_LINE_INFO);
+ }
}
- if (plan_type == InstallPlanType::INSTALL && !g_feature_packages)
+ if (plan_type == InstallPlanType::INSTALL)
{
if (use_head_version && is_user_requested)
{
@@ -334,11 +326,16 @@ namespace vcpkg::Commands::Install
System::Color::warning, "Package %s is already built -- not building from HEAD", display_name);
}
System::println("Installing package %s... ", display_name);
- install_package(paths,
- BinaryControlFile{action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO)},
- &status_db);
+ auto install_result = install_package(
+ paths, action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO), &status_db);
+ switch (install_result)
+ {
+ case InstallResult::SUCCESS:
System::println(System::Color::success, "Installing package %s... done", display_name);
return BuildResult::SUCCEEDED;
+ case InstallResult::FILE_CONFLICTS: return BuildResult::FILE_CONFLICTS;
+ default: Checks::unreachable(VCPKG_LINE_INFO);
+ }
}
Checks::unreachable(VCPKG_LINE_INFO);

MODIFY
src/vcpkg_Dependencies.cpp
src/vcpkg_Dependencies.cpp
@@ -119,9 +119,11 @@ namespace vcpkg::Dependencies
return to_package_specs(p->package.depends);
}
- if (auto p = this->binary_paragraph.get())
+ if (auto p = this->binary_control_file.get())
{
- return to_package_specs(p->depends);
+ auto deps = Util::fmap_flatten(p->features, [](const BinaryParagraph& pgh) { return pgh.depends; });
+ deps.insert(deps.end(), p->core_paragraph.depends.begin(), p->core_paragraph.depends.end());
+ return to_package_specs(deps);
}
if (auto p = this->source_paragraph.get())
@@ -164,7 +166,7 @@ namespace vcpkg::Dependencies
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
const AnyParagraph& any_paragraph,
const RequestType& request_type)
- : spec(spec), request_type(request_type), any_paragraph(any_paragraph)
+ : spec(spec), request_type(request_type), plan_type(InstallPlanType::UNKNOWN), any_paragraph(any_paragraph)
{
if (auto p = any_paragraph.status_paragraph.get())
{
@@ -172,7 +174,7 @@ namespace vcpkg::Dependencies
return;
}
- if (auto p = any_paragraph.binary_paragraph.get())
+ if (auto p = any_paragraph.binary_control_file.get())
{
this->plan_type = InstallPlanType::INSTALL;
return;
@@ -183,8 +185,6 @@ namespace vcpkg::Dependencies
this->plan_type = InstallPlanType::BUILD_AND_INSTALL;
return;
}
-
- this->plan_type = InstallPlanType::UNKNOWN;
}
std::string InstallPlanAction::displayname() const
@@ -225,34 +225,24 @@ namespace vcpkg::Dependencies
return left->spec.name() < right->spec.name();
}
- ExportPlanAction::ExportPlanAction()
- : spec(), any_paragraph(), plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN)
- {
- }
+ ExportPlanAction::ExportPlanAction() : plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
ExportPlanAction::ExportPlanAction(const PackageSpec& spec,
const AnyParagraph& any_paragraph,
const RequestType& request_type)
- : ExportPlanAction()
+ : spec(spec), any_paragraph(any_paragraph), plan_type(ExportPlanType::UNKNOWN), request_type(request_type)
{
- this->spec = spec;
- this->request_type = request_type;
-
- if (auto p = any_paragraph.binary_paragraph.get())
+ if (auto p = any_paragraph.binary_control_file.get())
{
this->plan_type = ExportPlanType::ALREADY_BUILT;
- this->any_paragraph.binary_paragraph = *p;
return;
}
if (auto p = any_paragraph.source_paragraph.get())
{
this->plan_type = ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT;
- this->any_paragraph.source_paragraph = *p;
return;
}
-
- this->plan_type = ExportPlanType::UNKNOWN;
}
bool RemovePlanAction::compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right)
@@ -428,7 +418,7 @@ namespace vcpkg::Dependencies
Expected<BinaryControlFile> maybe_bpgh = Paragraphs::try_load_cached_control_package(paths, spec);
if (auto bcf = maybe_bpgh.get())
- return ExportPlanAction{spec, {nullopt, bcf->core_paragraph, nullopt}, request_type};
+ return ExportPlanAction{spec, AnyParagraph{nullopt, std::move(*bcf), nullopt}, request_type};
auto maybe_scf = Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec));
if (auto scf = maybe_scf.get())

[vcpkg] Deduplicate code from feature packages