aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorDaniel Shaw <t-dansha@microsoft.com>2017-06-26 13:48:04 -0700
committerDaniel Shaw <t-dansha@microsoft.com>2017-06-26 15:36:57 -0700
commit838e8783d659456037c0e8e89dcc689e626b6816 (patch)
tree7398f92bf58d5ace733c33f20a6b852bd0e82ea3 /toolsrc/src
parent0f0234eed88c800586979071e0637cfc4c2d9c8c (diff)
downloadvcpkg-838e8783d659456037c0e8e89dcc689e626b6816.tar.gz
vcpkg-838e8783d659456037c0e8e89dcc689e626b6816.zip
adding tests for install plans
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/commands_ci.cpp3
-rw-r--r--toolsrc/src/commands_install.cpp3
-rw-r--r--toolsrc/src/test_install_plan.cpp155
-rw-r--r--toolsrc/src/vcpkg_Dependencies.cpp79
4 files changed, 237 insertions, 3 deletions
diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp
index 7ffc7577a..85febd580 100644
--- a/toolsrc/src/commands_ci.cpp
+++ b/toolsrc/src/commands_ci.cpp
@@ -40,7 +40,8 @@ namespace vcpkg::Commands::CI
const std::vector<PackageSpec> specs = load_all_package_specs(paths.get_filesystem(), paths.ports, triplet);
StatusParagraphs status_db = database_load_check(paths);
- const std::vector<InstallPlanAction> install_plan = Dependencies::create_install_plan(paths, specs, status_db);
+ const std::vector<InstallPlanAction> install_plan /* =
+ Dependencies::create_install_plan(Dependencies::PathsPortFile(paths), specs, status_db)*/;
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
std::vector<BuildResult> results;
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index 73b3e9eab..a58432eef 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -359,7 +359,8 @@ namespace vcpkg::Commands::Install
// create the plan
StatusParagraphs status_db = database_load_check(paths);
- std::vector<InstallPlanAction> install_plan = Dependencies::create_install_plan(paths, specs, status_db);
+ std::vector<InstallPlanAction> install_plan =
+ Dependencies::create_install_plan(Dependencies::PathsPortFile(paths), specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
// log the plan
diff --git a/toolsrc/src/test_install_plan.cpp b/toolsrc/src/test_install_plan.cpp
new file mode 100644
index 000000000..90aaa532f
--- /dev/null
+++ b/toolsrc/src/test_install_plan.cpp
@@ -0,0 +1,155 @@
+#include "CppUnitTest.h"
+#include "vcpkg_Dependencies.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+using namespace vcpkg;
+
+namespace UnitTest1
+{
+ class InstallPlanTests : public TestClass<InstallPlanTests>
+ {
+ TEST_METHOD(basic_install_scheme)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+
+ std::unordered_map<PackageSpec, SourceControlFile> map;
+ auto add_scf = [&](std::vector<std::unordered_map<std::string, std::string>>&& fields) -> PackageSpec {
+ auto m_pgh = vcpkg::SourceControlFile::parse_control_file(std::move(fields));
+ Assert::IsTrue(m_pgh.has_value());
+ auto& scf = *m_pgh.get();
+
+ auto spec = PackageSpec::from_name_and_triplet(scf.core_paragraph.name, Triplet::X86_WINDOWS);
+ Assert::IsTrue(spec.has_value());
+ map.emplace(*spec.get(), std::move(*m_pgh.get()));
+ return PackageSpec{*spec.get()};
+ };
+
+ auto spec_a = add_scf({{{"Source", "a"}, {"Version", "1.2.8"}, {"Build-Depends", "b"}}});
+ auto spec_b = add_scf({{{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", "c"}}});
+ auto spec_c = add_scf({{{"Source", "c"}, {"Version", "2.5.3"}, {"Build-Depends", ""}}});
+
+ auto map_port = Dependencies::MapPortFile(map);
+ auto install_plan =
+ Dependencies::create_install_plan(map_port, {spec_a}, StatusParagraphs(std::move(status_paragraphs)));
+
+ Assert::AreEqual(size_t(3), install_plan.size());
+ Assert::AreEqual("c", install_plan[0].spec.name().c_str());
+ Assert::AreEqual("b", install_plan[1].spec.name().c_str());
+ Assert::AreEqual("a", install_plan[2].spec.name().c_str());
+ }
+
+ TEST_METHOD(multiple_install_scheme)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+
+ std::unordered_map<PackageSpec, SourceControlFile> map;
+ auto add_scf = [&](std::vector<std::unordered_map<std::string, std::string>>&& fields) -> PackageSpec {
+ auto m_pgh = vcpkg::SourceControlFile::parse_control_file(std::move(fields));
+ Assert::IsTrue(m_pgh.has_value());
+ auto& scf = *m_pgh.get();
+
+ auto spec = PackageSpec::from_name_and_triplet(scf.core_paragraph.name, Triplet::X86_WINDOWS);
+ Assert::IsTrue(spec.has_value());
+ map.emplace(*spec.get(), std::move(*m_pgh.get()));
+ return PackageSpec{*spec.get()};
+ };
+
+ auto spec_a = add_scf({{{"Source", "a"}, {"Version", "1.2.8"}, {"Build-Depends", "d"}}});
+ auto spec_b = add_scf({{{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", "d, e"}}});
+ auto spec_c = add_scf({{{"Source", "c"}, {"Version", "2.5.3"}, {"Build-Depends", "e, h"}}});
+ auto spec_d = add_scf({{{"Source", "d"}, {"Version", "4.0"}, {"Build-Depends", "f, g, h"}}});
+ auto spec_e = add_scf({{{"Source", "e"}, {"Version", "1.0"}, {"Build-Depends", "g"}}});
+ auto spec_f = add_scf({{{"Source", "f"}, {"Version", "1.0"}, {"Build-Depends", ""}}});
+ auto spec_g = add_scf({{{"Source", "g"}, {"Version", "1.0"}, {"Build-Depends", ""}}});
+ auto spec_h = add_scf({{{"Source", "h"}, {"Version", "1.0"}, {"Build-Depends", ""}}});
+
+ auto map_port = Dependencies::MapPortFile(map);
+ auto install_plan = Dependencies::create_install_plan(
+ map_port, {spec_a, spec_b, spec_c}, StatusParagraphs(std::move(status_paragraphs)));
+
+ auto iterator_pos = [&](const PackageSpec& spec) -> int {
+ int counter = 0;
+ for (auto&& install_p : install_plan)
+ {
+ if (install_p.spec == spec)
+ {
+ return counter;
+ }
+ counter++;
+ }
+ return -1;
+ };
+ int a_pos = iterator_pos(spec_a), b_pos = iterator_pos(spec_b), c_pos = iterator_pos(spec_c),
+ d_pos = iterator_pos(spec_d), e_pos = iterator_pos(spec_e), f_pos = iterator_pos(spec_f),
+ g_pos = iterator_pos(spec_g), h_pos = iterator_pos(spec_h);
+
+ Assert::IsTrue(a_pos > d_pos);
+ Assert::IsTrue(b_pos > e_pos);
+ Assert::IsTrue(b_pos > d_pos);
+ Assert::IsTrue(c_pos > e_pos);
+ Assert::IsTrue(c_pos > h_pos);
+ Assert::IsTrue(d_pos > f_pos);
+ Assert::IsTrue(d_pos > g_pos);
+ Assert::IsTrue(d_pos > h_pos);
+ Assert::IsTrue(e_pos > g_pos);
+ }
+
+ TEST_METHOD(long_install_scheme)
+ {
+ using Pgh = std::unordered_map<std::string, std::string>;
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "j"},
+ {"Version", "1.2.8"},
+ {"Architecture", "x86-windows"},
+ {"Multi-Arch", "same"},
+ {"Build-Depends", "k"},
+ {"Status", "install ok installed"}}));
+ status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "k"},
+ {"Version", "1.2.8"},
+ {"Architecture", "x86-windows"},
+ {"Multi-Arch", "same"},
+ {"Build-Depends", ""},
+ {"Status", "install ok installed"}}));
+
+ std::unordered_map<PackageSpec, SourceControlFile> map;
+ auto add_scf = [&](std::vector<std::unordered_map<std::string, std::string>>&& fields) -> PackageSpec {
+ auto m_pgh = vcpkg::SourceControlFile::parse_control_file(std::move(fields));
+ Assert::IsTrue(m_pgh.has_value());
+ auto& scf = *m_pgh.get();
+
+ auto spec = PackageSpec::from_name_and_triplet(scf.core_paragraph.name, Triplet::X86_WINDOWS);
+ Assert::IsTrue(spec.has_value());
+ map.emplace(*spec.get(), std::move(*m_pgh.get()));
+ return PackageSpec{*spec.get()};
+ };
+
+ auto spec_h = add_scf({{{"Source", "h"}, {"Version", "1.2.8"}, {"Build-Depends", "j, k"}}});
+ auto spec_c = add_scf({{{"Source", "c"}, {"Version", "1.2.8"}, {"Build-Depends", "d, e, f, g, h, j, k"}}});
+ auto spec_k = add_scf({{{"Source", "k"}, {"Version", "1.2.8"}, {"Build-Depends", ""}}});
+ auto spec_b =
+ add_scf({{{"Source", "b"}, {"Version", "1.2.8"}, {"Build-Depends", "c, d, e, f, g, h, j, k"}}});
+ auto spec_d = add_scf({{{"Source", "d"}, {"Version", "1.2.8"}, {"Build-Depends", "e, f, g, h, j, k"}}});
+ auto spec_j = add_scf({{{"Source", "j"}, {"Version", "1.2.8"}, {"Build-Depends", "k"}}});
+ auto spec_f = add_scf({{{"Source", "f"}, {"Version", "1.2.8"}, {"Build-Depends", "g, h, j, k"}}});
+ auto spec_e = add_scf({{{"Source", "e"}, {"Version", "1.2.8"}, {"Build-Depends", "f, g, h, j, k"}}});
+ auto spec_a =
+ add_scf({{{"Source", "a"}, {"Version", "1.2.8"}, {"Build-Depends", "b, c, d, e, f, g, h, j, k"}}});
+ auto spec_g = add_scf({{{"Source", "g"}, {"Version", "1.2.8"}, {"Build-Depends", "h, j, k"}}});
+
+ auto map_port = Dependencies::MapPortFile(map);
+ auto install_plan =
+ Dependencies::create_install_plan(map_port, {spec_a}, StatusParagraphs(std::move(status_paragraphs)));
+
+ Assert::AreEqual(size_t(8), install_plan.size());
+ Assert::AreEqual("h", install_plan[0].spec.name().c_str());
+ Assert::AreEqual("g", install_plan[1].spec.name().c_str());
+ Assert::AreEqual("f", install_plan[2].spec.name().c_str());
+ Assert::AreEqual("e", install_plan[3].spec.name().c_str());
+ Assert::AreEqual("d", install_plan[4].spec.name().c_str());
+ Assert::AreEqual("c", install_plan[5].spec.name().c_str());
+ Assert::AreEqual("b", install_plan[6].spec.name().c_str());
+ Assert::AreEqual("a", install_plan[7].spec.name().c_str());
+ }
+ };
+} \ No newline at end of file
diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp
index bbf807c95..79f572496 100644
--- a/toolsrc/src/vcpkg_Dependencies.cpp
+++ b/toolsrc/src/vcpkg_Dependencies.cpp
@@ -139,12 +139,89 @@ namespace vcpkg::Dependencies
return left->spec.name() < right->spec.name();
}
- std::vector<InstallPlanAction> create_install_plan(const VcpkgPaths& paths,
+ MapPortFile::MapPortFile(const std::unordered_map<PackageSpec, SourceControlFile>& map) : ports(map){};
+ const SourceControlFile* MapPortFile::get_control_file(const PackageSpec& spec) const
+ {
+ auto scf = ports.find(spec);
+ if (scf == ports.end())
+ {
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
+ return &scf->second;
+ }
+
+ PathsPortFile::PathsPortFile(const VcpkgPaths& paths) : ports(paths){};
+ const SourceControlFile* PathsPortFile::get_control_file(const PackageSpec& spec) const
+ {
+ std::unordered_map<PackageSpec, SourceControlFile>::iterator cache_it = cache.find(spec);
+ if (cache_it != cache.end())
+ {
+ return &cache_it->second;
+ }
+ ExpectedT<SourceControlFile, ParseControlErrorInfo> source_control_file =
+ Paragraphs::try_load_port(ports.get_filesystem(), ports.port_dir(spec));
+
+ if (auto scf = source_control_file.get())
+ {
+ auto it = cache.emplace(spec, std::move(*scf));
+ return &it.first->second;
+ }
+
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
+
+ std::vector<InstallPlanAction> create_install_plan(const PortFileProvider& port_file_provider,
const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db)
{
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{
+ spec, {nullopt, nullopt, port_file_provider.get_control_file(spec)->core_paragraph}, request_type};
+ }
+ };
+
+ 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;
+ }
+
+ std::vector<InstallPlanAction> create_full_install_plan(const VcpkgPaths& paths,
+ const std::vector<PackageSpec>& specs,
+ const StatusParagraphs& status_db)
+ {
+ struct InstallAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, InstallPlanAction>
+ {
const VcpkgPaths& paths;
const StatusParagraphs& status_db;
const std::unordered_set<PackageSpec>& specs_as_set;