diff options
| author | mmazaherit <m.mazaheri.t@gmail.com> | 2017-06-08 23:53:58 -0400 |
|---|---|---|
| committer | mmazaherit <m.mazaheri.t@gmail.com> | 2017-06-08 23:53:58 -0400 |
| commit | e544b742903ddceba71d4652f30a9df4baca598e (patch) | |
| tree | 824fdf1bca936d845c20b51a140e9f60629653cb /toolsrc/src/SourceParagraph.cpp | |
| parent | 9b57ecbdd786113e33d8a149d240769682c7846e (diff) | |
| parent | ff52016d018c9d346cd402e9cc98d24dff39d900 (diff) | |
| download | vcpkg-e544b742903ddceba71d4652f30a9df4baca598e.tar.gz vcpkg-e544b742903ddceba71d4652f30a9df4baca598e.zip | |
Merge branch 'master' of https://github.com/mmazat/vcpkg
Diffstat (limited to 'toolsrc/src/SourceParagraph.cpp')
| -rw-r--r-- | toolsrc/src/SourceParagraph.cpp | 126 |
1 files changed, 96 insertions, 30 deletions
diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index d140ce72b..2508af1e8 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -5,6 +5,9 @@ #include "vcpkg_Checks.h" #include "vcpkg_Maps.h" #include "vcpkg_System.h" +#include "vcpkg_Util.h" +#include "vcpkg_expected.h" + #include "vcpkglib_helpers.h" namespace vcpkg @@ -21,6 +24,7 @@ namespace vcpkg static const std::string DESCRIPTION = "Description"; static const std::string MAINTAINER = "Maintainer"; static const std::string BUILD_DEPENDS = "Build-Depends"; + static const std::string SUPPORTS = "Supports"; } static const std::vector<std::string>& get_list_of_valid_fields() @@ -30,22 +34,51 @@ namespace vcpkg SourceParagraphOptionalField::DESCRIPTION, SourceParagraphOptionalField::MAINTAINER, - SourceParagraphOptionalField::BUILD_DEPENDS}; + SourceParagraphOptionalField::BUILD_DEPENDS, + SourceParagraphOptionalField::SUPPORTS}; return valid_fields; } - SourceParagraph::SourceParagraph() = default; + void print_error_message(const ParseControlErrorInfo& info) + { + System::println( + System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", info.name); + System::println("The following fields were not expected:\n\n %s\n\n", info.remaining_fields_as_string); + System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", info.valid_fields_as_string); + System::println("Different source may be available for vcpkg. Use .\\bootstrap-vcpkg.bat to update.\n"); + } + + void print_error_message(std::vector<ParseControlErrorInfo> error_info_list) + { + if (error_info_list.size() == 0) return; + for (ParseControlErrorInfo error_info : error_info_list) + { + System::println( + System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", error_info.name); + System::println("The following fields were not expected:\n\n %s\n\n", + error_info.remaining_fields_as_string); + } + + System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", + error_info_list.front().valid_fields_as_string); + System::println("Different source may be available for vcpkg. Use .\\bootstrap-vcpkg.bat to update.\n"); + } - SourceParagraph::SourceParagraph(std::unordered_map<std::string, std::string> fields) + ExpectedT<SourceParagraph, ParseControlErrorInfo> SourceParagraph::parse_control_file( + std::unordered_map<std::string, std::string> fields) { - this->name = details::remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); - this->version = details::remove_required_field(&fields, SourceParagraphRequiredField::VERSION); - this->description = details::remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION); - this->maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); + SourceParagraph sparagraph; + sparagraph.name = details::remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); + sparagraph.version = details::remove_required_field(&fields, SourceParagraphRequiredField::VERSION); + sparagraph.description = details::remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION); + sparagraph.maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); std::string deps = details::remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); - this->depends = expand_qualified_dependencies(parse_depends(deps)); + sparagraph.depends = expand_qualified_dependencies(parse_comma_list(deps)); + + std::string sups = details::remove_optional_field(&fields, SourceParagraphOptionalField::SUPPORTS); + sparagraph.supports = parse_comma_list(sups); if (!fields.empty()) { @@ -55,17 +88,14 @@ namespace vcpkg const std::string remaining_fields_as_string = Strings::join("\n ", remaining_fields); const std::string valid_fields_as_string = Strings::join("\n ", valid_fields); - System::println( - System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", this->name); - System::println("The following fields were not expected:\n\n %s\n\n", remaining_fields_as_string); - System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_fields_as_string); - Checks::exit_fail(VCPKG_LINE_INFO); + return ParseControlErrorInfo{sparagraph.name, remaining_fields_as_string, valid_fields_as_string}; } + return sparagraph; } std::vector<Dependency> vcpkg::expand_qualified_dependencies(const std::vector<std::string>& depends) { - auto convert = [&](const std::string& depend_string) -> Dependency { + return Util::fmap(depends, [&](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+\]" @@ -78,21 +108,12 @@ namespace vcpkg } 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) + std::vector<std::string> parse_comma_list(const std::string& str) { - if (depends_string.empty()) + if (str.empty()) { return {}; } @@ -102,17 +123,17 @@ namespace vcpkg size_t cur = 0; do { - auto pos = depends_string.find(',', cur); + auto pos = str.find(',', cur); if (pos == std::string::npos) { - out.push_back(depends_string.substr(cur)); + out.push_back(str.substr(cur)); break; } - out.push_back(depends_string.substr(cur, pos - cur)); + out.push_back(str.substr(cur, pos - cur)); // skip comma and space ++pos; - if (depends_string[pos] == ' ') + if (str[pos] == ' ') { ++pos; } @@ -137,4 +158,49 @@ namespace vcpkg } const std::string& to_string(const Dependency& dep) { return dep.name; } + + ExpectedT<Supports, std::vector<std::string>> Supports::parse(const std::vector<std::string>& strs) + { + Supports ret; + std::vector<std::string> unrecognized; + + for (auto&& str : strs) + { + if (str == "x64") + ret.architectures.push_back(Architecture::X64); + else if (str == "x86") + ret.architectures.push_back(Architecture::X86); + else if (str == "arm") + ret.architectures.push_back(Architecture::ARM); + else if (str == "windows") + ret.platforms.push_back(Platform::WINDOWS); + else if (str == "uwp") + ret.platforms.push_back(Platform::UWP); + else if (str == "v140") + ret.toolsets.push_back(ToolsetVersion::V140); + else if (str == "v141") + ret.toolsets.push_back(ToolsetVersion::V141); + else if (str == "crt-static") + ret.crt_linkages.push_back(Linkage::STATIC); + else if (str == "crt-dynamic") + ret.crt_linkages.push_back(Linkage::DYNAMIC); + else + unrecognized.push_back(str); + } + + if (unrecognized.empty()) + return std::move(ret); + else + return std::move(unrecognized); + } + + bool Supports::supports(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools) + { + auto is_in_or_empty = [](auto v, auto&& c) -> bool { return c.empty() || c.end() != Util::find(c, v); }; + if (!is_in_or_empty(arch, architectures)) return false; + if (!is_in_or_empty(plat, platforms)) return false; + if (!is_in_or_empty(crt, crt_linkages)) return false; + if (!is_in_or_empty(tools, toolsets)) return false; + return true; + } } |
