diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index e3f8bf79e82..d7c5c8344ab 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -104,11 +104,11 @@ namespace vcpkg::Build struct ExtendedBuildResult { ExtendedBuildResult(BuildResult code); - ExtendedBuildResult(BuildResult code, std::vector&& unmet_deps); + ExtendedBuildResult(BuildResult code, std::vector&& unmet_deps); ExtendedBuildResult(BuildResult code, std::unique_ptr&& bcf); BuildResult code; - std::vector unmet_dependencies; + std::vector unmet_dependencies; std::unique_ptr binary_control_file; }; diff --git a/toolsrc/include/vcpkg/statusparagraphs.h b/toolsrc/include/vcpkg/statusparagraphs.h index b3eec266aee..fa064de7edd 100644 --- a/toolsrc/include/vcpkg/statusparagraphs.h +++ b/toolsrc/include/vcpkg/statusparagraphs.h @@ -20,7 +20,21 @@ namespace vcpkg using iterator = container::reverse_iterator; using const_iterator = container::const_reverse_iterator; + /// Find the StatusParagraph for given spec. + /// Package specification to find the status paragraph for + /// Iterator for found spec const_iterator find(const PackageSpec& spec) const { return find(spec.name(), spec.triplet()); } + + /// Find the StatusParagraph for given feature spec. + /// Feature specification to find the status paragraph for + /// Iterator for found spec + const_iterator find(const FeatureSpec& spec) const { return find(spec.name(), spec.triplet(), spec.feature()); } + + /// Find a StatusParagraph by name, triplet and feature. + /// Package name + /// Triplet + /// Feature name + /// Iterator for found spec 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 find_all_installed(const PackageSpec& spec) const; + /// Find the StatusParagraph for given spec if installed + /// Package specification to find the status for + /// Iterator for found spec const_iterator find_installed(const PackageSpec& spec) const; + + /// Find the StatusParagraph for given feature spec if installed + /// Feature specification to find the status for + /// Iterator for found spec + const_iterator find_installed(const FeatureSpec& spec) const; + + /// Find the StatusParagraph for given spec and return its install status + /// Package specification to check if installed + /// `true` if installed, `false` if not or not found. bool is_installed(const PackageSpec& spec) const; + /// Find the StatusParagraph for given feature spec and return its install status + /// Feature specification to check if installed + /// `true` if installed, `false` if not or not found. + bool is_installed(const FeatureSpec& spec) const; + iterator insert(std::unique_ptr); friend void serialize(const StatusParagraphs& pgh, std::string& out_str); diff --git a/toolsrc/src/tests.statusparagraphs.cpp b/toolsrc/src/tests.statusparagraphs.cpp index 0d5324a8cb9..fa0d54fac26 100644 --- a/toolsrc/src/tests.statusparagraphs.cpp +++ b/toolsrc/src/tests.statusparagraphs.cpp @@ -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(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()); } }; } diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 7de276f4f42..cc376c77350 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -267,13 +267,16 @@ namespace vcpkg::Build const Triplet& triplet = config.triplet; { - std::vector missing_specs; + std::vector missing_specs; for (auto&& dep : filter_dependencies(config.scf.core_paragraph->depends, triplet)) { - auto dep_spec = PackageSpec::from_name_and_triplet(dep, triplet).value_or_exit(VCPKG_LINE_INFO); - if (!status_db.is_installed(dep_spec)) + auto dep_specs = FeatureSpec::from_strings_and_triplet({dep}, triplet); + for (auto&& feature : dep_specs) { - missing_specs.push_back(std::move(dep_spec)); + if (!status_db.is_installed(feature)) + { + missing_specs.push_back(std::move(feature)); + } } } // Fail the build if any dependencies were missing @@ -600,7 +603,7 @@ namespace vcpkg::Build : code(code), binary_control_file(std::move(bcf)) { } - ExtendedBuildResult::ExtendedBuildResult(BuildResult code, std::vector&& unmet_deps) + ExtendedBuildResult::ExtendedBuildResult(BuildResult code, std::vector&& unmet_deps) : code(code), unmet_dependencies(std::move(unmet_deps)) { } diff --git a/toolsrc/src/vcpkg/statusparagraphs.cpp b/toolsrc/src/vcpkg/statusparagraphs.cpp index 475f862799f..b23d8b884ef 100644 --- a/toolsrc/src/vcpkg/statusparagraphs.cpp +++ b/toolsrc/src/vcpkg/statusparagraphs.cpp @@ -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 pgh) { Checks::check_exit(VCPKG_LINE_INFO, pgh != nullptr, "Inserted null paragraph");