2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
#include "BinaryParagraph.h"
|
|
|
|
#include "vcpkg_Checks.h"
|
2017-06-17 17:39:14 +08:00
|
|
|
#include "vcpkg_Parse.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
2017-06-17 17:39:14 +08:00
|
|
|
namespace Fields
|
2016-11-04 08:36:47 +08:00
|
|
|
{
|
|
|
|
static const std::string PACKAGE = "Package";
|
|
|
|
static const std::string VERSION = "Version";
|
|
|
|
static const std::string ARCHITECTURE = "Architecture";
|
|
|
|
static const std::string MULTI_ARCH = "Multi-Arch";
|
|
|
|
}
|
|
|
|
|
2017-06-17 17:39:14 +08:00
|
|
|
namespace Fields
|
2016-11-04 08:36:47 +08:00
|
|
|
{
|
2017-07-13 08:40:41 +08:00
|
|
|
static const std::string FEATURE = "Feature";
|
2016-11-04 08:36:47 +08:00
|
|
|
static const std::string DESCRIPTION = "Description";
|
|
|
|
static const std::string MAINTAINER = "Maintainer";
|
|
|
|
static const std::string DEPENDS = "Depends";
|
2017-07-13 08:40:41 +08:00
|
|
|
static const std::string DEFAULTFEATURES = "Default-Features";
|
2016-11-04 08:36:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
BinaryParagraph::BinaryParagraph() = default;
|
|
|
|
|
2016-11-04 08:36:47 +08:00
|
|
|
BinaryParagraph::BinaryParagraph(std::unordered_map<std::string, std::string> fields)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-06-17 17:39:14 +08:00
|
|
|
using namespace vcpkg::Parse;
|
2016-11-04 08:36:47 +08:00
|
|
|
|
2017-06-17 17:39:14 +08:00
|
|
|
ParagraphParser parser(std::move(fields));
|
2016-10-05 06:16:07 +08:00
|
|
|
|
2017-06-17 17:39:14 +08:00
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
parser.required_field(Fields::PACKAGE, name);
|
|
|
|
std::string architecture;
|
|
|
|
parser.required_field(Fields::ARCHITECTURE, architecture);
|
|
|
|
this->spec = PackageSpec::from_name_and_triplet(name, Triplet::from_canonical_name(architecture))
|
|
|
|
.value_or_exit(VCPKG_LINE_INFO);
|
|
|
|
}
|
2016-11-04 08:36:47 +08:00
|
|
|
|
2017-07-13 08:40:41 +08:00
|
|
|
// one or the other
|
|
|
|
this->version = parser.optional_field(Fields::VERSION);
|
|
|
|
this->feature = parser.optional_field(Fields::FEATURE);
|
|
|
|
|
2017-06-17 17:39:14 +08:00
|
|
|
this->description = parser.optional_field(Fields::DESCRIPTION);
|
|
|
|
this->maintainer = parser.optional_field(Fields::MAINTAINER);
|
|
|
|
|
|
|
|
std::string multi_arch;
|
|
|
|
parser.required_field(Fields::MULTI_ARCH, multi_arch);
|
2016-09-27 12:12:04 +08:00
|
|
|
|
2017-06-17 17:39:14 +08:00
|
|
|
this->depends = parse_comma_list(parser.optional_field(Fields::DEPENDS));
|
2017-07-13 08:40:41 +08:00
|
|
|
if (this->feature.empty())
|
|
|
|
{
|
|
|
|
this->default_features = parse_comma_list(parser.optional_field(Fields::DEFAULTFEATURES));
|
|
|
|
}
|
2017-06-17 17:39:14 +08:00
|
|
|
|
2017-08-29 08:10:50 +08:00
|
|
|
if (const auto err = parser.error_info(this->spec.to_string()))
|
2017-06-17 17:39:14 +08:00
|
|
|
{
|
2017-08-09 05:00:03 +08:00
|
|
|
System::println(
|
|
|
|
System::Color::error, "Error: while parsing the Binary Paragraph for %s", this->spec.to_string());
|
2017-06-17 17:39:14 +08:00
|
|
|
print_error_message(err);
|
|
|
|
Checks::exit_fail(VCPKG_LINE_INFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
// prefer failing above when possible because it gives better information
|
|
|
|
Checks::check_exit(VCPKG_LINE_INFO, multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-11 04:06:44 +08:00
|
|
|
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-11 04:06:44 +08:00
|
|
|
this->spec = PackageSpec::from_name_and_triplet(spgh.name, triplet).value_or_exit(VCPKG_LINE_INFO);
|
2016-09-19 11:50:08 +08:00
|
|
|
this->version = spgh.version;
|
|
|
|
this->description = spgh.description;
|
|
|
|
this->maintainer = spgh.maintainer;
|
2017-04-11 04:06:44 +08:00
|
|
|
this->depends = filter_dependencies(spgh.depends, triplet);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 05:29:28 +08:00
|
|
|
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const FeatureParagraph& fpgh, const Triplet& triplet)
|
|
|
|
{
|
|
|
|
this->spec = PackageSpec::from_name_and_triplet(spgh.name, triplet).value_or_exit(VCPKG_LINE_INFO);
|
2017-08-29 09:46:28 +08:00
|
|
|
this->version = Strings::EMPTY;
|
2017-07-20 05:29:28 +08:00
|
|
|
this->feature = fpgh.name;
|
|
|
|
this->description = fpgh.description;
|
2017-08-29 09:46:28 +08:00
|
|
|
this->maintainer = Strings::EMPTY;
|
2017-07-20 05:29:28 +08:00
|
|
|
this->depends = filter_dependencies(fpgh.depends, triplet);
|
|
|
|
}
|
|
|
|
|
2017-07-26 12:29:31 +08:00
|
|
|
std::string BinaryParagraph::displayname() const
|
|
|
|
{
|
2017-08-29 09:55:27 +08:00
|
|
|
const auto f = Strings::is_empty(this->feature) ? "core" : this->feature;
|
|
|
|
return Strings::format("%s[%s]:%s", this->spec.name(), f, this->spec.triplet());
|
2017-07-26 12:29:31 +08:00
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
std::string BinaryParagraph::dir() const { return this->spec.dir(); }
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
std::string BinaryParagraph::fullstem() const
|
|
|
|
{
|
2017-04-11 04:03:34 +08:00
|
|
|
return Strings::format("%s_%s_%s", this->spec.name(), this->version, this->spec.triplet());
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:48:52 +08:00
|
|
|
void serialize(const BinaryParagraph& pgh, std::string& out_str)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 13:48:52 +08:00
|
|
|
out_str.append("Package: ").append(pgh.spec.name()).push_back('\n');
|
2017-07-20 05:29:28 +08:00
|
|
|
if (!pgh.version.empty())
|
|
|
|
out_str.append("Version: ").append(pgh.version).push_back('\n');
|
|
|
|
else if (!pgh.feature.empty())
|
|
|
|
out_str.append("Feature: ").append(pgh.feature).push_back('\n');
|
2017-04-13 13:48:52 +08:00
|
|
|
if (!pgh.depends.empty())
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 13:48:52 +08:00
|
|
|
out_str.append("Depends: ");
|
|
|
|
out_str.append(Strings::join(", ", pgh.depends));
|
|
|
|
out_str.push_back('\n');
|
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-13 13:48:52 +08:00
|
|
|
out_str.append("Architecture: ").append(pgh.spec.triplet().to_string()).push_back('\n');
|
|
|
|
out_str.append("Multi-Arch: same\n");
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
if (!pgh.maintainer.empty()) out_str.append("Maintainer: ").append(pgh.maintainer).push_back('\n');
|
|
|
|
if (!pgh.description.empty()) out_str.append("Description: ").append(pgh.description).push_back('\n');
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|