2017-01-27 12:49:09 -08:00
|
|
|
#include "pch.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
|
2017-04-03 14:45:00 -07:00
|
|
|
#include "PackageSpec.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
#include "Paragraphs.h"
|
2016-09-22 23:28:50 -07:00
|
|
|
#include "StatusParagraphs.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
#include "VcpkgPaths.h"
|
|
|
|
#include "vcpkg_Dependencies.h"
|
2016-11-07 16:38:49 -08:00
|
|
|
#include "vcpkg_Files.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
#include "vcpkg_Graphs.h"
|
2017-04-11 19:37:38 -07:00
|
|
|
#include "vcpkg_Util.h"
|
2017-04-12 18:55:37 -07:00
|
|
|
#include "vcpkglib.h"
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-01-05 14:14:11 -08:00
|
|
|
namespace vcpkg::Dependencies
|
2016-09-22 23:28:50 -07:00
|
|
|
{
|
2017-04-12 21:28:49 -07:00
|
|
|
std::vector<PackageSpec> AnyParagraph::dependencies(const Triplet& triplet) const
|
2017-04-11 19:37:38 -07:00
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
auto to_package_specs = [&](const std::vector<std::string>& dependencies_as_string) {
|
|
|
|
return Util::fmap(dependencies_as_string, [&](const std::string s) {
|
|
|
|
return PackageSpec::from_name_and_triplet(s, triplet).value_or_exit(VCPKG_LINE_INFO);
|
|
|
|
});
|
|
|
|
};
|
2017-04-11 19:37:38 -07:00
|
|
|
|
|
|
|
if (auto p = this->status_paragraph.get())
|
|
|
|
{
|
|
|
|
return to_package_specs(p->package.depends);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = this->binary_paragraph.get())
|
|
|
|
{
|
|
|
|
return to_package_specs(p->depends);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = this->source_paragraph.get())
|
|
|
|
{
|
2017-04-12 21:28:49 -07:00
|
|
|
return to_package_specs(filter_dependencies(p->depends, triplet));
|
2017-04-11 19:37:38 -07:00
|
|
|
}
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
Checks::exit_with_message(VCPKG_LINE_INFO,
|
|
|
|
"Cannot get dependencies because there was none of: source/binary/status paragraphs");
|
2017-04-11 19:37:38 -07:00
|
|
|
}
|
|
|
|
|
2017-04-06 18:57:17 -07:00
|
|
|
std::string to_output_string(RequestType request_type, const CStringView s)
|
|
|
|
{
|
|
|
|
switch (request_type)
|
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
case RequestType::AUTO_SELECTED: return Strings::format(" * %s", s);
|
|
|
|
case RequestType::USER_REQUESTED: return Strings::format(" %s", s);
|
|
|
|
default: Checks::unreachable(VCPKG_LINE_INFO);
|
2017-04-06 18:57:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
InstallPlanAction::InstallPlanAction()
|
|
|
|
: spec(), any_paragraph(), plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN)
|
|
|
|
{
|
|
|
|
}
|
2017-04-11 19:37:38 -07:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
|
|
|
const AnyParagraph& any_paragraph,
|
|
|
|
const RequestType& request_type)
|
|
|
|
: InstallPlanAction()
|
2017-04-11 19:37:38 -07:00
|
|
|
{
|
2017-04-12 21:28:49 -07:00
|
|
|
this->spec = spec;
|
2017-04-11 19:37:38 -07:00
|
|
|
this->request_type = request_type;
|
2017-04-12 21:28:49 -07:00
|
|
|
if (auto p = any_paragraph.status_paragraph.get())
|
2017-04-11 19:37:38 -07:00
|
|
|
{
|
|
|
|
this->plan_type = InstallPlanType::ALREADY_INSTALLED;
|
2017-04-12 21:28:49 -07:00
|
|
|
this->any_paragraph.status_paragraph = *p;
|
2017-04-11 19:37:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = any_paragraph.binary_paragraph.get())
|
|
|
|
{
|
|
|
|
this->plan_type = InstallPlanType::INSTALL;
|
2017-04-12 21:28:49 -07:00
|
|
|
this->any_paragraph.binary_paragraph = *p;
|
2017-04-11 19:37:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = any_paragraph.source_paragraph.get())
|
|
|
|
{
|
|
|
|
this->plan_type = InstallPlanType::BUILD_AND_INSTALL;
|
2017-04-12 21:28:49 -07:00
|
|
|
this->any_paragraph.source_paragraph = *p;
|
2017-04-11 19:37:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->plan_type = InstallPlanType::UNKNOWN;
|
|
|
|
}
|
2017-04-07 13:03:11 -07:00
|
|
|
|
2017-04-12 21:28:49 -07:00
|
|
|
bool InstallPlanAction::compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right)
|
2017-04-07 13:02:50 -07:00
|
|
|
{
|
|
|
|
return left->spec.name() < right->spec.name();
|
|
|
|
}
|
2017-01-30 17:52:53 -08:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
RemovePlanAction::RemovePlanAction() : plan_type(RemovePlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
|
2017-01-30 17:52:53 -08:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
RemovePlanAction::RemovePlanAction(const PackageSpec& spec,
|
|
|
|
const RemovePlanType& plan_type,
|
|
|
|
const RequestType& request_type)
|
|
|
|
: spec(spec), plan_type(plan_type), request_type(request_type)
|
|
|
|
{
|
|
|
|
}
|
2017-01-30 17:52:53 -08:00
|
|
|
|
2017-04-10 12:57:49 -07:00
|
|
|
bool ExportPlanAction::compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right)
|
|
|
|
{
|
|
|
|
return left->spec.name() < right->spec.name();
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
ExportPlanAction::ExportPlanAction()
|
|
|
|
: spec(), any_paragraph(), plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN)
|
|
|
|
{
|
|
|
|
}
|
2017-04-10 12:57:49 -07:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
ExportPlanAction::ExportPlanAction(const PackageSpec& spec,
|
|
|
|
const AnyParagraph& any_paragraph,
|
|
|
|
const RequestType& request_type)
|
|
|
|
: ExportPlanAction()
|
2017-04-10 12:57:49 -07:00
|
|
|
{
|
|
|
|
this->spec = spec;
|
|
|
|
this->request_type = request_type;
|
|
|
|
|
|
|
|
if (auto p = any_paragraph.binary_paragraph.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;
|
|
|
|
}
|
|
|
|
|
2017-04-12 21:37:55 -07:00
|
|
|
bool RemovePlanAction::compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right)
|
2017-04-06 17:37:19 -07:00
|
|
|
{
|
|
|
|
return left->spec.name() < right->spec.name();
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
std::vector<InstallPlanAction> create_install_plan(const VcpkgPaths& paths,
|
|
|
|
const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db)
|
2016-11-07 17:05:32 -08:00
|
|
|
{
|
2017-04-12 21:28:49 -07:00
|
|
|
struct InstallAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, InstallPlanAction>
|
2016-09-22 23:28:50 -07:00
|
|
|
{
|
2017-04-11 19:37:38 -07:00
|
|
|
const VcpkgPaths& paths;
|
|
|
|
const StatusParagraphs& status_db;
|
2017-04-12 21:28:49 -07:00
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set;
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
InstallAdjacencyProvider(const VcpkgPaths& p,
|
|
|
|
const StatusParagraphs& s,
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set)
|
|
|
|
: paths(p), status_db(s), specs_as_set(specs_as_set)
|
|
|
|
{
|
|
|
|
}
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-04-13 16:02:10 -07:00
|
|
|
std::vector<PackageSpec> adjacency_list(const InstallPlanAction& plan) const override
|
2016-09-22 23:28:50 -07:00
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
if (plan.any_paragraph.status_paragraph.get()) return std::vector<PackageSpec>{};
|
2017-04-13 16:02:10 -07:00
|
|
|
return plan.any_paragraph.dependencies(plan.spec.triplet());
|
2016-11-15 11:56:46 -08:00
|
|
|
}
|
2016-10-04 15:25:53 -07:00
|
|
|
|
2017-04-12 21:28:49 -07:00
|
|
|
InstallPlanAction load_vertex_data(const PackageSpec& spec) const override
|
2016-11-15 11:56:46 -08:00
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end()
|
|
|
|
? RequestType::USER_REQUESTED
|
|
|
|
: RequestType::AUTO_SELECTED;
|
2017-04-11 19:37:38 -07:00
|
|
|
auto it = status_db.find_installed(spec);
|
2017-04-28 12:55:50 -07:00
|
|
|
if (it != status_db.end()) return InstallPlanAction{spec, {*it->get(), nullopt, nullopt}, request_type};
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-04-11 19:37:38 -07:00
|
|
|
Expected<BinaryParagraph> maybe_bpgh = Paragraphs::try_load_cached_package(paths, spec);
|
|
|
|
if (auto bpgh = maybe_bpgh.get())
|
2017-04-28 12:55:50 -07:00
|
|
|
return InstallPlanAction{spec, {nullopt, *bpgh, nullopt}, request_type};
|
2017-04-11 19:37:38 -07:00
|
|
|
|
2017-06-17 02:39:14 -07:00
|
|
|
auto maybe_scf = Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec));
|
|
|
|
if (auto scf = maybe_scf.get())
|
|
|
|
return InstallPlanAction{spec, {nullopt, nullopt, *scf->get()->core_paragraph}, request_type};
|
2017-04-11 19:37:38 -07:00
|
|
|
|
2017-06-17 02:39:14 -07:00
|
|
|
print_error_message(maybe_scf.error());
|
2017-06-08 00:36:17 -07:00
|
|
|
Checks::exit_fail(VCPKG_LINE_INFO);
|
2017-03-31 09:26:58 -07:00
|
|
|
}
|
2017-04-11 19:37:38 -07:00
|
|
|
};
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-04-12 18:55:37 -07:00
|
|
|
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
|
2017-04-27 18:08:52 -07:00
|
|
|
std::vector<InstallPlanAction> toposort =
|
2017-04-28 12:55:50 -07:00
|
|
|
Graphs::topological_sort(specs, InstallAdjacencyProvider{paths, status_db, specs_as_set});
|
2017-04-27 18:08:52 -07:00
|
|
|
Util::erase_remove_if(toposort, [](const InstallPlanAction& plan) {
|
|
|
|
return plan.request_type == RequestType::AUTO_SELECTED &&
|
|
|
|
plan.plan_type == InstallPlanType::ALREADY_INSTALLED;
|
|
|
|
});
|
2017-04-12 21:41:54 -07:00
|
|
|
|
|
|
|
return toposort;
|
2016-11-07 16:38:49 -08:00
|
|
|
}
|
2017-01-26 17:53:45 -08:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db)
|
2017-04-12 18:55:37 -07:00
|
|
|
{
|
2017-04-12 21:37:55 -07:00
|
|
|
struct RemoveAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, RemovePlanAction>
|
2017-01-26 17:53:45 -08:00
|
|
|
{
|
2017-04-12 18:55:37 -07:00
|
|
|
const StatusParagraphs& status_db;
|
|
|
|
const std::vector<StatusParagraph*>& installed_ports;
|
2017-04-12 21:37:55 -07:00
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set;
|
2017-01-26 17:53:45 -08:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
RemoveAdjacencyProvider(const StatusParagraphs& status_db,
|
|
|
|
const std::vector<StatusParagraph*>& installed_ports,
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set)
|
|
|
|
: status_db(status_db), installed_ports(installed_ports), specs_as_set(specs_as_set)
|
|
|
|
{
|
|
|
|
}
|
2017-01-26 17:53:45 -08:00
|
|
|
|
2017-04-13 16:02:10 -07:00
|
|
|
std::vector<PackageSpec> adjacency_list(const RemovePlanAction& plan) const override
|
2017-01-26 17:53:45 -08:00
|
|
|
{
|
2017-04-13 16:02:10 -07:00
|
|
|
if (plan.plan_type == RemovePlanType::NOT_INSTALLED)
|
2017-04-12 18:55:37 -07:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-04-13 16:02:10 -07:00
|
|
|
const PackageSpec& spec = plan.spec;
|
2017-04-12 18:55:37 -07:00
|
|
|
std::vector<PackageSpec> dependents;
|
|
|
|
for (const StatusParagraph* an_installed_package : installed_ports)
|
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
if (an_installed_package->package.spec.triplet() != spec.triplet()) continue;
|
2017-04-12 18:55:37 -07:00
|
|
|
|
|
|
|
const std::vector<std::string>& deps = an_installed_package->package.depends;
|
2017-04-27 18:08:52 -07:00
|
|
|
if (std::find(deps.begin(), deps.end(), spec.name()) == deps.end()) continue;
|
2017-04-12 18:55:37 -07:00
|
|
|
|
|
|
|
dependents.push_back(an_installed_package->package.spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dependents;
|
2017-01-26 17:53:45 -08:00
|
|
|
}
|
|
|
|
|
2017-04-12 21:37:55 -07:00
|
|
|
RemovePlanAction load_vertex_data(const PackageSpec& spec) const override
|
2017-01-26 17:53:45 -08:00
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end()
|
|
|
|
? RequestType::USER_REQUESTED
|
|
|
|
: RequestType::AUTO_SELECTED;
|
2017-04-12 18:55:37 -07:00
|
|
|
const StatusParagraphs::const_iterator it = status_db.find_installed(spec);
|
|
|
|
if (it == status_db.end())
|
2017-01-26 17:53:45 -08:00
|
|
|
{
|
2017-04-28 12:55:50 -07:00
|
|
|
return RemovePlanAction{spec, RemovePlanType::NOT_INSTALLED, request_type};
|
2017-01-26 17:53:45 -08:00
|
|
|
}
|
2017-04-28 12:55:50 -07:00
|
|
|
return RemovePlanAction{spec, RemovePlanType::REMOVE, request_type};
|
2017-01-26 17:53:45 -08:00
|
|
|
}
|
2017-04-12 18:55:37 -07:00
|
|
|
};
|
2017-01-26 17:53:45 -08:00
|
|
|
|
2017-04-12 18:55:37 -07:00
|
|
|
const std::vector<StatusParagraph*>& installed_ports = get_installed_ports(status_db);
|
|
|
|
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
|
2017-04-28 12:55:50 -07:00
|
|
|
return Graphs::topological_sort(specs, RemoveAdjacencyProvider{status_db, installed_ports, specs_as_set});
|
2017-01-26 17:53:45 -08:00
|
|
|
}
|
2017-04-10 12:57:49 -07:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
std::vector<ExportPlanAction> create_export_plan(const VcpkgPaths& paths,
|
|
|
|
const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db)
|
2017-04-10 12:57:49 -07:00
|
|
|
{
|
|
|
|
struct ExportAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, ExportPlanAction>
|
|
|
|
{
|
|
|
|
const VcpkgPaths& paths;
|
|
|
|
const StatusParagraphs& status_db;
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set;
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
ExportAdjacencyProvider(const VcpkgPaths& p,
|
|
|
|
const StatusParagraphs& s,
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set)
|
|
|
|
: paths(p), status_db(s), specs_as_set(specs_as_set)
|
|
|
|
{
|
|
|
|
}
|
2017-04-10 12:57:49 -07:00
|
|
|
|
|
|
|
std::vector<PackageSpec> adjacency_list(const ExportPlanAction& plan) const override
|
|
|
|
{
|
|
|
|
return plan.any_paragraph.dependencies(plan.spec.triplet());
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportPlanAction load_vertex_data(const PackageSpec& spec) const override
|
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end()
|
|
|
|
? RequestType::USER_REQUESTED
|
|
|
|
: RequestType::AUTO_SELECTED;
|
2017-04-10 12:57:49 -07:00
|
|
|
|
|
|
|
Expected<BinaryParagraph> maybe_bpgh = Paragraphs::try_load_cached_package(paths, spec);
|
|
|
|
if (auto bpgh = maybe_bpgh.get())
|
2017-04-28 12:55:50 -07:00
|
|
|
return ExportPlanAction{spec, {nullopt, *bpgh, nullopt}, request_type};
|
2017-04-10 12:57:49 -07:00
|
|
|
|
2017-06-17 02:39:14 -07:00
|
|
|
auto maybe_scf = Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec));
|
|
|
|
if (auto scf = maybe_scf.get())
|
|
|
|
return ExportPlanAction{spec, {nullopt, nullopt, *scf->get()->core_paragraph}, request_type};
|
2017-06-05 15:58:47 -07:00
|
|
|
else
|
2017-06-17 02:39:14 -07:00
|
|
|
print_error_message(maybe_scf.error());
|
2017-06-05 15:58:47 -07:00
|
|
|
|
2017-04-28 15:51:20 -07:00
|
|
|
Checks::exit_with_message(VCPKG_LINE_INFO, "Could not find package %s", spec);
|
2017-04-10 12:57:49 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
|
2017-04-27 18:08:52 -07:00
|
|
|
std::vector<ExportPlanAction> toposort =
|
2017-04-28 12:55:50 -07:00
|
|
|
Graphs::topological_sort(specs, ExportAdjacencyProvider{paths, status_db, specs_as_set});
|
2017-04-10 12:57:49 -07:00
|
|
|
return toposort;
|
|
|
|
}
|
2017-01-05 14:14:11 -08:00
|
|
|
}
|