2016-09-22 23:28:50 -07:00
|
|
|
#include "vcpkg_Dependencies.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "vcpkg_Graphs.h"
|
|
|
|
#include "vcpkg_paths.h"
|
|
|
|
#include "package_spec.h"
|
|
|
|
#include "StatusParagraphs.h"
|
|
|
|
#include <unordered_set>
|
|
|
|
#include "vcpkg_Maps.h"
|
2016-11-07 16:38:49 -08:00
|
|
|
#include "vcpkg_Files.h"
|
2017-01-25 19:32:50 -08: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
|
|
|
{
|
2016-11-15 11:56:46 -08:00
|
|
|
std::vector<package_spec_with_install_plan> create_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db)
|
2016-11-07 17:05:32 -08:00
|
|
|
{
|
2016-11-15 11:56:46 -08:00
|
|
|
std::unordered_map<package_spec, install_plan_action> was_examined; // Examine = we have checked its immediate (non-recursive) dependencies
|
2016-09-22 23:28:50 -07:00
|
|
|
Graphs::Graph<package_spec> graph;
|
2016-11-15 11:56:46 -08:00
|
|
|
graph.add_vertices(specs);
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
std::vector<package_spec> examine_stack(specs);
|
2016-09-22 23:28:50 -07:00
|
|
|
while (!examine_stack.empty())
|
|
|
|
{
|
2016-10-03 17:45:01 -07:00
|
|
|
const package_spec spec = examine_stack.back();
|
2016-09-22 23:28:50 -07:00
|
|
|
examine_stack.pop_back();
|
|
|
|
|
|
|
|
if (was_examined.find(spec) != was_examined.end())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
auto process_dependencies = [&](const std::vector<std::string>& dependencies_as_string)
|
|
|
|
{
|
|
|
|
for (const std::string& dep_as_string : dependencies_as_string)
|
|
|
|
{
|
|
|
|
const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw();
|
|
|
|
graph.add_edge(spec, current_dep);
|
|
|
|
if (was_examined.find(current_dep) == was_examined.end())
|
|
|
|
{
|
|
|
|
examine_stack.push_back(std::move(current_dep));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-09-22 23:28:50 -07:00
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
auto it = status_db.find(spec);
|
|
|
|
if (it != status_db.end() && (*it)->want == want_t::install)
|
2016-09-22 23:28:50 -07:00
|
|
|
{
|
2016-11-15 11:56:46 -08:00
|
|
|
was_examined.emplace(spec, install_plan_action{install_plan_type::ALREADY_INSTALLED, nullptr, nullptr});
|
2016-11-15 11:56:46 -08:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-04 15:25:53 -07:00
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
expected<BinaryParagraph> maybe_bpgh = try_load_cached_package(paths, spec);
|
|
|
|
if (BinaryParagraph* bpgh = maybe_bpgh.get())
|
|
|
|
{
|
|
|
|
process_dependencies(bpgh->depends);
|
2016-11-15 11:56:46 -08:00
|
|
|
was_examined.emplace(spec, install_plan_action{install_plan_type::INSTALL, std::make_unique<BinaryParagraph>(std::move(*bpgh)), nullptr});
|
2016-11-15 11:56:46 -08:00
|
|
|
continue;
|
2016-09-22 23:28:50 -07:00
|
|
|
}
|
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
expected<SourceParagraph> maybe_spgh = try_load_port(paths, spec.name());
|
|
|
|
SourceParagraph* spgh = maybe_spgh.get();
|
2016-12-20 14:45:13 -08:00
|
|
|
Checks::check_exit(spgh != nullptr, "Cannot find package %s", spec.name());
|
2016-11-15 11:56:46 -08:00
|
|
|
process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet()));
|
2016-11-15 11:56:46 -08:00
|
|
|
was_examined.emplace(spec, install_plan_action{install_plan_type::BUILD_AND_INSTALL, nullptr, std::make_unique<SourceParagraph>(std::move(*spgh))});
|
2016-09-22 23:28:50 -07:00
|
|
|
}
|
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
std::vector<package_spec_with_install_plan> ret;
|
2016-11-07 16:38:49 -08:00
|
|
|
|
2016-11-15 11:56:46 -08:00
|
|
|
const std::vector<package_spec> pkgs = graph.find_topological_sort();
|
|
|
|
for (const package_spec& pkg : pkgs)
|
2016-11-07 16:38:49 -08:00
|
|
|
{
|
2016-11-15 11:56:46 -08:00
|
|
|
ret.push_back({ pkg, std::move(was_examined[pkg]) });
|
2016-11-07 16:38:49 -08:00
|
|
|
}
|
2016-11-15 11:56:46 -08:00
|
|
|
return ret;
|
2016-11-07 16:38:49 -08:00
|
|
|
}
|
2017-01-05 14:14:11 -08:00
|
|
|
}
|