[vcpkg] Add tests for create_export_plan and remove unused arguments
MODIFY
include/vcpkg/dependencies.h
include/vcpkg/dependencies.h
@@ -93,7 +93,7 @@ namespace vcpkg::Dependencies
enum class ExportPlanType
{
UNKNOWN,
- PORT_AVAILABLE_BUT_NOT_BUILT,
+ NOT_BUILT,
ALREADY_BUILT
};
@@ -165,9 +165,7 @@ namespace vcpkg::Dependencies
std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db);
- std::vector<ExportPlanAction> create_export_plan(const PortFileProvider& port_file_provider,
- const VcpkgPaths& paths,
- const std::vector<PackageSpec>& specs,
+ std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db);
std::vector<AnyAction> create_feature_install_plan(const std::unordered_map<std::string, SourceControlFile>& map,

MODIFY
src/tests.plan.cpp
src/tests.plan.cpp
@@ -997,4 +997,98 @@ namespace UnitTest1
features_check(&plan[1], "a", {"core", "a1"});
}
};
+
+ class ExportPlanTests : public TestClass<ExportPlanTests>
+ {
+ TEST_METHOD(basic_export_scheme)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("a"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_recurse)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("a"));
+ pghs.push_back(make_status_pgh("b", "a"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+ auto spec_b = spec_map.emplace("b", "a");
+
+ auto plan = Dependencies::create_export_plan({spec_b}, status_db);
+
+ Assert::AreEqual(size_t(2), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+
+ Assert::AreEqual("b", plan[1].spec.name().c_str());
+ Assert::IsTrue(plan[1].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_bystander)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("a"));
+ pghs.push_back(make_status_pgh("b"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+ auto spec_b = spec_map.emplace("b", "a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_missing)
+ {
+ StatusParagraphs status_db;
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::NOT_BUILT);
+ }
+
+ TEST_METHOD(basic_upgrade_scheme_with_features)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("b"));
+ pghs.push_back(make_status_pgh("a"));
+ pghs.push_back(make_status_feature_pgh("a", "a1", "b[core]"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a", "", {{"a1", ""}});
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(2), plan.size());
+
+ Assert::AreEqual("b", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+
+ Assert::AreEqual("a", plan[1].spec.name().c_str());
+ Assert::IsTrue(plan[1].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+ };
}

MODIFY
src/vcpkg/dependencies.cpp
src/vcpkg/dependencies.cpp
@@ -223,7 +223,7 @@ namespace vcpkg::Dependencies
}
ExportPlanAction::ExportPlanAction(const PackageSpec& spec, const RequestType& request_type)
- : spec(spec), plan_type(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT), request_type(request_type)
+ : spec(spec), plan_type(ExportPlanType::NOT_BUILT), request_type(request_type)
{
}
@@ -349,23 +349,16 @@ namespace vcpkg::Dependencies
return Graphs::topological_sort(specs, RemoveAdjacencyProvider{status_db, installed_ports, specs_as_set});
}
- std::vector<ExportPlanAction> create_export_plan(const PortFileProvider& port_file_provider,
- const VcpkgPaths& paths,
- const std::vector<PackageSpec>& specs,
+ std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db)
{
struct ExportAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, ExportPlanAction>
{
- const VcpkgPaths& paths;
const StatusParagraphs& status_db;
- const PortFileProvider& provider;
const std::unordered_set<PackageSpec>& specs_as_set;
- ExportAdjacencyProvider(const VcpkgPaths& p,
- const StatusParagraphs& s,
- const PortFileProvider& prov,
- const std::unordered_set<PackageSpec>& specs_as_set)
- : paths(p), status_db(s), provider(prov), specs_as_set(specs_as_set)
+ ExportAdjacencyProvider(const StatusParagraphs& s, const std::unordered_set<PackageSpec>& specs_as_set)
+ : status_db(s), specs_as_set(specs_as_set)
{
}
@@ -394,8 +387,8 @@ namespace vcpkg::Dependencies
};
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
- std::vector<ExportPlanAction> toposort = Graphs::topological_sort(
- specs, ExportAdjacencyProvider{paths, status_db, port_file_provider, specs_as_set});
+ std::vector<ExportPlanAction> toposort =
+ Graphs::topological_sort(specs, ExportAdjacencyProvider{status_db, specs_as_set});
return toposort;
}

MODIFY
src/vcpkg/export.cpp
src/vcpkg/export.cpp
@@ -69,7 +69,7 @@ namespace vcpkg::Export
static void print_plan(const std::map<ExportPlanType, std::vector<const ExportPlanAction*>>& group_by_plan_type)
{
static constexpr std::array<ExportPlanType, 2> ORDER = {ExportPlanType::ALREADY_BUILT,
- ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT};
+ ExportPlanType::NOT_BUILT};
static constexpr Build::BuildPackageOptions build_options = {Build::UseHeadVersion::NO,
Build::AllowDownloads::YES};
@@ -92,7 +92,7 @@ namespace vcpkg::Export
case ExportPlanType::ALREADY_BUILT:
System::println("The following packages are already built and will be exported:\n%s", as_string);
continue;
- case ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT:
+ case ExportPlanType::NOT_BUILT:
System::println("The following packages need to be built:\n%s", as_string);
continue;
default: Checks::unreachable(VCPKG_LINE_INFO);
@@ -486,8 +486,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
// create the plan
const StatusParagraphs status_db = database_load_check(paths);
Dependencies::PathsPortFileProvider provider(paths);
- std::vector<ExportPlanAction> export_plan =
- Dependencies::create_export_plan(provider, paths, opts.specs, status_db);
+ std::vector<ExportPlanAction> export_plan = Dependencies::create_export_plan(opts.specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !export_plan.empty(), "Export plan cannot be empty");
std::map<ExportPlanType, std::vector<const ExportPlanAction*>> group_by_plan_type;
@@ -505,7 +504,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
"Additional packages (*) need to be exported to complete this operation.");
}
- const auto it = group_by_plan_type.find(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT);
+ const auto it = group_by_plan_type.find(ExportPlanType::NOT_BUILT);
if (it != group_by_plan_type.cend() && !it->second.empty())
{
System::println(System::Color::error, "There are packages that have not been built.");

[vcpkg] Add tests for create_export_plan and remove unused arguments