Improve error message on invalid dependency of package
MODIFY
include/vcpkg/packagespec.h
include/vcpkg/packagespec.h
@@ -22,6 +22,10 @@ namespace vcpkg
static std::vector<PackageSpec> to_package_specs(const std::vector<std::string>& ports, const Triplet& triplet);
+ static std::vector<PackageSpec> from_dependencies_of_port(const std::string& port,
+ const std::vector<std::string>& dependencies,
+ const Triplet& triplet);
+
const std::string& name() const;
const Triplet& triplet() const;

MODIFY
src/vcpkg/dependencies.cpp
src/vcpkg/dependencies.cpp
@@ -114,19 +114,19 @@ namespace vcpkg::Dependencies
{
if (const auto p = this->status_paragraph.get())
{
- return PackageSpec::to_package_specs(p->package.depends, triplet);
+ return PackageSpec::from_dependencies_of_port(p->package.spec.name(), p->package.depends, triplet);
}
if (const auto p = this->binary_control_file.get())
{
auto deps = Util::fmap_flatten(p->features, [](const BinaryParagraph& pgh) { return pgh.depends; });
deps.insert(deps.end(), p->core_paragraph.depends.cbegin(), p->core_paragraph.depends.cend());
- return PackageSpec::to_package_specs(deps, triplet);
+ return PackageSpec::from_dependencies_of_port(p->core_paragraph.spec.name(), deps, triplet);
}
if (const auto p = this->source_paragraph.get())
{
- return PackageSpec::to_package_specs(filter_dependencies(p->depends, triplet), triplet);
+ return PackageSpec::from_dependencies_of_port(p->name, filter_dependencies(p->depends, triplet), triplet);
}
Checks::exit_with_message(VCPKG_LINE_INFO,

MODIFY
src/vcpkg/packagespec.cpp
src/vcpkg/packagespec.cpp
@@ -96,8 +96,8 @@ namespace vcpkg
std::vector<PackageSpec> PackageSpec::to_package_specs(const std::vector<std::string>& ports,
const Triplet& triplet)
{
- return Util::fmap(ports, [&](const std::string& s) -> PackageSpec {
- auto maybe_spec = PackageSpec::from_name_and_triplet(s, triplet);
+ return Util::fmap(ports, [&](const std::string& spec_as_string) -> PackageSpec {
+ auto maybe_spec = PackageSpec::from_name_and_triplet(spec_as_string, triplet);
if (auto spec = maybe_spec.get())
{
return std::move(*spec);
@@ -107,7 +107,28 @@ namespace vcpkg
Checks::exit_with_message(VCPKG_LINE_INFO,
"Invalid package: %s\n"
"%s",
- s,
+ spec_as_string,
+ vcpkg::to_string(error_type));
+ });
+ }
+
+ std::vector<PackageSpec> PackageSpec::from_dependencies_of_port(const std::string& port,
+ const std::vector<std::string>& dependencies,
+ const Triplet& triplet)
+ {
+ return Util::fmap(dependencies, [&](const std::string& spec_as_string) -> PackageSpec {
+ auto maybe_spec = PackageSpec::from_name_and_triplet(spec_as_string, triplet);
+ if (auto spec = maybe_spec.get())
+ {
+ return std::move(*spec);
+ }
+
+ const PackageSpecParseResult error_type = maybe_spec.error();
+ Checks::exit_with_message(VCPKG_LINE_INFO,
+ "Invalid dependency [%s] in package [%s]\n"
+ "%s",
+ spec_as_string,
+ port,
vcpkg::to_string(error_type));
});
}

Improve error message on invalid dependency of package