Enable qualified dependencies. Fix bug in internal 'build' command.

Added capability for CONTROL files to specify qualified dependencies, which are substring searched inside triplet names.

Fixed bug in internal 'build' command where if a package is already built, that built package's dependencies will be used to determine requirements for the build instead of the port directory's CONTROL file.
This commit is contained in:
Robert Schumacher 2016-11-05 01:02:15 -07:00
Родитель e5152851f2
Коммит 7f336c7467
15 изменённых файлов: 221 добавлений и 82 удалений

Просмотреть файл

@ -5,6 +5,16 @@
namespace vcpkg
{
struct triplet;
struct dependency
{
std::string name;
std::string qualifier;
};
std::ostream& operator<<(std::ostream& os, const dependency& p);
struct SourceParagraph
{
SourceParagraph();
@ -15,6 +25,11 @@ namespace vcpkg
std::string version;
std::string description;
std::string maintainer;
std::vector<std::string> depends;
std::vector<dependency> depends;
};
std::vector<std::string> filter_dependencies(const std::vector<vcpkg::dependency>& deps, const triplet& t);
std::vector<vcpkg::dependency> expand_qualified_dependencies(const std::vector<std::string>& depends);
std::vector<std::string> parse_depends(const std::string& depends_string);
}

Просмотреть файл

@ -21,6 +21,7 @@ namespace vcpkg
StatusParagraphs database_load_check(const vcpkg_paths& paths);
std::vector<std::string> get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db);
std::vector<std::string> get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db);
void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db);
void deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db);

Просмотреть файл

@ -9,5 +9,5 @@ namespace vcpkg {namespace Dependencies
{
std::vector<package_spec> create_dependency_ordered_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db);
std::unordered_set<package_spec> find_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db);
std::unordered_set<package_spec> find_unmet_dependencies(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db);
}}

Просмотреть файл

@ -9,6 +9,4 @@ namespace vcpkg {namespace details
std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname);
std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname);
std::vector<std::string> parse_depends(const std::string& depends_string);
}}

Просмотреть файл

@ -56,7 +56,7 @@ namespace vcpkg
Checks::check_exit(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch);
std::string deps = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DEPENDS);
this->depends = details::parse_depends(deps);
this->depends = parse_depends(deps);
}
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)
@ -65,7 +65,7 @@ namespace vcpkg
this->version = spgh.version;
this->description = spgh.description;
this->maintainer = spgh.maintainer;
this->depends = spgh.depends;
this->depends = filter_dependencies(spgh.depends, target_triplet);
}
std::string BinaryParagraph::displayname() const

Просмотреть файл

@ -2,6 +2,7 @@
#include "vcpkglib_helpers.h"
#include "vcpkg_System.h"
#include "vcpkg_Maps.h"
#include "triplet.h"
namespace vcpkg
{
@ -44,7 +45,7 @@ namespace vcpkg
this->maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER);
std::string deps = details::remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS);
this->depends = details::parse_depends(deps);
this->depends = expand_qualified_dependencies(parse_depends(deps));
if (!fields.empty())
{
@ -60,4 +61,84 @@ namespace vcpkg
exit(EXIT_FAILURE);
}
}
std::vector<dependency> vcpkg::expand_qualified_dependencies(const std::vector<std::string>& depends)
{
auto convert = [&](const std::string& depend_string) -> dependency {
auto pos = depend_string.find(' ');
if (pos == std::string::npos)
return{ depend_string, "" };
// expect of the form "\w+ \[\w+\]"
dependency dep;
dep.name = depend_string.substr(0, pos);
if (depend_string.c_str()[pos + 1] != '[' || depend_string[depend_string.size() - 1] != ']')
{
// Error, but for now just slurp the entire string.
return{ depend_string, "" };
}
dep.qualifier = depend_string.substr(pos + 2, depend_string.size() - pos - 3);
return dep;
};
std::vector<vcpkg::dependency> ret;
for (auto&& depend_string : depends)
{
ret.push_back(convert(depend_string));
}
return ret;
}
std::vector<std::string> parse_depends(const std::string& depends_string)
{
if (depends_string.empty())
{
return{};
}
std::vector<std::string> out;
size_t cur = 0;
do
{
auto pos = depends_string.find(',', cur);
if (pos == std::string::npos)
{
out.push_back(depends_string.substr(cur));
break;
}
out.push_back(depends_string.substr(cur, pos - cur));
// skip comma and space
++pos;
if (depends_string[pos] == ' ')
{
++pos;
}
cur = pos;
} while (cur != std::string::npos);
return out;
}
std::vector<std::string> filter_dependencies(const std::vector<vcpkg::dependency>& deps, const triplet& t)
{
std::vector<std::string> ret;
for (auto&& dep : deps)
{
if (dep.qualifier.empty() || t.canonical_name().find(dep.qualifier) != std::string::npos)
{
ret.push_back(dep.name);
}
}
return ret;
}
std::ostream & operator<<(std::ostream & os, const dependency & p)
{
os << p.name;
return os;
}
}

Просмотреть файл

@ -138,7 +138,16 @@ namespace vcpkg
const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str());
Input::check_triplet(spec.target_triplet(), paths);
std::unordered_set<package_spec> unmet_dependencies = Dependencies::find_unmet_dependencies(paths, spec, status_db);
// Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies).
auto first_level_deps = get_unmet_package_build_dependencies(paths, spec, status_db);
std::vector<package_spec> first_level_deps_specs;
for (auto&& dep : first_level_deps)
{
first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw());
}
std::unordered_set<package_spec> unmet_dependencies = Dependencies::find_unmet_dependencies(paths, first_level_deps_specs, status_db);
if (!unmet_dependencies.empty())
{
System::println(System::color::error, "The build command requires all dependencies to be already installed.");

Просмотреть файл

@ -209,29 +209,33 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar
// TODO: Refactoring between this function and install_package
std::vector<std::string> vcpkg::get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db)
{
std::vector<std::unordered_map<std::string, std::string>> pghs;
{
const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL";
const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL";
auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path);
if (auto control_contents = control_contents_maybe.get())
auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path);
if (auto control_contents = control_contents_maybe.get())
{
std::vector<std::unordered_map<std::string, std::string>> pghs;
try
{
try
{
pghs = parse_paragraphs(*control_contents);
}
catch (std::runtime_error)
{
}
Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string());
return BinaryParagraph(pghs[0]).depends;
pghs = parse_paragraphs(*control_contents);
}
catch (std::runtime_error)
{
}
Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string());
return BinaryParagraph(pghs[0]).depends;
}
return get_unmet_package_build_dependencies(paths, spec, status_db);
}
std::vector<std::string> vcpkg::get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db)
{
const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL";
auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path);
if (auto control_contents = control_contents_maybe.get())
{
std::vector<std::unordered_map<std::string, std::string>> pghs;
try
{
pghs = parse_paragraphs(*control_contents);
@ -240,7 +244,7 @@ std::vector<std::string> vcpkg::get_unmet_package_dependencies(const vcpkg_paths
{
}
Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string());
return SourceParagraph(pghs[0]).depends;
return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet());
}
Checks::exit_with_message("Could not find package named %s", spec);
@ -252,11 +256,11 @@ void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& bin
spgh.package = binary_paragraph;
spgh.want = want_t::install;
spgh.state = install_state_t::half_installed;
for (const std::string& dependency : spgh.package.depends)
for (auto&& dep : spgh.package.depends)
{
if (status_db.find_installed(dependency, spgh.package.spec.target_triplet()) == status_db.end())
if (status_db.find_installed(dep, spgh.package.spec.target_triplet()) == status_db.end())
{
std::abort();
Checks::unreachable();
}
}
write_update(paths, spgh);

Просмотреть файл

@ -0,0 +1,39 @@
#include "CppUnitTest.h"
#include "SourceParagraph.h"
#include "triplet.h"
#pragma comment(lib,"version")
#pragma comment(lib,"winhttp")
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace vcpkg;
namespace UnitTest1
{
TEST_CLASS(DependencyTests)
{
public:
TEST_METHOD(parse_depends_one)
{
auto v = expand_qualified_dependencies(parse_depends("libA [windows]"));
Assert::AreEqual(size_t(1), v.size());
Assert::AreEqual("libA", v[0].name.c_str());
Assert::AreEqual("windows", v[0].qualifier.c_str());
}
TEST_METHOD(filter_depends)
{
auto deps = expand_qualified_dependencies(parse_depends("libA [windows], libB, libC [uwp]"));
auto v = filter_dependencies(deps, triplet::X64_WINDOWS);
Assert::AreEqual(size_t(2), v.size());
Assert::AreEqual("libA", v[0].c_str());
Assert::AreEqual("libB", v[1].c_str());
auto v2 = filter_dependencies(deps, triplet::ARM_UWP);
Assert::AreEqual(size_t(2), v.size());
Assert::AreEqual("libB", v2[0].c_str());
Assert::AreEqual("libC", v2[1].c_str());
}
};
}

Просмотреть файл

@ -48,7 +48,7 @@ namespace UnitTest1
Assert::AreEqual("m", pgh.maintainer.c_str());
Assert::AreEqual("d", pgh.description.c_str());
Assert::AreEqual(size_t(1), pgh.depends.size());
Assert::AreEqual("bd", pgh.depends[0].c_str());
Assert::AreEqual("bd", pgh.depends[0].name.c_str());
}
TEST_METHOD(SourceParagraph_Two_Depends)
@ -60,8 +60,8 @@ namespace UnitTest1
});
Assert::AreEqual(size_t(2), pgh.depends.size());
Assert::AreEqual("z", pgh.depends[0].c_str());
Assert::AreEqual("openssl", pgh.depends[1].c_str());
Assert::AreEqual("z", pgh.depends[0].name.c_str());
Assert::AreEqual("openssl", pgh.depends[1].name.c_str());
}
TEST_METHOD(SourceParagraph_Three_Depends)
@ -73,17 +73,37 @@ namespace UnitTest1
});
Assert::AreEqual(size_t(3), pgh.depends.size());
Assert::AreEqual("z", pgh.depends[0].c_str());
Assert::AreEqual("openssl", pgh.depends[1].c_str());
Assert::AreEqual("xyz", pgh.depends[2].c_str());
Assert::AreEqual("z", pgh.depends[0].name.c_str());
Assert::AreEqual("openssl", pgh.depends[1].name.c_str());
Assert::AreEqual("xyz", pgh.depends[2].name.c_str());
}
TEST_METHOD(SourceParagraph_Construct_Qualified_Depends)
{
vcpkg::SourceParagraph pgh({
{ "Source", "zlib" },
{ "Version", "1.2.8" },
{ "Build-Depends", "libA [windows], libB [uwp]" }
});
Assert::AreEqual("zlib", pgh.name.c_str());
Assert::AreEqual("1.2.8", pgh.version.c_str());
Assert::AreEqual("", pgh.maintainer.c_str());
Assert::AreEqual("", pgh.description.c_str());
Assert::AreEqual(size_t(2), pgh.depends.size());
Assert::AreEqual("libA", pgh.depends[0].name.c_str());
Assert::AreEqual("windows", pgh.depends[0].qualifier.c_str());
Assert::AreEqual("libB", pgh.depends[1].name.c_str());
Assert::AreEqual("uwp", pgh.depends[1].qualifier.c_str());
}
TEST_METHOD(BinaryParagraph_Construct_Minimum)
{
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
});
@ -91,7 +111,7 @@ namespace UnitTest1
Assert::AreEqual("1.2.8", pgh.version.c_str());
Assert::AreEqual("", pgh.maintainer.c_str());
Assert::AreEqual("", pgh.description.c_str());
Assert::AreEqual("a", pgh.spec.target_triplet().canonical_name().c_str());
Assert::AreEqual("x86-windows", pgh.spec.target_triplet().canonical_name().c_str());
Assert::AreEqual(size_t(0), pgh.depends.size());
}
@ -100,7 +120,7 @@ namespace UnitTest1
vcpkg::BinaryParagraph pgh({
{"Package", "s"},
{"Version", "v"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Maintainer", "m"},
{"Description", "d"},
@ -119,7 +139,7 @@ namespace UnitTest1
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", "a, b, c"},
});
@ -253,7 +273,7 @@ namespace UnitTest1
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
});
ss << pgh;
@ -262,7 +282,7 @@ namespace UnitTest1
Assert::AreEqual(size_t(4), pghs[0].size());
Assert::AreEqual("zlib", pghs[0]["Package"].c_str());
Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str());
Assert::AreEqual("a", pghs[0]["Architecture"].c_str());
Assert::AreEqual("x86-windows", pghs[0]["Architecture"].c_str());
Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str());
}
@ -272,7 +292,7 @@ namespace UnitTest1
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Description", "first line\n second line"},
{"Maintainer", "abc <abc@abc.abc>"},
{"Depends", "dep"},
@ -284,7 +304,7 @@ namespace UnitTest1
Assert::AreEqual(size_t(7), pghs[0].size());
Assert::AreEqual("zlib", pghs[0]["Package"].c_str());
Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str());
Assert::AreEqual("a", pghs[0]["Architecture"].c_str());
Assert::AreEqual("x86-windows", pghs[0]["Architecture"].c_str());
Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str());
Assert::AreEqual("first line\n second line", pghs[0]["Description"].c_str());
Assert::AreEqual("dep", pghs[0]["Depends"].c_str());
@ -296,7 +316,7 @@ namespace UnitTest1
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "a"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", "a, b, c"},
});

Просмотреть файл

@ -8,6 +8,9 @@ namespace vcpkg {namespace Checks
void unreachable()
{
System::println(System::color::error, "Error: Unreachable code was reached");
#ifndef NDEBUG
std::abort();
#endif
exit(EXIT_FAILURE);
}

Просмотреть файл

@ -57,11 +57,9 @@ namespace vcpkg { namespace Dependencies
return build_dependency_graph(paths, specs, status_db).find_topological_sort();
}
std::unordered_set<package_spec> find_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db)
std::unordered_set<package_spec> find_unmet_dependencies(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db)
{
const Graphs::Graph<package_spec> dependency_graph = build_dependency_graph(paths, {spec}, status_db);
std::unordered_set<package_spec> key_set = Maps::extract_key_set(dependency_graph.adjacency_list());
key_set.erase(spec);
return key_set;
const Graphs::Graph<package_spec> dependency_graph = build_dependency_graph(paths, specs, status_db);
return Maps::extract_key_set(dependency_graph.adjacency_list());
}
}}

Просмотреть файл

@ -45,37 +45,4 @@ namespace vcpkg {namespace details
return value;
}
std::vector<std::string> parse_depends(const std::string& depends_string)
{
if (depends_string.empty())
{
return {};
}
std::vector<std::string> out;
size_t cur = 0;
do
{
auto pos = depends_string.find(',', cur);
if (pos == std::string::npos)
{
out.push_back(depends_string.substr(cur));
break;
}
out.push_back(depends_string.substr(cur, pos - cur));
// skip comma and space
++pos;
if (depends_string[pos] == ' ')
{
++pos;
}
cur = pos;
}
while (cur != std::string::npos);
return out;
}
}}

Просмотреть файл

@ -19,7 +19,8 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\test.cpp" />
<ClCompile Include="..\src\tests_dependencies.cpp" />
<ClCompile Include="..\src\tests_paragraph.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\vcpkgcommon\vcpkgcommon.vcxproj">
@ -116,7 +117,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\include;$(VCInstallDir)UnitTest\include;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UseFullPaths>true</UseFullPaths>
<PrecompiledHeaderFile />

Просмотреть файл

@ -15,7 +15,10 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\test.cpp">
<ClCompile Include="..\src\tests_paragraph.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\tests_dependencies.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>