[vcpkg] Add find/find_installed/is_installed for FeatureSpec

Signed-off-by: Squareys <squareys@googlemail.com>
This commit is contained in:
Squareys 2018-02-16 14:27:04 +01:00
parent f279e9f5e3
commit 16faed6785
3 changed files with 83 additions and 0 deletions

View File

@ -20,7 +20,21 @@ namespace vcpkg
using iterator = container::reverse_iterator;
using const_iterator = container::const_reverse_iterator;
/// <summary>Find the StatusParagraph for given spec.</summary>
/// <param name="spec">Package specification to find the status paragraph for</param>
/// <returns>Iterator for found spec</returns>
const_iterator find(const PackageSpec& spec) const { return find(spec.name(), spec.triplet()); }
/// <summary>Find the StatusParagraph for given feature spec.</summary>
/// <param name="spec">Feature specification to find the status paragraph for</param>
/// <returns>Iterator for found spec</returns>
const_iterator find(const FeatureSpec& spec) const { return find(spec.name(), spec.triplet(), spec.feature()); }
/// <summary>Find a StatusParagraph by name, triplet and feature.</summary>
/// <param name="name">Package name</param>
/// <param name="triplet">Triplet</param>
/// <param name="feature">Feature name</param>
/// <returns>Iterator for found spec</returns>
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;
@ -28,9 +42,26 @@ namespace vcpkg
Optional<InstalledPackageView> find_all_installed(const PackageSpec& spec) const;
/// <summary>Find the StatusParagraph for given spec if installed</summary>
/// <param name="spec">Package specification to find the status for</param>
/// <returns>Iterator for found spec</returns>
const_iterator find_installed(const PackageSpec& spec) const;
/// <summary>Find the StatusParagraph for given feature spec if installed</summary>
/// <param name="spec">Feature specification to find the status for</param>
/// <returns>Iterator for found spec</returns>
const_iterator find_installed(const FeatureSpec& spec) const;
/// <summary>Find the StatusParagraph for given spec and return its install status</summary>
/// <param name="spec">Package specification to check if installed</param>
/// <returns>`true` if installed, `false` if not or not found.</returns>
bool is_installed(const PackageSpec& spec) const;
/// <summary>Find the StatusParagraph for given feature spec and return its install status</summary>
/// <param name="spec">Feature specification to check if installed</param>
/// <returns>`true` if installed, `false` if not or not found.</returns>
bool is_installed(const FeatureSpec& spec) const;
iterator insert(std::unique_ptr<StatusParagraph>);
friend void serialize(const StatusParagraphs& pgh, std::string& out_str);

View File

@ -77,6 +77,39 @@ Status: purge ok not-installed
auto it = status_db.find_installed(unsafe_pspec("ffmpeg", Triplet::X64_WINDOWS));
Assert::IsTrue(it != status_db.end());
// Feature "openssl" is not installed and should not be found
auto it1 = status_db.find_installed({unsafe_pspec("ffmpeg", Triplet::X64_WINDOWS), "openssl"});
Assert::IsTrue(it1 == status_db.end());
}
TEST_METHOD(find_for_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: 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)); }));
// Feature "openssl" is installed and should therefore be found
auto it = status_db.find_installed({unsafe_pspec("ffmpeg", Triplet::X64_WINDOWS), "openssl"});
Assert::IsTrue(it != status_db.end());
}
};
}

View File

@ -83,12 +83,31 @@ namespace vcpkg
}
}
StatusParagraphs::const_iterator StatusParagraphs::find_installed(const FeatureSpec& spec) const
{
auto it = find(spec);
if (it != end() && (*it)->is_installed())
{
return it;
}
else
{
return end();
}
}
bool vcpkg::StatusParagraphs::is_installed(const PackageSpec& spec) const
{
auto it = find(spec);
return it != end() && (*it)->is_installed();
}
bool vcpkg::StatusParagraphs::is_installed(const FeatureSpec& spec) const
{
auto it = find(spec);
return it != end() && (*it)->is_installed();
}
StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr<StatusParagraph> pgh)
{
Checks::check_exit(VCPKG_LINE_INFO, pgh != nullptr, "Inserted null paragraph");