BinaryParagraph now contains a package_spec instead of name+triplet

This commit is contained in:
Alexander Karatarakis 2016-10-04 15:16:07 -07:00
parent e383b39637
commit 429e2eca4a
6 changed files with 38 additions and 34 deletions

View File

@ -3,6 +3,7 @@
#include <unordered_map>
#include "SourceParagraph.h"
#include "triplet.h"
#include "package_spec.h"
namespace vcpkg
{
@ -18,11 +19,10 @@ namespace vcpkg
std::string dir() const;
std::string name;
package_spec spec;
std::string version;
std::string description;
std::string maintainer;
triplet target_triplet;
std::vector<std::string> depends;
};

View File

@ -9,12 +9,14 @@ namespace vcpkg
BinaryParagraph::BinaryParagraph() = default;
BinaryParagraph::BinaryParagraph(const std::unordered_map<std::string, std::string>& fields) :
name(required_field(fields, "Package")),
version(required_field(fields, "Version")),
description(optional_field(fields, "Description")),
maintainer(optional_field(fields, "Maintainer")),
target_triplet(triplet::from_canonical_name(required_field(fields, "Architecture")))
maintainer(optional_field(fields, "Maintainer"))
{
const std::string name = required_field(fields, "Package");
const triplet target_triplet = triplet::from_canonical_name(required_field(fields, "Architecture"));
this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_throw();
{
std::string multi_arch = required_field(fields, "Multi-Arch");
Checks::check_throw(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch);
@ -30,32 +32,31 @@ namespace vcpkg
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)
{
this->name = spgh.name;
this->spec = package_spec::from_name_and_triplet(spgh.name, target_triplet).get_or_throw();
this->version = spgh.version;
this->description = spgh.description;
this->maintainer = spgh.maintainer;
this->depends = spgh.depends;
this->target_triplet = target_triplet;
}
std::string BinaryParagraph::displayname() const
{
return Strings::format("%s:%s", this->name, this->target_triplet);
return Strings::format("%s:%s", this->spec.name(), this->spec.target_triplet());
}
std::string BinaryParagraph::dir() const
{
return Strings::format("%s_%s", this->name, this->target_triplet);
return this->spec.dir();
}
std::string BinaryParagraph::fullstem() const
{
return Strings::format("%s_%s_%s", this->name, this->version, this->target_triplet);
return Strings::format("%s_%s_%s", this->spec.name(), this->version, this->spec.target_triplet());
}
std::ostream& operator<<(std::ostream& os, const BinaryParagraph& p)
{
os << "Package: " << p.name << "\n";
os << "Package: " << p.spec.name() << "\n";
os << "Version: " << p.version << "\n";
if (!p.depends.empty())
{
@ -70,7 +71,7 @@ namespace vcpkg
os << "\n";
}
os << "Architecture: " << p.target_triplet << "\n";
os << "Architecture: " << p.spec.target_triplet() << "\n";
os << "Multi-Arch: same\n";
if (!p.maintainer.empty())
os << "Maintainer: " << p.maintainer << "\n";

View File

@ -15,7 +15,8 @@ namespace vcpkg
{
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
{
return pgh->package.name == name && pgh->package.target_triplet == target_triplet;
const package_spec& spec = pgh->package.spec;
return spec.name() == name && spec.target_triplet() == target_triplet;
});
}
@ -23,7 +24,8 @@ namespace vcpkg
{
return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh)
{
return pgh->package.name == name && pgh->package.target_triplet == target_triplet;
const package_spec& spec = pgh->package.spec;
return spec.name() == name && spec.target_triplet() == target_triplet;
});
}
@ -41,18 +43,17 @@ namespace vcpkg
StatusParagraphs::iterator StatusParagraphs::insert(std::unique_ptr<StatusParagraph> pgh)
{
Checks::check_throw(pgh != nullptr, "Inserted null paragraph");
auto ptr = find(pgh->package.name, pgh->package.target_triplet);
const package_spec& spec = pgh->package.spec;
auto ptr = find(spec.name(), spec.target_triplet());
if (ptr == end())
{
paragraphs.push_back(std::move(pgh));
return paragraphs.rbegin();
}
else
{
// consume data from provided pgh.
**ptr = std::move(*pgh);
return ptr;
}
// consume data from provided pgh.
**ptr = std::move(*pgh);
return ptr;
}
std::ostream& vcpkg::operator<<(std::ostream& os, const StatusParagraphs& l)

View File

@ -39,7 +39,7 @@ namespace vcpkg
{
if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge)
continue;
auto it = src_names_to_versions.find(pgh->package.name);
auto it = src_names_to_versions.find(pgh->package.spec.name());
if (it == src_names_to_versions.end())
{
// Package was not installed from portfile

View File

@ -135,7 +135,7 @@ static std::string get_fullpkgname_from_listfile(const fs::path& path)
static fs::path prefix_path_for_package(const vcpkg_paths& paths, const BinaryParagraph& pgh)
{
return paths.package_dir(package_spec::from_name_and_triplet(pgh.name, pgh.target_triplet).get_or_throw());
return paths.package_dir(pgh.spec);
}
static void write_update(const vcpkg_paths& paths, const StatusParagraph& p)
@ -157,9 +157,11 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar
auto package_prefix_path = prefix_path_for_package(paths, bpgh);
auto prefix_length = package_prefix_path.native().size();
const triplet& target_triplet = bpgh.spec.target_triplet();
const std::string& target_triplet_as_string = target_triplet.canonical_name();
std::error_code ec;
fs::create_directory(paths.installed / bpgh.target_triplet.canonical_name(), ec);
listfile << bpgh.target_triplet << "\n";
fs::create_directory(paths.installed / target_triplet_as_string, ec);
listfile << target_triplet << "\n";
for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it)
{
@ -171,7 +173,7 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar
}
auto suffix = it->path().generic_u8string().substr(prefix_length + 1);
auto target = paths.installed / bpgh.target_triplet.canonical_name() / suffix;
auto target = paths.installed / target_triplet_as_string / suffix;
auto status = it->status(ec);
if (ec)
@ -187,7 +189,7 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar
System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message());
}
listfile << bpgh.target_triplet << "/" << suffix << "\n";
listfile << target_triplet << "/" << suffix << "\n";
}
else if (fs::is_regular_file(status))
{
@ -196,7 +198,7 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar
{
System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message());
}
listfile << bpgh.target_triplet << "/" << suffix << "\n";
listfile << target_triplet << "/" << suffix << "\n";
}
else if (!fs::status_known(status))
{
@ -257,7 +259,7 @@ void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& bin
spgh.state = install_state_t::half_installed;
for (const std::string& dependency : spgh.package.depends)
{
if (status_db.find_installed(dependency, spgh.package.target_triplet) == status_db.end())
if (status_db.find_installed(dependency, spgh.package.spec.target_triplet()) == status_db.end())
{
std::abort();
}
@ -297,12 +299,12 @@ static deinstall_plan deinstall_package_plan(
{
if (inst_pkg->want != want_t::install)
continue;
if (inst_pkg->package.target_triplet != pkg.target_triplet)
if (inst_pkg->package.spec.target_triplet() != pkg.spec.target_triplet())
continue;
const auto& deps = inst_pkg->package.depends;
if (std::find(deps.begin(), deps.end(), pkg.name) != deps.end())
if (std::find(deps.begin(), deps.end(), pkg.spec.name()) != deps.end())
{
dependencies_out.push_back(inst_pkg.get());
}

View File

@ -87,11 +87,11 @@ namespace UnitTest1
{"Multi-Arch", "same"},
});
Assert::AreEqual("zlib", pgh.name.c_str());
Assert::AreEqual("zlib", pgh.spec.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("a", pgh.target_triplet.canonical_name().c_str());
Assert::AreEqual("a", pgh.spec.target_triplet().canonical_name().c_str());
Assert::AreEqual(size_t(0), pgh.depends.size());
}
@ -106,7 +106,7 @@ namespace UnitTest1
{"Description", "d"},
{"Depends", "bd"}
});
Assert::AreEqual("s", pgh.name.c_str());
Assert::AreEqual("s", pgh.spec.name().c_str());
Assert::AreEqual("v", pgh.version.c_str());
Assert::AreEqual("m", pgh.maintainer.c_str());
Assert::AreEqual("d", pgh.description.c_str());