Skip to content

Commit

Permalink
[vcpkg] Implement Default-Features (#2697)
Browse files Browse the repository at this point in the history
* [vcpkg] Add Default-Feature to make_status_pgh utility function

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Parse "Default-Features" as dependencies and add test for parsing

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Document some methods and structures

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Add install_default_features_test

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Change install_default_features_test to not have preinstalled package

* [vcpkg] Test install behaviour of default features

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Implement default features

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Test default features upgrade behavior

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Implement upgrade with default features

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Test behaviour of upgrade with default features in dependencies

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Make upgrade install new default features

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Move collecting of packages for which to prevent defaults

Further down the line to create_feature_install_plan.

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Fix core missing from default features and potential inf loop

Signed-off-by: Squareys <squareys@googlemail.com>

* [vcpkg] Rename, fix and move some tests

Signed-off-by: Squareys <squareys@googlemail.com>
  • Loading branch information
Squareys authored and ras0219-msft committed Feb 15, 2018
1 parent 50a545f commit 425d07e
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 27 deletions.
1 change: 1 addition & 0 deletions toolsrc/include/tests.utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework

std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name,
const char* depends = "",
const char* default_features = "",
const char* triplet = "x86-windows");
std::unique_ptr<vcpkg::StatusParagraph> make_status_feature_pgh(const char* name,
const char* feature,
Expand Down
3 changes: 2 additions & 1 deletion toolsrc/include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ namespace vcpkg::Dependencies
PackageGraph(const PortFileProvider& provider, const StatusParagraphs& status_db);
~PackageGraph();

void install(const FeatureSpec& spec) const;
void install(const FeatureSpec& spec,
const std::unordered_set<std::string>& prevent_default_features = {}) const;
void upgrade(const PackageSpec& spec) const;

std::vector<AnyAction> serialize() const;
Expand Down
23 changes: 23 additions & 0 deletions toolsrc/include/vcpkg/packagespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace vcpkg
static ExpectedT<ParsedSpecifier, PackageSpecParseResult> from_string(const std::string& input);
};

///
/// <summary>
/// Full specification of a package. Contains all information to reference
/// a specific package.
/// </summary>
///
struct PackageSpec
{
static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name,
Expand Down Expand Up @@ -46,6 +52,12 @@ namespace vcpkg
Triplet m_triplet;
};

///
/// <summary>
/// Full specification of a feature. Contains all information to reference
/// a single feature in a specific package.
/// </summary>
///
struct FeatureSpec
{
FeatureSpec(const PackageSpec& spec, const std::string& feature) : m_spec(spec), m_feature(feature) {}
Expand Down Expand Up @@ -82,6 +94,12 @@ namespace vcpkg
std::string m_feature;
};

///
/// <summary>
/// Full specification of a package. Contains all information to reference
/// a collection of features in a single package.
/// </summary>
///
struct FullPackageSpec
{
PackageSpec package_spec;
Expand All @@ -93,6 +111,11 @@ namespace vcpkg
const Triplet& default_triplet);
};

///
/// <summary>
/// Contains all information to reference a collection of features in a single package by their names.
/// </summary>
///
struct Features
{
std::string name;
Expand Down
9 changes: 8 additions & 1 deletion toolsrc/include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace vcpkg

std::string to_string(const Dependency& dep);

/// <summary>
/// Port metadata of additional feature in a package (part of CONTROL file)
/// </summary>
struct FeatureParagraph
{
std::string name;
Expand All @@ -37,7 +40,7 @@ namespace vcpkg
};

/// <summary>
/// Port metadata (CONTROL file)
/// Port metadata of the core feature of a package (part of CONTROL file)
/// </summary>
struct SourceParagraph
{
Expand All @@ -49,6 +52,10 @@ namespace vcpkg
std::vector<Dependency> depends;
std::vector<std::string> default_features;
};

/// <summary>
/// Full metadata of a package: core and other features.
/// </summary>
struct SourceControlFile
{
static Parse::ParseExpected<SourceControlFile> parse_control_file(
Expand Down
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/statusparagraphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

namespace vcpkg
{
/// <summary>Status paragraphs</summary>
///
/// Collection of <see cref="vcpkg::StatusParagraph"/>, e.g. contains the information
/// about whether a package is installed or not.
///
struct StatusParagraphs
{
StatusParagraphs();
Expand Down
35 changes: 34 additions & 1 deletion toolsrc/src/tests.paragraph.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tests.pch.h"
#include "tests.pch.h"

#pragma comment(lib, "version")
#pragma comment(lib, "winhttp")
Expand Down Expand Up @@ -47,6 +47,7 @@ namespace UnitTest1
{"Maintainer", "m"},
{"Description", "d"},
{"Build-Depends", "bd"},
{"Default-Features", "df"},
{"Supports", "x64"},
}});
Assert::IsTrue(m_pgh.has_value());
Expand All @@ -58,6 +59,8 @@ namespace UnitTest1
Assert::AreEqual("d", pgh->core_paragraph->description.c_str());
Assert::AreEqual(size_t(1), pgh->core_paragraph->depends.size());
Assert::AreEqual("bd", pgh->core_paragraph->depends[0].name().c_str());
Assert::AreEqual(size_t(1), pgh->core_paragraph->default_features.size());
Assert::AreEqual("df", pgh->core_paragraph->default_features[0].c_str());
Assert::AreEqual(size_t(1), pgh->core_paragraph->supports.size());
Assert::AreEqual("x64", pgh->core_paragraph->supports[0].c_str());
}
Expand Down Expand Up @@ -134,6 +137,21 @@ namespace UnitTest1
Assert::AreEqual("uwp", pgh->core_paragraph->depends[1].qualifier.c_str());
}

TEST_METHOD(SourceParagraph_Default_Features)
{
auto m_pgh =
vcpkg::SourceControlFile::parse_control_file(std::vector<std::unordered_map<std::string, std::string>>{{
{"Source", "a"},
{"Version", "1.0"},
{"Default-Features", "a1"},
}});
Assert::IsTrue(m_pgh.has_value());
auto& pgh = *m_pgh.get();

Assert::AreEqual(size_t(1), pgh->core_paragraph->default_features.size());
Assert::AreEqual("a1", pgh->core_paragraph->default_features[0].c_str());
}

TEST_METHOD(BinaryParagraph_Construct_Minimum)
{
vcpkg::BinaryParagraph pgh({
Expand Down Expand Up @@ -200,6 +218,21 @@ namespace UnitTest1
Assert::IsTrue(pgh.abi == "abcd123");
}

TEST_METHOD(BinaryParagraph_Default_Features)
{
vcpkg::BinaryParagraph pgh({
{"Package", "a"},
{"Version", "1.0"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Default-Features", "a1"},
});

Assert::AreEqual(size_t(0), pgh.depends.size());
Assert::AreEqual(size_t(1), pgh.default_features.size());
Assert::IsTrue(pgh.default_features[0] == "a1");
}

TEST_METHOD(parse_paragraphs_empty)
{
const char* str = "";
Expand Down
Loading

0 comments on commit 425d07e

Please sign in to comment.