2016-09-22 23:28:50 -07:00
|
|
|
#pragma once
|
2017-10-13 18:37:41 -07:00
|
|
|
|
|
|
|
#include <vcpkg/base/optional.h>
|
|
|
|
#include <vcpkg/base/util.h>
|
2017-10-31 03:04:28 -07:00
|
|
|
#include <vcpkg/build.h>
|
2017-10-13 18:37:41 -07:00
|
|
|
#include <vcpkg/packagespec.h>
|
|
|
|
#include <vcpkg/statusparagraphs.h>
|
|
|
|
#include <vcpkg/vcpkgpaths.h>
|
|
|
|
|
2019-01-18 19:03:37 -08:00
|
|
|
#include <functional>
|
2017-04-27 17:56:06 -07:00
|
|
|
#include <vector>
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2019-01-18 19:03:37 -08:00
|
|
|
namespace vcpkg::Graphs
|
|
|
|
{
|
|
|
|
struct Randomizer;
|
|
|
|
}
|
|
|
|
|
2017-01-05 14:14:11 -08:00
|
|
|
namespace vcpkg::Dependencies
|
2016-09-22 23:28:50 -07:00
|
|
|
{
|
2017-04-03 16:21:46 -07:00
|
|
|
enum class RequestType
|
2017-01-30 13:57:43 -08:00
|
|
|
{
|
2017-01-30 17:52:53 -08:00
|
|
|
UNKNOWN,
|
2017-01-30 13:57:43 -08:00
|
|
|
USER_REQUESTED,
|
|
|
|
AUTO_SELECTED
|
|
|
|
};
|
|
|
|
|
2017-10-31 03:04:28 -07:00
|
|
|
std::string to_output_string(RequestType request_type,
|
|
|
|
const CStringView s,
|
|
|
|
const Build::BuildPackageOptions& options);
|
2017-04-06 18:57:17 -07:00
|
|
|
std::string to_output_string(RequestType request_type, const CStringView s);
|
|
|
|
|
2017-04-03 16:22:32 -07:00
|
|
|
enum class InstallPlanType
|
2016-11-15 11:56:46 -08:00
|
|
|
{
|
2017-01-30 17:52:53 -08:00
|
|
|
UNKNOWN,
|
2016-11-15 11:56:46 -08:00
|
|
|
BUILD_AND_INSTALL,
|
2017-10-26 19:00:30 -07:00
|
|
|
ALREADY_INSTALLED,
|
|
|
|
EXCLUDED
|
2016-11-15 11:56:46 -08:00
|
|
|
};
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2017-08-21 20:06:47 -07:00
|
|
|
struct InstallPlanAction : Util::MoveOnlyBase
|
2016-11-15 11:56:46 -08:00
|
|
|
{
|
2017-04-12 21:28:49 -07:00
|
|
|
static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right);
|
|
|
|
|
2018-04-12 00:47:17 -07:00
|
|
|
InstallPlanAction() noexcept;
|
2017-08-21 20:06:47 -07:00
|
|
|
|
2018-04-10 04:48:02 -07:00
|
|
|
InstallPlanAction(InstalledPackageView&& spghs,
|
2018-02-25 10:13:57 -08:00
|
|
|
const std::set<std::string>& features,
|
2017-08-28 14:42:44 -07:00
|
|
|
const RequestType& request_type);
|
2018-01-23 02:21:47 -08:00
|
|
|
|
2017-07-12 17:40:41 -07:00
|
|
|
InstallPlanAction(const PackageSpec& spec,
|
2019-06-21 23:50:05 -07:00
|
|
|
const SourceControlFileLocation& scfl,
|
2018-02-25 10:13:57 -08:00
|
|
|
const std::set<std::string>& features,
|
2018-03-14 10:30:27 -07:00
|
|
|
const RequestType& request_type,
|
|
|
|
std::vector<PackageSpec>&& dependencies);
|
2017-08-21 20:06:47 -07:00
|
|
|
|
2017-07-25 21:29:31 -07:00
|
|
|
std::string displayname() const;
|
2017-01-30 17:52:53 -08:00
|
|
|
|
2017-04-12 21:28:49 -07:00
|
|
|
PackageSpec spec;
|
2018-01-23 02:21:47 -08:00
|
|
|
|
2019-06-21 23:50:05 -07:00
|
|
|
Optional<const SourceControlFileLocation&> source_control_file_location;
|
2018-01-23 06:50:24 -08:00
|
|
|
Optional<InstalledPackageView> installed_package;
|
2018-01-23 02:21:47 -08:00
|
|
|
|
2017-04-03 16:22:32 -07:00
|
|
|
InstallPlanType plan_type;
|
2017-04-07 13:03:11 -07:00
|
|
|
RequestType request_type;
|
2017-10-31 03:04:28 -07:00
|
|
|
Build::BuildPackageOptions build_options;
|
2018-02-25 10:13:57 -08:00
|
|
|
std::set<std::string> feature_list;
|
2018-03-14 10:30:27 -07:00
|
|
|
|
|
|
|
std::vector<PackageSpec> computed_dependencies;
|
2016-11-15 11:56:46 -08:00
|
|
|
};
|
|
|
|
|
2017-04-03 16:23:46 -07:00
|
|
|
enum class RemovePlanType
|
2017-01-26 14:25:36 -08:00
|
|
|
{
|
2017-01-30 17:52:53 -08:00
|
|
|
UNKNOWN,
|
2017-01-26 14:25:36 -08:00
|
|
|
NOT_INSTALLED,
|
2017-01-30 13:57:43 -08:00
|
|
|
REMOVE
|
2017-01-26 14:25:36 -08:00
|
|
|
};
|
|
|
|
|
2017-08-22 15:14:15 -07:00
|
|
|
struct RemovePlanAction : Util::MoveOnlyBase
|
2017-01-26 17:53:45 -08:00
|
|
|
{
|
2017-04-12 21:37:55 -07:00
|
|
|
static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right);
|
|
|
|
|
2018-04-12 00:47:17 -07:00
|
|
|
RemovePlanAction() noexcept;
|
2017-04-12 21:37:55 -07:00
|
|
|
RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type);
|
2017-01-30 17:52:53 -08:00
|
|
|
|
2017-04-12 21:37:55 -07:00
|
|
|
PackageSpec spec;
|
2017-04-03 16:23:46 -07:00
|
|
|
RemovePlanType plan_type;
|
2017-04-03 16:21:46 -07:00
|
|
|
RequestType request_type;
|
2017-01-26 17:53:45 -08:00
|
|
|
};
|
|
|
|
|
2017-07-12 17:40:41 -07:00
|
|
|
struct AnyAction
|
|
|
|
{
|
2017-12-13 05:43:00 -08:00
|
|
|
AnyAction(InstallPlanAction&& iplan) : install_action(std::move(iplan)) {}
|
|
|
|
AnyAction(RemovePlanAction&& rplan) : remove_action(std::move(rplan)) {}
|
2017-08-21 17:16:14 -07:00
|
|
|
|
2017-12-13 05:43:00 -08:00
|
|
|
Optional<InstallPlanAction> install_action;
|
|
|
|
Optional<RemovePlanAction> remove_action;
|
2017-09-13 17:23:04 -07:00
|
|
|
|
|
|
|
const PackageSpec& spec() const;
|
2017-07-12 17:40:41 -07:00
|
|
|
};
|
|
|
|
|
2017-04-10 12:57:49 -07:00
|
|
|
enum class ExportPlanType
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
2018-02-28 12:15:16 -08:00
|
|
|
NOT_BUILT,
|
2017-04-10 12:57:49 -07:00
|
|
|
ALREADY_BUILT
|
|
|
|
};
|
|
|
|
|
2017-08-22 15:14:15 -07:00
|
|
|
struct ExportPlanAction : Util::MoveOnlyBase
|
2017-04-10 12:57:49 -07:00
|
|
|
{
|
|
|
|
static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right);
|
|
|
|
|
2018-04-12 00:47:17 -07:00
|
|
|
ExportPlanAction() noexcept;
|
2018-01-23 02:21:47 -08:00
|
|
|
ExportPlanAction(const PackageSpec& spec,
|
2018-01-23 06:50:24 -08:00
|
|
|
InstalledPackageView&& installed_package,
|
2018-01-23 02:21:47 -08:00
|
|
|
const RequestType& request_type);
|
|
|
|
|
|
|
|
ExportPlanAction(const PackageSpec& spec, const RequestType& request_type);
|
2017-04-10 12:57:49 -07:00
|
|
|
|
|
|
|
PackageSpec spec;
|
|
|
|
ExportPlanType plan_type;
|
|
|
|
RequestType request_type;
|
2018-01-23 02:21:47 -08:00
|
|
|
|
|
|
|
Optional<const BinaryParagraph&> core_paragraph() const;
|
|
|
|
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
|
|
|
|
|
|
|
|
private:
|
2018-01-23 06:50:24 -08:00
|
|
|
Optional<InstalledPackageView> m_installed_package;
|
2017-04-10 12:57:49 -07:00
|
|
|
};
|
|
|
|
|
2017-10-16 11:44:04 -07:00
|
|
|
struct PortFileProvider
|
|
|
|
{
|
2019-06-21 23:50:05 -07:00
|
|
|
virtual Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const = 0;
|
|
|
|
virtual std::vector<const SourceControlFileLocation*> load_all_control_files() const = 0;
|
2017-10-16 11:44:04 -07:00
|
|
|
};
|
2017-06-26 13:48:04 -07:00
|
|
|
|
2017-12-13 05:43:00 -08:00
|
|
|
struct MapPortFileProvider : Util::ResourceBase, PortFileProvider
|
2017-06-26 13:48:04 -07:00
|
|
|
{
|
2019-06-21 23:50:05 -07:00
|
|
|
explicit MapPortFileProvider(const std::unordered_map<std::string, SourceControlFileLocation>& map);
|
|
|
|
Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override;
|
|
|
|
std::vector<const SourceControlFileLocation*> load_all_control_files() const override;
|
2017-12-13 05:43:00 -08:00
|
|
|
|
|
|
|
private:
|
2019-06-21 23:50:05 -07:00
|
|
|
const std::unordered_map<std::string, SourceControlFileLocation>& ports;
|
2017-06-26 13:48:04 -07:00
|
|
|
};
|
|
|
|
|
2017-12-13 05:43:00 -08:00
|
|
|
struct PathsPortFileProvider : Util::ResourceBase, PortFileProvider
|
2017-06-26 13:48:04 -07:00
|
|
|
{
|
2019-06-21 23:50:05 -07:00
|
|
|
explicit PathsPortFileProvider(const vcpkg::VcpkgPaths& paths,
|
|
|
|
const std::vector<std::string>* ports_dirs_paths);
|
|
|
|
Optional<const SourceControlFileLocation&> get_control_file(const std::string& src_name) const override;
|
|
|
|
std::vector<const SourceControlFileLocation*> load_all_control_files() const override;
|
2017-12-13 05:43:00 -08:00
|
|
|
|
|
|
|
private:
|
2019-06-21 23:50:05 -07:00
|
|
|
Files::Filesystem& filesystem;
|
|
|
|
std::vector<fs::path> ports_dirs;
|
|
|
|
mutable std::unordered_map<std::string, SourceControlFileLocation> cache;
|
2017-12-13 05:43:00 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ClusterGraph;
|
|
|
|
struct GraphPlan;
|
|
|
|
|
2019-01-18 19:03:37 -08:00
|
|
|
struct CreateInstallPlanOptions
|
|
|
|
{
|
|
|
|
Graphs::Randomizer* randomizer = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-12-13 05:43:00 -08:00
|
|
|
struct PackageGraph
|
|
|
|
{
|
|
|
|
PackageGraph(const PortFileProvider& provider, const StatusParagraphs& status_db);
|
|
|
|
~PackageGraph();
|
|
|
|
|
2018-02-15 01:18:25 +01:00
|
|
|
void install(const FeatureSpec& spec,
|
|
|
|
const std::unordered_set<std::string>& prevent_default_features = {}) const;
|
2018-01-23 15:38:08 -08:00
|
|
|
void upgrade(const PackageSpec& spec) const;
|
2017-12-13 05:43:00 -08:00
|
|
|
|
2019-01-18 19:03:37 -08:00
|
|
|
std::vector<AnyAction> serialize(const CreateInstallPlanOptions& options = {}) const;
|
2017-12-13 05:43:00 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<GraphPlan> m_graph_plan;
|
|
|
|
std::unique_ptr<ClusterGraph> m_graph;
|
2017-06-26 13:48:04 -07:00
|
|
|
};
|
|
|
|
|
2017-04-27 17:56:06 -07:00
|
|
|
std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs,
|
|
|
|
const StatusParagraphs& status_db);
|
2017-04-10 12:57:49 -07:00
|
|
|
|
2018-02-28 12:15:16 -08:00
|
|
|
std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs,
|
2017-04-27 17:56:06 -07:00
|
|
|
const StatusParagraphs& status_db);
|
2017-07-12 17:40:41 -07:00
|
|
|
|
2019-06-21 23:50:05 -07:00
|
|
|
std::vector<AnyAction> create_feature_install_plan(const std::unordered_map<std::string, SourceControlFileLocation>& map,
|
2017-08-20 19:09:39 -07:00
|
|
|
const std::vector<FeatureSpec>& specs,
|
2017-07-12 17:40:41 -07:00
|
|
|
const StatusParagraphs& status_db);
|
2017-12-13 05:43:00 -08:00
|
|
|
|
2019-01-18 19:03:37 -08:00
|
|
|
/// <summary>Figure out which actions are required to install features specifications in `specs`.</summary>
|
|
|
|
/// <param name="provider">Contains the ports of the current environment.</param>
|
|
|
|
/// <param name="specs">Feature specifications to resolve dependencies for.</param>
|
|
|
|
/// <param name="status_db">Status of installed packages in the current environment.</param>
|
2018-03-24 01:04:48 -07:00
|
|
|
std::vector<AnyAction> create_feature_install_plan(const PortFileProvider& provider,
|
2017-12-13 05:43:00 -08:00
|
|
|
const std::vector<FeatureSpec>& specs,
|
2019-01-18 19:03:37 -08:00
|
|
|
const StatusParagraphs& status_db,
|
|
|
|
const CreateInstallPlanOptions& options = {});
|
2017-12-13 05:43:00 -08:00
|
|
|
|
2019-06-24 12:09:48 -07:00
|
|
|
void print_plan(const std::vector<AnyAction>& action_plan,
|
|
|
|
const bool is_recursive = true,
|
|
|
|
const fs::path& default_ports_dir = "");
|
2017-07-12 17:40:41 -07:00
|
|
|
}
|