Add checks for fields in CONTROL file. Resolves #228

This commit is contained in:
Alexander Karatarakis 2016-11-02 20:26:52 -07:00
Родитель 079a027b1e
Коммит 4665b16ab3
5 изменённых файлов: 92 добавлений и 15 удалений

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

@ -7,14 +7,17 @@ namespace vcpkg
{
struct SourceParagraph
{
static const std::vector<std::string>& get_list_of_valid_entries();
SourceParagraph();
explicit SourceParagraph(const std::unordered_map<std::string, std::string>& fields);
explicit SourceParagraph(std::unordered_map<std::string, std::string> fields);
std::string name;
std::string version;
std::string description;
std::string maintainer;
std::vector<std::string> depends;
std::unordered_map<std::string, std::string> unparsed_fields;
};
}

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

@ -5,8 +5,10 @@
namespace vcpkg {namespace details
{
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname);
std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname);
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);
}}

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

@ -1,16 +1,50 @@
#include "SourceParagraph.h"
#include "vcpkglib_helpers.h"
using namespace vcpkg::details;
vcpkg::SourceParagraph::SourceParagraph() = default;
vcpkg::SourceParagraph::SourceParagraph(const std::unordered_map<std::string, std::string>& fields):
name(required_field(fields, "Source")),
version(required_field(fields, "Version")),
description(optional_field(fields, "Description")),
maintainer(optional_field(fields, "Maintainer"))
namespace vcpkg
{
std::string deps = optional_field(fields, "Build-Depends");
this->depends = parse_depends(deps);
//
namespace SourceParagraphRequiredField
{
static const std::string SOURCE = "Source";
static const std::string VERSION = "Version";
}
namespace SourceParagraphOptionalEntry
{
static const std::string DESCRIPTION = "Description";
static const std::string MAINTAINER = "Maintainer";
static const std::string BUILD_DEPENDS = "Build-Depends";
}
const std::vector<std::string>& SourceParagraph::get_list_of_valid_entries()
{
static const std::vector<std::string> valid_enties =
{
SourceParagraphRequiredField::SOURCE,
SourceParagraphRequiredField::VERSION,
SourceParagraphOptionalEntry::DESCRIPTION,
SourceParagraphOptionalEntry::MAINTAINER,
SourceParagraphOptionalEntry::BUILD_DEPENDS
};
return valid_enties;
}
SourceParagraph::SourceParagraph() = default;
SourceParagraph::SourceParagraph(std::unordered_map<std::string, std::string> fields)
{
using namespace vcpkg::details;
this->name = remove_required_field(&fields, SourceParagraphRequiredField::SOURCE);
this->version = remove_required_field(&fields, SourceParagraphRequiredField::VERSION);
this->description = remove_optional_field(&fields, SourceParagraphOptionalEntry::DESCRIPTION);
this->maintainer = remove_optional_field(&fields, SourceParagraphOptionalEntry::MAINTAINER);
std::string deps = remove_optional_field(&fields, SourceParagraphOptionalEntry::BUILD_DEPENDS);
this->depends = parse_depends(deps);
this->unparsed_fields = std::move(fields);
}
}

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

@ -8,6 +8,7 @@
#include "vcpkg_System.h"
#include "vcpkg_Dependencies.h"
#include "vcpkg_Input.h"
#include "vcpkg_Maps.h"
namespace vcpkg
{
@ -24,6 +25,20 @@ namespace vcpkg
Checks::check_exit(pghs.size() == 1, "Error: invalid control file");
SourceParagraph source_paragraph(pghs[0]);
if (!source_paragraph.unparsed_fields.empty())
{
const std::vector<std::string> remaining_keys = Maps::extract_keys(source_paragraph.unparsed_fields);
const std::vector<std::string>& valid_entries = SourceParagraph::get_list_of_valid_entries();
const std::string remaining_keys_as_string = Strings::join(remaining_keys, "\n ");
const std::string valid_keys_as_string = Strings::join(valid_entries, "\n ");
System::println(System::color::error, "Error: There are invalid fields in the port file");
System::println("The following fields were not expected in the port file:\n\n %s\n\n", remaining_keys_as_string);
System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_keys_as_string);
exit(EXIT_FAILURE);
}
const fs::path ports_cmake_script_path = paths.ports_cmake;
auto&& target_triplet = spec.target_triplet();
const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")",

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

@ -13,14 +13,37 @@ namespace vcpkg {namespace details
}
return it->second;
};
}
std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname)
{
auto it = fields->find(fieldname);
if (it == fields->end())
{
return std::string();
}
const std::string value = std::move(it->second);
fields->erase(it);
return value;
}
std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
{
auto it = fields.find(fieldname);
vcpkg::Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname);
Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname);
return it->second;
};
}
std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname)
{
auto it = fields->find(fieldname);
Checks::check_exit(it != fields->end(), "Required field not present: %s", fieldname);
const std::string value = std::move(it->second);
fields->erase(it);
return value;
}
std::vector<std::string> parse_depends(const std::string& depends_string)
{