aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-06-17 02:39:14 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-06-20 09:36:21 -0700
commit8741214bf69d1209a1e6d405ed8561d27f04436a (patch)
tree85325eb4b2d2c1c15eb8bd58426dac5462242d4e /toolsrc/include
parent8c4d55b8f304c74aeb95878cfe354830ff4abc88 (diff)
downloadvcpkg-8741214bf69d1209a1e6d405ed8561d27f04436a.tar.gz
vcpkg-8741214bf69d1209a1e6d405ed8561d27f04436a.zip
[vcpkg] Use unique_ptr<> for paragraphs. Post-parser phase rework.
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/Paragraphs.h28
-rw-r--r--toolsrc/include/SourceParagraph.h24
-rw-r--r--toolsrc/include/StatusParagraph.h2
-rw-r--r--toolsrc/include/vcpkg_Build.h10
-rw-r--r--toolsrc/include/vcpkg_Parse.h36
-rw-r--r--toolsrc/include/vcpkg_expected.h6
-rw-r--r--toolsrc/include/vcpkglib.h1
-rw-r--r--toolsrc/include/vcpkglib_helpers.h18
8 files changed, 72 insertions, 53 deletions
diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h
index 83a32b2af..60f509266 100644
--- a/toolsrc/include/Paragraphs.h
+++ b/toolsrc/include/Paragraphs.h
@@ -1,36 +1,38 @@
#pragma once
+#include <map>
+
#include "BinaryParagraph.h"
#include "VcpkgPaths.h"
#include "VersionT.h"
#include "filesystem_fs.h"
+#include "vcpkg_Parse.h"
#include "vcpkg_expected.h"
-#include <map>
namespace vcpkg::Paragraphs
{
- using ParagraphDataMap = std::unordered_map<std::string, std::string>;
+ using RawParagraph = Parse::RawParagraph;
- Expected<ParagraphDataMap> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path);
- Expected<std::vector<ParagraphDataMap>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path);
- Expected<ParagraphDataMap> parse_single_paragraph(const std::string& str);
- Expected<std::vector<ParagraphDataMap>> parse_paragraphs(const std::string& str);
+ Expected<RawParagraph> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path);
+ Expected<std::vector<RawParagraph>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path);
+ Expected<RawParagraph> parse_single_paragraph(const std::string& str);
+ Expected<std::vector<RawParagraph>> parse_paragraphs(const std::string& str);
- ExpectedT<SourceControlFile, ParseControlErrorInfo> try_load_port(const Files::Filesystem& fs,
- const fs::path& control_path);
+ Parse::ParseExpected<SourceControlFile> try_load_port(const Files::Filesystem& fs, const fs::path& control_path);
Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec);
struct LoadResults
{
- std::vector<SourceControlFile> paragraphs;
- std::vector<ParseControlErrorInfo> errors;
+ std::vector<std::unique_ptr<SourceControlFile>> paragraphs;
+ std::vector<std::unique_ptr<Parse::ParseControlErrorInfo>> errors;
};
LoadResults try_load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir);
- std::vector<SourceControlFile> load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir);
+ std::vector<std::unique_ptr<SourceControlFile>> load_all_ports(const Files::Filesystem& fs,
+ const fs::path& ports_dir);
- std::map<std::string, VersionT> extract_port_names_and_versions(
- const std::vector<SourceParagraph>& source_paragraphs);
+ std::map<std::string, VersionT> load_all_port_names_and_versions(const Files::Filesystem& fs,
+ const fs::path& ports_dir);
}
diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h
index 31c9560cc..e85884b51 100644
--- a/toolsrc/include/SourceParagraph.h
+++ b/toolsrc/include/SourceParagraph.h
@@ -1,6 +1,7 @@
#pragma once
#include "Span.h"
+#include "vcpkg_Parse.h"
#include "vcpkg_System.h"
#include "vcpkg_expected.h"
@@ -22,13 +23,6 @@ namespace vcpkg
const std::string& to_string(const Dependency& dep);
- struct ParseControlErrorInfo
- {
- std::string name;
- std::string remaining_fields_as_string;
- std::error_code error;
- };
-
struct FeatureParagraph
{
std::string name;
@@ -47,23 +41,19 @@ namespace vcpkg
std::string maintainer;
std::vector<std::string> supports;
std::vector<Dependency> depends;
- std::string default_features;
+ std::vector<std::string> default_features;
};
struct SourceControlFile
{
- static ExpectedT<SourceControlFile, ParseControlErrorInfo> parse_control_file(
- std::vector<std::unordered_map<std::string, std::string>>&& control_paragraphs);
+ static Parse::ParseExpected<SourceControlFile> parse_control_file(
+ std::vector<Parse::RawParagraph>&& control_paragraphs);
- SourceParagraph core_paragraph;
+ std::unique_ptr<SourceParagraph> core_paragraph;
std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs;
-
- std::vector<ParseControlErrorInfo> errors;
};
- std::vector<SourceParagraph> getSourceParagraphs(const std::vector<SourceControlFile>& control_files);
-
- void print_error_message(span<const ParseControlErrorInfo> error_info_list);
- inline void print_error_message(const ParseControlErrorInfo& error_info_list)
+ void print_error_message(span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list);
+ inline void print_error_message(const std::unique_ptr<Parse::ParseControlErrorInfo>& error_info_list)
{
return print_error_message({&error_info_list, 1});
}
diff --git a/toolsrc/include/StatusParagraph.h b/toolsrc/include/StatusParagraph.h
index 2d1815dc0..b56533d65 100644
--- a/toolsrc/include/StatusParagraph.h
+++ b/toolsrc/include/StatusParagraph.h
@@ -29,7 +29,7 @@ namespace vcpkg
struct StatusParagraph
{
StatusParagraph();
- explicit StatusParagraph(const std::unordered_map<std::string, std::string>& fields);
+ explicit StatusParagraph(std::unordered_map<std::string, std::string>&& fields);
BinaryParagraph package;
Want want;
diff --git a/toolsrc/include/vcpkg_Build.h b/toolsrc/include/vcpkg_Build.h
index e13f66029..9a4e2baeb 100644
--- a/toolsrc/include/vcpkg_Build.h
+++ b/toolsrc/include/vcpkg_Build.h
@@ -120,14 +120,20 @@ namespace vcpkg::Build
COUNT,
};
- Optional<BuildPolicy> to_build_policy(const std::string& str);
+ constexpr std::array<BuildPolicy, size_t(BuildPolicy::COUNT)> g_all_policies = {
+ BuildPolicy::EMPTY_PACKAGE,
+ BuildPolicy::DLLS_WITHOUT_LIBS,
+ BuildPolicy::ONLY_RELEASE_CRT,
+ BuildPolicy::EMPTY_INCLUDE_FOLDER,
+ BuildPolicy::ALLOW_OBSOLETE_MSVCRT,
+ };
const std::string& to_string(BuildPolicy policy);
CStringView to_cmake_variable(BuildPolicy policy);
struct BuildPolicies
{
- BuildPolicies() {}
+ BuildPolicies() = default;
BuildPolicies(std::map<BuildPolicy, bool>&& map) : m_policies(std::move(map)) {}
inline bool is_enabled(BuildPolicy policy) const
diff --git a/toolsrc/include/vcpkg_Parse.h b/toolsrc/include/vcpkg_Parse.h
new file mode 100644
index 000000000..a2eb152dc
--- /dev/null
+++ b/toolsrc/include/vcpkg_Parse.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <memory>
+#include <unordered_map>
+
+#include "vcpkg_expected.h"
+#include "vcpkg_optional.h"
+
+namespace vcpkg::Parse
+{
+ struct ParseControlErrorInfo
+ {
+ std::string name;
+ std::vector<std::string> missing_fields;
+ std::vector<std::string> extra_fields;
+ std::error_code error;
+ };
+
+ template<class P>
+ using ParseExpected = ExpectedT<std::unique_ptr<P>, std::unique_ptr<ParseControlErrorInfo>>;
+
+ using RawParagraph = std::unordered_map<std::string, std::string>;
+
+ struct ParagraphParser
+ {
+ ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {}
+
+ void required_field(const std::string& fieldname, std::string& out);
+ std::string optional_field(const std::string& fieldname);
+ std::unique_ptr<ParseControlErrorInfo> error_info(const std::string& name) const;
+
+ private:
+ RawParagraph&& fields;
+ std::vector<std::string> missing_fields;
+ };
+}
diff --git a/toolsrc/include/vcpkg_expected.h b/toolsrc/include/vcpkg_expected.h
index 15dbf5e79..9637ec087 100644
--- a/toolsrc/include/vcpkg_expected.h
+++ b/toolsrc/include/vcpkg_expected.h
@@ -9,8 +9,10 @@ namespace vcpkg
struct ErrorHolder
{
ErrorHolder() : m_is_error(false) {}
- ErrorHolder(const Err& err) : m_is_error(true), m_err(err) {}
- ErrorHolder(Err&& err) : m_is_error(true), m_err(std::move(err)) {}
+ template<class U>
+ ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward<U>(err))
+ {
+ }
constexpr bool has_error() const { return m_is_error; }
diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h
index df64e5463..bd2400b77 100644
--- a/toolsrc/include/vcpkglib.h
+++ b/toolsrc/include/vcpkglib.h
@@ -36,4 +36,5 @@ namespace vcpkg
const fs::path& cmake_script,
const std::vector<CMakeVariable>& pass_variables);
+ std::string shorten_description(const std::string& desc);
} // namespace vcpkg
diff --git a/toolsrc/include/vcpkglib_helpers.h b/toolsrc/include/vcpkglib_helpers.h
deleted file mode 100644
index a8ddcde4d..000000000
--- a/toolsrc/include/vcpkglib_helpers.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <unordered_map>
-
-namespace vcpkg::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::string shorten_description(const std::string& desc);
-}