2016-09-23 14:28:50 +08:00
|
|
|
#pragma once
|
2017-04-04 05:45:00 +08:00
|
|
|
#include "PackageSpec.h"
|
2016-09-23 14:28:50 +08:00
|
|
|
#include "StatusParagraphs.h"
|
2017-04-04 07:29:11 +08:00
|
|
|
#include "VcpkgPaths.h"
|
2017-07-13 08:40:41 +08:00
|
|
|
#include "vcpkg_Graphs.h"
|
2017-01-31 08:14:48 +08:00
|
|
|
#include "vcpkg_optional.h"
|
2017-04-28 08:56:06 +08:00
|
|
|
#include <vector>
|
2016-09-23 14:28:50 +08:00
|
|
|
|
2017-01-06 06:14:11 +08:00
|
|
|
namespace vcpkg::Dependencies
|
2016-09-23 14:28:50 +08:00
|
|
|
{
|
2017-04-04 07:21:46 +08:00
|
|
|
enum class RequestType
|
2017-01-31 05:57:43 +08:00
|
|
|
{
|
2017-01-31 09:52:53 +08:00
|
|
|
UNKNOWN,
|
2017-01-31 05:57:43 +08:00
|
|
|
USER_REQUESTED,
|
|
|
|
AUTO_SELECTED
|
|
|
|
};
|
|
|
|
|
2017-04-07 09:57:17 +08:00
|
|
|
std::string to_output_string(RequestType request_type, const CStringView s);
|
|
|
|
|
2017-04-13 12:37:55 +08:00
|
|
|
struct AnyParagraph
|
|
|
|
{
|
|
|
|
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
|
|
|
|
|
|
|
|
Optional<StatusParagraph> status_paragraph;
|
|
|
|
Optional<BinaryParagraph> binary_paragraph;
|
|
|
|
Optional<SourceParagraph> source_paragraph;
|
2017-07-13 08:40:41 +08:00
|
|
|
Optional<const SourceControlFile*> source_control_file;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ClusterNode
|
|
|
|
{
|
|
|
|
std::vector<StatusParagraph> status_paragraphs;
|
|
|
|
Optional<const SourceControlFile*> source_paragraph;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace vcpkg::Dependencies
|
|
|
|
{
|
|
|
|
struct FeatureSpec
|
|
|
|
{
|
|
|
|
PackageSpec spec;
|
|
|
|
std::string feature_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FeatureNodeEdges
|
|
|
|
{
|
|
|
|
std::vector<FeatureSpec> dotted;
|
|
|
|
std::vector<FeatureSpec> dashed;
|
|
|
|
bool plus = false;
|
|
|
|
};
|
|
|
|
std::vector<FeatureSpec> to_feature_specs(const std::vector<std::string> depends,
|
|
|
|
const std::unordered_map<std::string, PackageSpec> str_to_spec);
|
|
|
|
struct Cluster
|
|
|
|
{
|
|
|
|
ClusterNode cluster_node;
|
|
|
|
std::unordered_map<std::string, FeatureNodeEdges> edges;
|
|
|
|
std::unordered_set<std::string> tracked_nodes;
|
|
|
|
std::unordered_set<std::string> original_nodes;
|
|
|
|
bool minus = false;
|
|
|
|
bool zero = true;
|
|
|
|
Cluster() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Cluster(const Cluster&) = delete;
|
|
|
|
Cluster& operator=(const Cluster&) = delete;
|
2017-04-13 12:37:55 +08:00
|
|
|
};
|
|
|
|
|
2017-04-04 07:22:32 +08:00
|
|
|
enum class InstallPlanType
|
2016-11-16 03:56:46 +08:00
|
|
|
{
|
2017-01-31 09:52:53 +08:00
|
|
|
UNKNOWN,
|
2016-11-16 03:56:46 +08:00
|
|
|
BUILD_AND_INSTALL,
|
|
|
|
INSTALL,
|
|
|
|
ALREADY_INSTALLED
|
|
|
|
};
|
2016-09-23 14:28:50 +08:00
|
|
|
|
2017-04-04 07:22:51 +08:00
|
|
|
struct InstallPlanAction
|
2016-11-16 03:56:46 +08:00
|
|
|
{
|
2017-04-13 12:28:49 +08:00
|
|
|
static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right);
|
|
|
|
|
2017-04-04 07:22:51 +08:00
|
|
|
InstallPlanAction();
|
2017-04-14 08:19:26 +08:00
|
|
|
InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type);
|
2017-07-13 08:40:41 +08:00
|
|
|
InstallPlanAction(const PackageSpec& spec,
|
|
|
|
const SourceControlFile& any_paragraph,
|
|
|
|
std::unordered_set<std::string> features,
|
|
|
|
const RequestType& request_type);
|
2017-04-04 07:22:51 +08:00
|
|
|
InstallPlanAction(const InstallPlanAction&) = delete;
|
|
|
|
InstallPlanAction(InstallPlanAction&&) = default;
|
|
|
|
InstallPlanAction& operator=(const InstallPlanAction&) = delete;
|
|
|
|
InstallPlanAction& operator=(InstallPlanAction&&) = default;
|
2017-01-31 09:52:53 +08:00
|
|
|
|
2017-04-13 12:28:49 +08:00
|
|
|
PackageSpec spec;
|
|
|
|
AnyParagraph any_paragraph;
|
2017-04-04 07:22:32 +08:00
|
|
|
InstallPlanType plan_type;
|
2017-04-08 04:03:11 +08:00
|
|
|
RequestType request_type;
|
2017-07-13 08:40:41 +08:00
|
|
|
std::unordered_set<std::string> feature_list;
|
2016-11-16 03:56:46 +08:00
|
|
|
};
|
|
|
|
|
2017-04-04 07:23:46 +08:00
|
|
|
enum class RemovePlanType
|
2017-01-27 06:25:36 +08:00
|
|
|
{
|
2017-01-31 09:52:53 +08:00
|
|
|
UNKNOWN,
|
2017-01-27 06:25:36 +08:00
|
|
|
NOT_INSTALLED,
|
2017-01-31 05:57:43 +08:00
|
|
|
REMOVE
|
2017-01-27 06:25:36 +08:00
|
|
|
};
|
|
|
|
|
2017-04-04 07:24:18 +08:00
|
|
|
struct RemovePlanAction
|
2017-01-27 09:53:45 +08:00
|
|
|
{
|
2017-04-13 12:37:55 +08:00
|
|
|
static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right);
|
|
|
|
|
2017-04-04 07:24:18 +08:00
|
|
|
RemovePlanAction();
|
2017-04-13 12:37:55 +08:00
|
|
|
RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type);
|
2017-04-04 07:24:18 +08:00
|
|
|
RemovePlanAction(const RemovePlanAction&) = delete;
|
|
|
|
RemovePlanAction(RemovePlanAction&&) = default;
|
|
|
|
RemovePlanAction& operator=(const RemovePlanAction&) = delete;
|
|
|
|
RemovePlanAction& operator=(RemovePlanAction&&) = default;
|
2017-01-31 09:52:53 +08:00
|
|
|
|
2017-04-13 12:37:55 +08:00
|
|
|
PackageSpec spec;
|
2017-04-04 07:23:46 +08:00
|
|
|
RemovePlanType plan_type;
|
2017-04-04 07:21:46 +08:00
|
|
|
RequestType request_type;
|
2017-01-27 09:53:45 +08:00
|
|
|
};
|
|
|
|
|
2017-07-13 08:40:41 +08:00
|
|
|
struct AnyAction
|
|
|
|
{
|
|
|
|
Optional<InstallPlanAction> install_plan;
|
|
|
|
Optional<RemovePlanAction> remove_plan;
|
|
|
|
};
|
|
|
|
|
2017-04-11 03:57:49 +08:00
|
|
|
enum class ExportPlanType
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
|
|
|
PORT_AVAILABLE_BUT_NOT_BUILT,
|
|
|
|
ALREADY_BUILT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ExportPlanAction
|
|
|
|
{
|
|
|
|
static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right);
|
|
|
|
|
|
|
|
ExportPlanAction();
|
|
|
|
ExportPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type);
|
|
|
|
ExportPlanAction(const ExportPlanAction&) = delete;
|
|
|
|
ExportPlanAction(ExportPlanAction&&) = default;
|
|
|
|
ExportPlanAction& operator=(const ExportPlanAction&) = delete;
|
|
|
|
ExportPlanAction& operator=(ExportPlanAction&&) = default;
|
|
|
|
|
|
|
|
PackageSpec spec;
|
|
|
|
AnyParagraph any_paragraph;
|
|
|
|
ExportPlanType plan_type;
|
|
|
|
RequestType request_type;
|
|
|
|
};
|
|
|
|
|
2017-06-28 05:52:26 +08:00
|
|
|
__interface PortFileProvider { virtual const SourceControlFile& get_control_file(const PackageSpec& spec) const; };
|
2017-06-27 04:48:04 +08:00
|
|
|
|
|
|
|
struct MapPortFile : PortFileProvider
|
|
|
|
{
|
|
|
|
const std::unordered_map<PackageSpec, SourceControlFile>& ports;
|
|
|
|
explicit MapPortFile(const std::unordered_map<PackageSpec, SourceControlFile>& map);
|
2017-06-28 05:52:26 +08:00
|
|
|
const SourceControlFile& get_control_file(const PackageSpec& spec) const override;
|
2017-06-27 04:48:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PathsPortFile : PortFileProvider
|
|
|
|
{
|
|
|
|
const VcpkgPaths& ports;
|
|
|
|
mutable std::unordered_map<PackageSpec, SourceControlFile> cache;
|
|
|
|
explicit PathsPortFile(const VcpkgPaths& paths);
|
2017-06-28 05:52:26 +08:00
|
|
|
const SourceControlFile& get_control_file(const PackageSpec& spec) const override;
|
2017-06-27 04:48:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<InstallPlanAction> create_install_plan(const PortFileProvider& port_file_provider,
|
2017-04-28 08:56:06 +08:00
|
|
|
const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db);
|
2017-01-27 09:53:45 +08:00
|
|
|
|
2017-04-28 08:56:06 +08:00
|
|
|
std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db);
|
2017-04-11 03:57:49 +08:00
|
|
|
|
2017-04-28 08:56:06 +08:00
|
|
|
std::vector<ExportPlanAction> create_export_plan(const VcpkgPaths& paths,
|
|
|
|
const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db);
|
2017-01-06 06:14:11 +08:00
|
|
|
}
|
2017-07-13 08:40:41 +08:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct std::hash<vcpkg::Dependencies::Cluster>
|
|
|
|
{
|
|
|
|
size_t operator()(const vcpkg::Dependencies::Cluster& value) const
|
|
|
|
{
|
|
|
|
size_t hash = 17;
|
|
|
|
if (auto source = value.cluster_node.source_paragraph.get())
|
|
|
|
{
|
|
|
|
hash = hash * 31 + std::hash<std::string>()((*source)->core_paragraph->name);
|
|
|
|
}
|
|
|
|
else if (!value.cluster_node.status_paragraphs.empty())
|
|
|
|
{
|
|
|
|
auto start = *value.cluster_node.status_paragraphs.begin();
|
|
|
|
hash = hash * 31 + std::hash<std::string>()(start.package.displayname());
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace vcpkg::Dependencies
|
|
|
|
{
|
|
|
|
struct GraphPlan
|
|
|
|
{
|
|
|
|
Graphs::Graph<Cluster*> remove_graph;
|
|
|
|
Graphs::Graph<Cluster*> install_graph;
|
|
|
|
};
|
|
|
|
bool mark_plus(const std::string& feature,
|
|
|
|
Cluster& cluster,
|
|
|
|
std::unordered_map<PackageSpec, Cluster>& pkg_to_cluster,
|
|
|
|
GraphPlan& graph_plan);
|
|
|
|
void mark_minus(Cluster& cluster, std::unordered_map<PackageSpec, Cluster>& pkg_to_cluster, GraphPlan& graph_plan);
|
|
|
|
|
|
|
|
std::vector<AnyAction> create_feature_install_plan(const std::unordered_map<PackageSpec, SourceControlFile>& map,
|
|
|
|
const std::vector<FullPackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db);
|
|
|
|
}
|