From 90876a3bfef586a20e475d5ef812bac843e7a1a8 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 15:43:09 -0700 Subject: [PATCH] SourceParagraph checks fields at construction time --- toolsrc/include/SourceParagraph.h | 1 - toolsrc/src/SourceParagraph.cpp | 16 +++++++++++++++- toolsrc/src/commands_installation.cpp | 14 -------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 6aae818722..9c9439ea7f 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -18,6 +18,5 @@ namespace vcpkg std::string description; std::string maintainer; std::vector depends; - std::unordered_map unparsed_fields; }; } diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 34d2a81707..1fa50e233e 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -1,5 +1,7 @@ #include "SourceParagraph.h" #include "vcpkglib_helpers.h" +#include "vcpkg_System.h" +#include "vcpkg_Maps.h" namespace vcpkg { @@ -45,6 +47,18 @@ namespace vcpkg std::string deps = remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); this->depends = parse_depends(deps); - this->unparsed_fields = std::move(fields); + if (!fields.empty()) + { + const std::vector remaining_fields = Maps::extract_keys(fields); + const std::vector& valid_fields = get_list_of_valid_fields(); + + const std::string remaining_fields_as_string = Strings::join(remaining_fields, "\n "); + const std::string valid_fields_as_string = Strings::join(valid_fields, "\n "); + + 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); + exit(EXIT_FAILURE); + } } } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 22309cabf6..022b871390 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -25,20 +25,6 @@ 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 remaining_keys = Maps::extract_keys(source_paragraph.unparsed_fields); - const std::vector& valid_entries = SourceParagraph::get_list_of_valid_fields(); - - 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 port file %s", port_dir.generic_string()); - 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")",