[vcpkg] Fix bug where packages with uninstalled features appear to be uninstalled.
MODIFY
include/vcpkg/statusparagraphs.h
include/vcpkg/statusparagraphs.h
@@ -16,10 +16,10 @@ namespace vcpkg
using const_iterator = container::const_reverse_iterator;
const_iterator find(const PackageSpec& spec) const { return find(spec.name(), spec.triplet()); }
- const_iterator find(const std::string& name, const Triplet& triplet) const;
- iterator find(const std::string& name, const Triplet& triplet);
+ iterator find(const std::string& name, const Triplet& triplet, const std::string& feature = "");
+ const_iterator find(const std::string& name, const Triplet& triplet, const std::string& feature = "") const;
+
std::vector<std::unique_ptr<StatusParagraph>*> find_all(const std::string& name, const Triplet& triplet);
- iterator find(const std::string& name, const Triplet& triplet, const std::string& feature);
const_iterator find_installed(const PackageSpec& spec) const
{

ADD
src/tests.statusparagraphs.cpp
+#include <CppUnitTest.h>
+
+#include <vcpkg/base/util.h>
+#include <vcpkg/paragraphs.h>
+#include <vcpkg/statusparagraph.h>
+#include <vcpkg/statusparagraphs.h>
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+using namespace vcpkg;
+using namespace vcpkg::Paragraphs;
+
+namespace UnitTest1
+{
+ class StatusParagraphsTests : public TestClass<StatusParagraphsTests>
+ {
+ TEST_METHOD(find_installed)
+ {
+ auto pghs = parse_paragraphs(R"(
+Package: ffmpeg
+Version: 3.3.3
+Architecture: x64-windows
+Multi-Arch: same
+Description:
+Status: install ok installed
+)");
+ Assert::IsTrue(!!pghs);
+ if (!pghs) return;
+
+ StatusParagraphs status_db(Util::fmap(
+ *pghs.get(), [](RawParagraph& rpgh) { return std::make_unique<StatusParagraph>(std::move(rpgh)); }));
+
+ auto it = status_db.find_installed("ffmpeg", Triplet::X64_WINDOWS);
+ Assert::IsTrue(it != status_db.end());
+ }
+
+ TEST_METHOD(find_not_installed)
+ {
+ auto pghs = parse_paragraphs(R"(
+Package: ffmpeg
+Version: 3.3.3
+Architecture: x64-windows
+Multi-Arch: same
+Description:
+Status: purge ok not-installed
+)");
+ Assert::IsTrue(!!pghs);
+ if (!pghs) return;
+
+ StatusParagraphs status_db(Util::fmap(
+ *pghs.get(), [](RawParagraph& rpgh) { return std::make_unique<StatusParagraph>(std::move(rpgh)); }));
+
+ auto it = status_db.find_installed("ffmpeg", Triplet::X64_WINDOWS);
+ Assert::IsTrue(it == status_db.end());
+ }
+
+ TEST_METHOD(find_with_feature_packages)
+ {
+ auto pghs = parse_paragraphs(R"(
+Package: ffmpeg
+Version: 3.3.3
+Architecture: x64-windows
+Multi-Arch: same
+Description:
+Status: install ok installed
+
+Package: ffmpeg
+Feature: openssl
+Depends: openssl
+Architecture: x64-windows
+Multi-Arch: same
+Description:
+Status: purge ok not-installed
+)");
+ Assert::IsTrue(!!pghs);
+ if (!pghs) return;
+
+ StatusParagraphs status_db(Util::fmap(
+ *pghs.get(), [](RawParagraph& rpgh) { return std::make_unique<StatusParagraph>(std::move(rpgh)); }));
+
+ auto it = status_db.find_installed("ffmpeg", Triplet::X64_WINDOWS);
+ Assert::IsTrue(it != status_db.end());
+ }
+ };
+}
\ No newline at end of file

MODIFY
src/vcpkg/statusparagraphs.cpp
src/vcpkg/statusparagraphs.cpp
@@ -10,22 +10,6 @@ namespace vcpkg
StatusParagraphs::StatusParagraphs(std::vector<std::unique_ptr<StatusParagraph>>&& ps)
: paragraphs(std::move(ps)){};
- StatusParagraphs::const_iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet) const
- {
- return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
- const PackageSpec& spec = pgh->package.spec;
- return spec.name() == name && spec.triplet() == triplet;
- });
- }
-
- StatusParagraphs::iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet)
- {
- return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
- const PackageSpec& spec = pgh->package.spec;
- return spec.name() == name && spec.triplet() == triplet;
- });
- }
-
std::vector<std::unique_ptr<StatusParagraph>*> StatusParagraphs::find_all(const std::string& name,
const Triplet& triplet)
{
@@ -50,6 +34,16 @@ namespace vcpkg
});
}
+ StatusParagraphs::const_iterator StatusParagraphs::find(const std::string& name,
+ const Triplet& triplet,
+ const std::string& feature) const
+ {
+ return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) {
+ const PackageSpec& spec = pgh->package.spec;
+ return spec.name() == name && spec.triplet() == triplet && pgh->package.feature == feature;
+ });
+ }
+
StatusParagraphs::const_iterator StatusParagraphs::find_installed(const std::string& name,
const Triplet& triplet) const
{

MODIFY
vcpkgtest/vcpkgtest.vcxproj
vcpkgtest/vcpkgtest.vcxproj
<ClCompile Include="..\src\tests.packagespec.cpp" />
<ClCompile Include="..\src\tests.paragraph.cpp" />
<ClCompile Include="..\src\tests.installplan.cpp" />
+ <ClCompile Include="..\src\tests.statusparagraphs.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\vcpkglib\vcpkglib.vcxproj">

MODIFY
vcpkgtest/vcpkgtest.vcxproj.filters
vcpkgtest/vcpkgtest.vcxproj.filters
<ClCompile Include="..\src\tests.paragraph.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\src\tests.statusparagraphs.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file

[vcpkg] Fix bug where packages with uninstalled features appear to be uninstalled.