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-08-20 20:06:21 -07:00
|
|
|
struct FeatureNodeEdges
|
|
|
|
{
|
|
|
|
std::vector<FeatureSpec> remove_edges;
|
|
|
|
std::vector<FeatureSpec> build_edges;
|
|
|
|
bool plus = false;
|
|
|
|
};
|
|
|
|
|
2017-08-22 15:14:15 -07:00
|
|
|
struct Cluster : Util::MoveOnlyBase
|
2017-08-20 20:06:21 -07:00
|
|
|
{
|
|
|
|
std::vector<StatusParagraph*> status_paragraphs;
|
|
|
|
Optional<const SourceControlFile*> source_control_file;
|
|
|
|
PackageSpec spec;
|
|
|
|
std::unordered_map<std::string, FeatureNodeEdges> edges;
|
|
|
|
std::unordered_set<std::string> to_install_features;
|
|
|
|
std::unordered_set<std::string> original_features;
|
|
|
|
bool will_remove = false;
|
|
|
|
bool transient_uninstalled = true;
|
2017-08-21 20:06:47 -07:00
|
|
|
RequestType request_type = RequestType::AUTO_SELECTED;
|
2017-08-20 20:06:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ClusterPtr
|
|
|
|
{
|
|
|
|
Cluster* ptr;
|
2017-08-21 20:06:47 -07:00
|
|
|
|
|
|
|
Cluster* operator->() { return ptr; }
|
2017-08-20 20:06:21 -07:00
|
|
|
};
|
2017-08-20 19:36:43 -07:00
|
|
|
|
2017-07-19 14:29:28 -07:00
|
|
|
bool operator==(const ClusterPtr& l, const ClusterPtr& r) { return l.ptr == r.ptr; }
|
2017-08-20 20:06:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct std::hash<vcpkg::Dependencies::ClusterPtr>
|
|
|
|
{
|
|
|
|
size_t operator()(const vcpkg::Dependencies::ClusterPtr& value) const
|
|
|
|
{
|
|
|
|
return std::hash<vcpkg::PackageSpec>()(value.ptr->spec);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace vcpkg::Dependencies
|
|
|
|
{
|
|
|
|
struct GraphPlan
|
|
|
|
{
|
|
|
|
Graphs::Graph<ClusterPtr> remove_graph;
|
|
|
|
Graphs::Graph<ClusterPtr> install_graph;
|
|
|
|
};
|
|
|
|
|
2017-08-22 15:14:15 -07:00
|
|
|
struct ClusterGraph : Util::MoveOnlyBase
|
2017-08-20 20:06:21 -07:00
|
|
|
{
|
2017-08-21 17:16:14 -07:00
|
|
|
explicit ClusterGraph(std::unordered_map<std::string, const SourceControlFile*>&& ports)
|
|
|
|
: m_ports(std::move(ports))
|
|
|
|
{
|
|
|
|
}
|
2017-08-20 20:06:21 -07:00
|
|
|
|
|
|
|
Cluster& get(const PackageSpec& spec)
|
|
|
|
{
|
|
|
|
auto it = m_graph.find(spec);
|
2017-08-21 17:16:14 -07:00
|
|
|
if (it == m_graph.end())
|
|
|
|
{
|
|
|
|
// Load on-demand from m_ports
|
|
|
|
auto it_ports = m_ports.find(spec.name());
|
|
|
|
if (it_ports != m_ports.end())
|
|
|
|
{
|
|
|
|
auto& clust = m_graph[spec];
|
|
|
|
clust.spec = spec;
|
|
|
|
cluster_from_scf(*it_ports->second, clust);
|
|
|
|
return clust;
|
|
|
|
}
|
|
|
|
return m_graph[spec];
|
|
|
|
}
|
|
|
|
return it->second;
|
2017-08-20 20:06:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-21 17:16:14 -07:00
|
|
|
void cluster_from_scf(const SourceControlFile& scf, Cluster& out_cluster)
|
|
|
|
{
|
|
|
|
FeatureNodeEdges core_dependencies;
|
|
|
|
core_dependencies.build_edges =
|
|
|
|
filter_dependencies_to_specs(scf.core_paragraph->depends, out_cluster.spec.triplet());
|
|
|
|
out_cluster.edges.emplace("core", std::move(core_dependencies));
|
|
|
|
|
|
|
|
for (const auto& feature : scf.feature_paragraphs)
|
|
|
|
{
|
|
|
|
FeatureNodeEdges added_edges;
|
|
|
|
added_edges.build_edges = filter_dependencies_to_specs(feature->depends, out_cluster.spec.triplet());
|
|
|
|
out_cluster.edges.emplace(feature->name, std::move(added_edges));
|
|
|
|
}
|
|
|
|
out_cluster.source_control_file = &scf;
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:06:21 -07:00
|
|
|
std::unordered_map<PackageSpec, Cluster> m_graph;
|
2017-08-21 17:16:14 -07:00
|
|
|
std::unordered_map<std::string, const SourceControlFile*> m_ports;
|
2017-08-20 20:06:21 -07:00
|
|
|
};
|
2017-07-19 14:29:28 -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-08-21 20:06:47 -07:00
|
|
|
InstallPlanAction::InstallPlanAction() : plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
|
2017-04-11 19:37:38 -07:00
|
|
|
|
2017-07-12 17:40:41 -07:00
|
|
|
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
|
|
|
const SourceControlFile& any_paragraph,
|
2017-07-19 14:19:11 -07:00
|
|
|
const std::unordered_set<std::string>& features,
|
2017-07-12 17:40:41 -07:00
|
|
|
const RequestType& request_type)
|
2017-08-21 20:06:47 -07:00
|
|
|
: spec(spec), plan_type(InstallPlanType::BUILD_AND_INSTALL), request_type(request_type), feature_list(features)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
|
|
|
this->any_paragraph.source_control_file = &any_paragraph;
|
2017-08-21 20:06:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
|
|
|
const std::unordered_set<std::string>& features,
|
|
|
|
const RequestType& request_type)
|
|
|
|
: spec(spec), plan_type(InstallPlanType::ALREADY_INSTALLED), request_type(request_type), feature_list(features)
|
|
|
|
{
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
|
|
|
const AnyParagraph& any_paragraph,
|
|
|
|
const RequestType& request_type)
|
2017-08-21 20:06:47 -07:00
|
|
|
: spec(spec), request_type(request_type), any_paragraph(any_paragraph)
|
2017-04-11 19:37:38 -07:00
|
|
|
{
|
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;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = any_paragraph.binary_paragraph.get())
|
|
|
|
{
|
|
|
|
this->plan_type = InstallPlanType::INSTALL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto p = any_paragraph.source_paragraph.get())
|
|
|
|
{
|
|
|
|
this->plan_type = InstallPlanType::BUILD_AND_INSTALL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->plan_type = InstallPlanType::UNKNOWN;
|
|
|
|
}
|
2017-04-07 13:03:11 -07:00
|
|
|
|
2017-07-25 21:29:31 -07:00
|
|
|
std::string InstallPlanAction::displayname() const
|
|
|
|
{
|
|
|
|
if (this->feature_list.empty())
|
|
|
|
{
|
|
|
|
return this->spec.to_string();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string features;
|
|
|
|
for (auto&& feature : this->feature_list)
|
|
|
|
{
|
|
|
|
features += feature + ",";
|
|
|
|
}
|
|
|
|
features.pop_back();
|
|
|
|
|
|
|
|
return this->spec.name() + "[" + features + "]:" + this->spec.triplet().to_string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-08-21 17:16:14 -07:00
|
|
|
MapPortFile::MapPortFile(const std::unordered_map<std::string, SourceControlFile>& map) : ports(map) {}
|
2017-07-19 14:19:11 -07:00
|
|
|
|
2017-08-21 17:16:14 -07:00
|
|
|
const SourceControlFile& MapPortFile::get_control_file(const std::string& spec) const
|
2017-06-26 13:48:04 -07:00
|
|
|
{
|
|
|
|
auto scf = ports.find(spec);
|
|
|
|
if (scf == ports.end())
|
|
|
|
{
|
|
|
|
Checks::exit_fail(VCPKG_LINE_INFO);
|
|
|
|
}
|
2017-06-27 14:52:26 -07:00
|
|
|
return scf->second;
|
2017-06-26 13:48:04 -07:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:19:11 -07:00
|
|
|
PathsPortFile::PathsPortFile(const VcpkgPaths& paths) : ports(paths) {}
|
|
|
|
|
2017-08-21 17:16:14 -07:00
|
|
|
const SourceControlFile& PathsPortFile::get_control_file(const std::string& spec) const
|
2017-06-26 13:48:04 -07:00
|
|
|
{
|
2017-08-21 17:16:14 -07:00
|
|
|
auto cache_it = cache.find(spec);
|
2017-06-26 13:48:04 -07:00
|
|
|
if (cache_it != cache.end())
|
|
|
|
{
|
2017-06-27 14:52:26 -07:00
|
|
|
return cache_it->second;
|
2017-06-26 13:48:04 -07:00
|
|
|
}
|
2017-06-26 15:45:31 -07:00
|
|
|
Parse::ParseExpected<SourceControlFile> source_control_file =
|
2017-06-26 13:48:04 -07:00
|
|
|
Paragraphs::try_load_port(ports.get_filesystem(), ports.port_dir(spec));
|
|
|
|
|
|
|
|
if (auto scf = source_control_file.get())
|
|
|
|
{
|
2017-06-26 15:45:31 -07:00
|
|
|
auto it = cache.emplace(spec, std::move(*scf->get()));
|
2017-06-27 14:52:26 -07:00
|
|
|
return it.first->second;
|
2017-06-26 13:48:04 -07:00
|
|
|
}
|
2017-06-27 14:52:26 -07:00
|
|
|
print_error_message(source_control_file.error());
|
2017-06-26 13:48:04 -07:00
|
|
|
Checks::exit_fail(VCPKG_LINE_INFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<InstallPlanAction> create_install_plan(const PortFileProvider& port_file_provider,
|
2017-04-27 18:08:52 -07:00
|
|
|
const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db)
|
2017-06-26 13:48:04 -07:00
|
|
|
{
|
|
|
|
struct InstallAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, InstallPlanAction>
|
|
|
|
{
|
|
|
|
const PortFileProvider& port_file_provider;
|
|
|
|
const StatusParagraphs& status_db;
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set;
|
|
|
|
|
|
|
|
InstallAdjacencyProvider(const PortFileProvider& port_file_provider,
|
|
|
|
const StatusParagraphs& s,
|
|
|
|
const std::unordered_set<PackageSpec>& specs_as_set)
|
|
|
|
: port_file_provider(port_file_provider), status_db(s), specs_as_set(specs_as_set)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<PackageSpec> adjacency_list(const InstallPlanAction& plan) const override
|
|
|
|
{
|
|
|
|
if (plan.any_paragraph.status_paragraph.get()) return std::vector<PackageSpec>{};
|
|
|
|
return plan.any_paragraph.dependencies(plan.spec.triplet());
|
|
|
|
}
|
|
|
|
|
|
|
|
InstallPlanAction load_vertex_data(const PackageSpec& spec) const override
|
|
|
|
{
|
|
|
|
const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end()
|
|
|
|
? RequestType::USER_REQUESTED
|
|
|
|
: RequestType::AUTO_SELECTED;
|
|
|
|
auto it = status_db.find_installed(spec);
|
|
|
|
if (it != status_db.end()) return InstallPlanAction{spec, {*it->get(), nullopt, nullopt}, request_type};
|
|
|
|
return InstallPlanAction{
|
2017-08-21 17:16:14 -07:00
|
|
|
spec,
|
|
|
|
{nullopt, nullopt, *port_file_provider.get_control_file(spec.name()).core_paragraph},
|
|
|
|
request_type};
|
2017-06-26 13:48:04 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
|
|
|
|
std::vector<InstallPlanAction> toposort =
|
|
|
|
Graphs::topological_sort(specs, InstallAdjacencyProvider{port_file_provider, status_db, specs_as_set});
|
|
|
|
Util::erase_remove_if(toposort, [](const InstallPlanAction& plan) {
|
|
|
|
return plan.request_type == RequestType::AUTO_SELECTED &&
|
|
|
|
plan.plan_type == InstallPlanType::ALREADY_INSTALLED;
|
|
|
|
});
|
|
|
|
|
|
|
|
return toposort;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-07-25 21:29:31 -07:00
|
|
|
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};
|
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-07-12 17:40:41 -07:00
|
|
|
|
2017-08-21 21:08:43 -07:00
|
|
|
enum class MarkPlusResult
|
|
|
|
{
|
|
|
|
FEATURE_NOT_FOUND,
|
|
|
|
SUCCESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
MarkPlusResult mark_plus(const std::string& feature,
|
|
|
|
Cluster& cluster,
|
|
|
|
ClusterGraph& pkg_to_cluster,
|
|
|
|
GraphPlan& graph_plan);
|
2017-08-20 20:06:21 -07:00
|
|
|
void mark_minus(Cluster& cluster, ClusterGraph& pkg_to_cluster, GraphPlan& graph_plan);
|
2017-08-20 19:36:43 -07:00
|
|
|
|
2017-08-21 21:08:43 -07:00
|
|
|
MarkPlusResult mark_plus(const std::string& feature, Cluster& cluster, ClusterGraph& graph, GraphPlan& graph_plan)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
if (feature == "")
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
// Indicates that core was not specified in the reference
|
|
|
|
return mark_plus("core", cluster, graph, graph_plan);
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
2017-08-21 21:08:43 -07:00
|
|
|
|
2017-08-20 19:36:43 -07:00
|
|
|
auto it = cluster.edges.find(feature);
|
2017-08-21 21:08:43 -07:00
|
|
|
if (it == cluster.edges.end()) return MarkPlusResult::FEATURE_NOT_FOUND;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-21 21:08:43 -07:00
|
|
|
if (cluster.edges[feature].plus) return MarkPlusResult::SUCCESS;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-20 19:36:43 -07:00
|
|
|
if (cluster.original_features.find(feature) == cluster.original_features.end())
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-07-19 14:19:11 -07:00
|
|
|
cluster.transient_uninstalled = true;
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:19:11 -07:00
|
|
|
if (!cluster.transient_uninstalled)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 21:08:43 -07:00
|
|
|
return MarkPlusResult::SUCCESS;
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
2017-08-20 19:36:43 -07:00
|
|
|
cluster.edges[feature].plus = true;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-07-19 14:19:11 -07:00
|
|
|
if (!cluster.original_features.empty())
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
mark_minus(cluster, graph, graph_plan);
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:29:28 -07:00
|
|
|
graph_plan.install_graph.add_vertex({&cluster});
|
2017-07-19 14:19:11 -07:00
|
|
|
auto& tracked = cluster.to_install_features;
|
2017-08-20 19:36:43 -07:00
|
|
|
tracked.insert(feature);
|
|
|
|
|
|
|
|
if (feature != "core")
|
|
|
|
{
|
|
|
|
// All features implicitly depend on core
|
2017-08-21 21:08:43 -07:00
|
|
|
auto res = mark_plus("core", cluster, graph, graph_plan);
|
|
|
|
|
|
|
|
// Should be impossible for "core" to not exist
|
|
|
|
Checks::check_exit(VCPKG_LINE_INFO, res == MarkPlusResult::SUCCESS);
|
2017-08-20 19:36:43 -07:00
|
|
|
}
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-20 19:36:43 -07:00
|
|
|
for (auto&& depend : cluster.edges[feature].build_edges)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
auto& depend_cluster = graph.get(depend.spec());
|
2017-08-21 21:08:43 -07:00
|
|
|
auto res = mark_plus(depend.feature(), depend_cluster, graph, graph_plan);
|
|
|
|
|
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
res == MarkPlusResult::SUCCESS,
|
|
|
|
"Error: Unable to satisfy dependency %s of %s",
|
|
|
|
depend,
|
|
|
|
FeatureSpec(cluster.spec, feature));
|
|
|
|
|
2017-07-12 17:40:41 -07:00
|
|
|
if (&depend_cluster == &cluster) continue;
|
2017-07-19 14:29:28 -07:00
|
|
|
graph_plan.install_graph.add_edge({&cluster}, {&depend_cluster});
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
2017-08-21 21:08:43 -07:00
|
|
|
|
|
|
|
return MarkPlusResult::SUCCESS;
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-08-20 19:36:43 -07:00
|
|
|
void mark_minus(Cluster& cluster, ClusterGraph& graph, GraphPlan& graph_plan)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-07-19 14:19:11 -07:00
|
|
|
if (cluster.will_remove) return;
|
|
|
|
cluster.will_remove = true;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-07-19 14:29:28 -07:00
|
|
|
graph_plan.remove_graph.add_vertex({&cluster});
|
2017-07-12 17:40:41 -07:00
|
|
|
for (auto&& pair : cluster.edges)
|
|
|
|
{
|
2017-07-19 14:19:11 -07:00
|
|
|
auto& remove_edges_edges = pair.second.remove_edges;
|
|
|
|
for (auto&& depend : remove_edges_edges)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
auto& depend_cluster = graph.get(depend.spec());
|
2017-07-19 14:29:28 -07:00
|
|
|
graph_plan.remove_graph.add_edge({&cluster}, {&depend_cluster});
|
2017-08-20 19:36:43 -07:00
|
|
|
mark_minus(depend_cluster, graph, graph_plan);
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-20 19:36:43 -07:00
|
|
|
|
|
|
|
cluster.transient_uninstalled = true;
|
2017-07-19 14:19:11 -07:00
|
|
|
for (auto&& original_feature : cluster.original_features)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 21:08:43 -07:00
|
|
|
auto res = mark_plus(original_feature, cluster, graph, graph_plan);
|
|
|
|
if (res != MarkPlusResult::SUCCESS)
|
|
|
|
{
|
|
|
|
System::println(System::Color::warning,
|
|
|
|
"Warning: could not reinstall feature %s",
|
|
|
|
FeatureSpec{cluster.spec, original_feature});
|
|
|
|
}
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 21:29:31 -07:00
|
|
|
|
2017-08-21 17:16:14 -07:00
|
|
|
static ClusterGraph create_feature_install_graph(const std::unordered_map<std::string, SourceControlFile>& map,
|
2017-08-20 19:36:43 -07:00
|
|
|
const StatusParagraphs& status_db)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 17:16:14 -07:00
|
|
|
std::unordered_map<std::string, const SourceControlFile*> ptr_map;
|
|
|
|
for (auto&& p : map)
|
|
|
|
ptr_map.emplace(p.first, &p.second);
|
|
|
|
ClusterGraph graph(std::move(ptr_map));
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-20 20:06:21 -07:00
|
|
|
auto installed_ports = get_installed_ports(status_db);
|
|
|
|
|
|
|
|
for (auto&& status_paragraph : installed_ports)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 17:16:14 -07:00
|
|
|
Cluster& cluster = graph.get(status_paragraph->package.spec);
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-07-19 14:19:11 -07:00
|
|
|
cluster.transient_uninstalled = false;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-20 20:06:21 -07:00
|
|
|
cluster.status_paragraphs.emplace_back(status_paragraph);
|
|
|
|
|
|
|
|
auto& status_paragraph_feature = status_paragraph->package.feature;
|
|
|
|
// In this case, empty string indicates the "core" paragraph for a package.
|
2017-07-12 17:40:41 -07:00
|
|
|
if (status_paragraph_feature == "")
|
|
|
|
{
|
2017-07-19 14:19:11 -07:00
|
|
|
cluster.original_features.insert("core");
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-19 14:19:11 -07:00
|
|
|
cluster.original_features.insert(status_paragraph_feature);
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-20 20:06:21 -07:00
|
|
|
|
|
|
|
for (auto&& status_paragraph : installed_ports)
|
|
|
|
{
|
|
|
|
auto& spec = status_paragraph->package.spec;
|
|
|
|
auto& status_paragraph_feature = status_paragraph->package.feature;
|
|
|
|
auto reverse_edges = FeatureSpec::from_strings_and_triplet(status_paragraph->package.depends,
|
|
|
|
status_paragraph->package.spec.triplet());
|
|
|
|
|
|
|
|
for (auto&& dependency : reverse_edges)
|
|
|
|
{
|
2017-08-21 17:16:14 -07:00
|
|
|
auto& dep_cluster = graph.get(dependency.spec());
|
2017-08-20 20:06:21 -07:00
|
|
|
|
|
|
|
auto depends_name = dependency.feature();
|
|
|
|
if (depends_name == "") depends_name = "core";
|
|
|
|
|
2017-08-21 17:16:14 -07:00
|
|
|
auto& target_node = dep_cluster.edges[depends_name];
|
2017-08-20 20:06:21 -07:00
|
|
|
target_node.remove_edges.emplace_back(FeatureSpec{spec, status_paragraph_feature});
|
|
|
|
}
|
|
|
|
}
|
2017-08-21 17:16:14 -07:00
|
|
|
return graph;
|
2017-08-20 19:36:43 -07:00
|
|
|
}
|
|
|
|
|
2017-08-21 17:16:14 -07:00
|
|
|
std::vector<AnyAction> create_feature_install_plan(const std::unordered_map<std::string, SourceControlFile>& map,
|
2017-08-20 19:36:43 -07:00
|
|
|
const std::vector<FeatureSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db)
|
|
|
|
{
|
|
|
|
ClusterGraph graph = create_feature_install_graph(map, status_db);
|
2017-07-12 17:40:41 -07:00
|
|
|
|
|
|
|
GraphPlan graph_plan;
|
|
|
|
for (auto&& spec : specs)
|
|
|
|
{
|
2017-08-20 19:36:43 -07:00
|
|
|
Cluster& spec_cluster = graph.get(spec.spec());
|
2017-08-21 20:06:47 -07:00
|
|
|
spec_cluster.request_type = RequestType::USER_REQUESTED;
|
2017-08-21 21:08:43 -07:00
|
|
|
auto res = mark_plus(spec.feature(), spec_cluster, graph, graph_plan);
|
|
|
|
|
|
|
|
Checks::check_exit(
|
|
|
|
VCPKG_LINE_INFO, res == MarkPlusResult::SUCCESS, "Error: Unable to locate feature %s", spec);
|
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
graph_plan.install_graph.add_vertex(ClusterPtr{&spec_cluster});
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:29:28 -07:00
|
|
|
Graphs::GraphAdjacencyProvider<ClusterPtr> adjacency_remove_graph(graph_plan.remove_graph.adjacency_list());
|
2017-07-12 17:40:41 -07:00
|
|
|
auto remove_vertex_list = graph_plan.remove_graph.vertex_list();
|
|
|
|
auto remove_toposort = Graphs::topological_sort(remove_vertex_list, adjacency_remove_graph);
|
|
|
|
|
2017-07-19 14:29:28 -07:00
|
|
|
Graphs::GraphAdjacencyProvider<ClusterPtr> adjacency_install_graph(graph_plan.install_graph.adjacency_list());
|
2017-07-12 17:40:41 -07:00
|
|
|
auto insert_vertex_list = graph_plan.install_graph.vertex_list();
|
|
|
|
auto insert_toposort = Graphs::topological_sort(insert_vertex_list, adjacency_install_graph);
|
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
std::vector<AnyAction> plan;
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
for (auto&& p_cluster : remove_toposort)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 20:06:47 -07:00
|
|
|
auto scf = *p_cluster->source_control_file.get();
|
|
|
|
auto spec = PackageSpec::from_name_and_triplet(scf->core_paragraph->name, p_cluster->spec.triplet())
|
2017-08-21 17:16:14 -07:00
|
|
|
.value_or_exit(VCPKG_LINE_INFO);
|
2017-08-21 20:06:47 -07:00
|
|
|
plan.emplace_back(RemovePlanAction{
|
2017-08-21 17:16:14 -07:00
|
|
|
std::move(spec),
|
2017-07-19 14:29:28 -07:00
|
|
|
RemovePlanType::REMOVE,
|
2017-08-21 20:06:47 -07:00
|
|
|
p_cluster->request_type,
|
2017-08-21 17:16:14 -07:00
|
|
|
});
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
for (auto&& p_cluster : insert_toposort)
|
2017-07-12 17:40:41 -07:00
|
|
|
{
|
2017-08-21 20:06:47 -07:00
|
|
|
if (p_cluster->transient_uninstalled)
|
|
|
|
{
|
|
|
|
// If it will be transiently uninstalled, we need to issue a full installation command
|
|
|
|
auto pscf = p_cluster->source_control_file.value_or_exit(VCPKG_LINE_INFO);
|
|
|
|
Checks::check_exit(VCPKG_LINE_INFO, pscf != nullptr);
|
|
|
|
plan.emplace_back(InstallPlanAction{
|
|
|
|
p_cluster->spec,
|
|
|
|
*pscf,
|
|
|
|
p_cluster->to_install_features,
|
|
|
|
p_cluster->request_type,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the package isn't transitively installed, still include it if the user explicitly requested it
|
|
|
|
if (p_cluster->request_type != RequestType::USER_REQUESTED) continue;
|
|
|
|
plan.emplace_back(InstallPlanAction{
|
|
|
|
p_cluster->spec,
|
|
|
|
p_cluster->original_features,
|
|
|
|
p_cluster->request_type,
|
|
|
|
});
|
|
|
|
}
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
return plan;
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|
2017-01-05 14:14:11 -08:00
|
|
|
}
|