diff options
| author | atkawa7 <atkawa7@yahoo.com> | 2017-06-14 08:29:12 -0700 |
|---|---|---|
| committer | atkawa7 <atkawa7@yahoo.com> | 2017-06-14 08:29:12 -0700 |
| commit | ce5ad1ffe1ed0c6351a09b01bc92a2ad258b8f19 (patch) | |
| tree | b64edb2fe7d020661b3fe30213eef2a967a60fd3 /toolsrc/src/SourceParagraph.cpp | |
| parent | 0a7fee0e8b0a637c83b9dd55bcb7a85c85779aba (diff) | |
| parent | c5ac9898999b712b7bac2fbc497825882d5e9011 (diff) | |
| download | vcpkg-ce5ad1ffe1ed0c6351a09b01bc92a2ad258b8f19.tar.gz vcpkg-ce5ad1ffe1ed0c6351a09b01bc92a2ad258b8f19.zip | |
Merge https://github.com/Microsoft/vcpkg
Diffstat (limited to 'toolsrc/src/SourceParagraph.cpp')
| -rw-r--r-- | toolsrc/src/SourceParagraph.cpp | 148 |
1 files changed, 111 insertions, 37 deletions
diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index d140ce72b..3b770a4b4 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,51 +24,86 @@ 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() + static span<const std::string> get_list_of_valid_fields() { - static const std::vector<std::string> valid_fields = {SourceParagraphRequiredField::SOURCE, - SourceParagraphRequiredField::VERSION, + static const std::string valid_fields[] = {SourceParagraphRequiredField::SOURCE, + SourceParagraphRequiredField::VERSION, - SourceParagraphOptionalField::DESCRIPTION, - SourceParagraphOptionalField::MAINTAINER, - SourceParagraphOptionalField::BUILD_DEPENDS}; + SourceParagraphOptionalField::DESCRIPTION, + SourceParagraphOptionalField::MAINTAINER, + SourceParagraphOptionalField::BUILD_DEPENDS, + SourceParagraphOptionalField::SUPPORTS}; return valid_fields; } - SourceParagraph::SourceParagraph() = default; + void print_error_message(span<const ParseControlErrorInfo> error_info_list) + { + Checks::check_exit(VCPKG_LINE_INFO, error_info_list.size() > 0); - SourceParagraph::SourceParagraph(std::unordered_map<std::string, std::string> fields) + for (auto&& error_info : error_info_list) + { + if (error_info.error) + { + System::println( + System::Color::error, "Error: while loading %s: %s", error_info.name, error_info.error.message()); + } + } + + bool have_remaining_fields = false; + for (auto&& error_info : error_info_list) + { + if (!error_info.remaining_fields_as_string.empty()) + { + 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); + have_remaining_fields = true; + } + } + + if (have_remaining_fields) + { + System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", + Strings::join("\n ", get_list_of_valid_fields())); + System::println("Different source may be available for vcpkg. Use .\\bootstrap-vcpkg.bat to update.\n"); + } + } + + 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()) { const std::vector<std::string> remaining_fields = Maps::extract_keys(fields); - const std::vector<std::string>& valid_fields = get_list_of_valid_fields(); 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}; } + 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 +116,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 +131,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 +166,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::is_supported(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; + } } |
