diff options
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/LineInfo.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/PackageSpec.h | 6 | ||||
| -rw-r--r-- | toolsrc/include/PackageSpecParseResult.h | 32 | ||||
| -rw-r--r-- | toolsrc/include/Paragraphs.h | 3 | ||||
| -rw-r--r-- | toolsrc/include/PostBuildLint_BuildType.h | 32 | ||||
| -rw-r--r-- | toolsrc/include/PostBuildLint_ConfigurationType.h | 36 | ||||
| -rw-r--r-- | toolsrc/include/PostBuildLint_LinkageType.h | 38 | ||||
| -rw-r--r-- | toolsrc/include/SourceParagraph.h | 54 | ||||
| -rw-r--r-- | toolsrc/include/VcpkgPaths.h | 9 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Build.h | 57 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Commands.h | 7 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Util.h | 6 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_expected.h | 79 |
13 files changed, 223 insertions, 138 deletions
diff --git a/toolsrc/include/LineInfo.h b/toolsrc/include/LineInfo.h index 66d91c520..62973462a 100644 --- a/toolsrc/include/LineInfo.h +++ b/toolsrc/include/LineInfo.h @@ -1,5 +1,7 @@ #pragma once +#include <string> + namespace vcpkg { struct LineInfo diff --git a/toolsrc/include/PackageSpec.h b/toolsrc/include/PackageSpec.h index 050d9d079..58edb8274 100644 --- a/toolsrc/include/PackageSpec.h +++ b/toolsrc/include/PackageSpec.h @@ -7,9 +7,11 @@ namespace vcpkg { struct PackageSpec { - static Expected<PackageSpec> from_string(const std::string& spec_as_string, const Triplet& default_triplet); + static ExpectedT<PackageSpec, PackageSpecParseResult> from_string(const std::string& spec_as_string, + const Triplet& default_triplet); static std::string to_string(const std::string& name, const Triplet& triplet); - static Expected<PackageSpec> from_name_and_triplet(const std::string& name, const Triplet& triplet); + static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name, + const Triplet& triplet); const std::string& name() const; diff --git a/toolsrc/include/PackageSpecParseResult.h b/toolsrc/include/PackageSpecParseResult.h index b72c534c2..1462b8073 100644 --- a/toolsrc/include/PackageSpecParseResult.h +++ b/toolsrc/include/PackageSpecParseResult.h @@ -1,5 +1,6 @@ #pragma once -#include <system_error> + +#include "vcpkg_expected.h" namespace vcpkg { @@ -10,27 +11,22 @@ namespace vcpkg INVALID_CHARACTERS }; - struct PackageSpecParseResultCategoryImpl final : std::error_category - { - virtual const char* name() const noexcept override; + CStringView to_string(PackageSpecParseResult ev) noexcept; - virtual std::string message(int ev) const noexcept override; - }; - - const std::error_category& package_spec_parse_result_category(); + template<> + struct ErrorHolder<PackageSpecParseResult> + { + ErrorHolder() : m_err(PackageSpecParseResult::SUCCESS) {} + ErrorHolder(PackageSpecParseResult err) : m_err(err) {} - std::error_code make_error_code(PackageSpecParseResult e); + constexpr bool has_error() const { return m_err != PackageSpecParseResult::SUCCESS; } - PackageSpecParseResult to_package_spec_parse_result(int i); + const PackageSpecParseResult& error() const { return m_err; } + PackageSpecParseResult& error() { return m_err; } - PackageSpecParseResult to_package_spec_parse_result(std::error_code ec); -} + CStringView to_string() const { return vcpkg::to_string(m_err); } -// Enable implicit conversion to std::error_code -namespace std -{ - template<> - struct is_error_code_enum<vcpkg::PackageSpecParseResult> : ::std::true_type - { + private: + PackageSpecParseResult m_err; }; } diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 66f6bd2e4..59f0eefc8 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -16,7 +16,8 @@ namespace vcpkg::Paragraphs Expected<ParagraphDataMap> parse_single_paragraph(const std::string& str); Expected<std::vector<ParagraphDataMap>> parse_paragraphs(const std::string& str); - Expected<SourceParagraph> try_load_port(const Files::Filesystem& fs, const fs::path& control_path); + ExpectedT<SourceParagraph, ParseControlErrorInfo> try_load_port(const Files::Filesystem& fs, + const fs::path& control_path); Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec); diff --git a/toolsrc/include/PostBuildLint_BuildType.h b/toolsrc/include/PostBuildLint_BuildType.h index 58bb20766..38ad3084e 100644 --- a/toolsrc/include/PostBuildLint_BuildType.h +++ b/toolsrc/include/PostBuildLint_BuildType.h @@ -1,12 +1,17 @@ #pragma once #include "CStringView.h" -#include "PostBuildLint_ConfigurationType.h" -#include "PostBuildLint_LinkageType.h" +#include "vcpkg_Build.h" #include <array> #include <regex> namespace vcpkg::PostBuildLint { + enum class ConfigurationType + { + DEBUG, + RELEASE, + }; + struct BuildType { enum class BackingEnum @@ -17,11 +22,13 @@ namespace vcpkg::PostBuildLint RELEASE_DYNAMIC }; - static BuildType value_of(const ConfigurationType& config, const LinkageType& linkage); + static BuildType value_of(const ConfigurationType& config, const Build::LinkageType& linkage); BuildType() = delete; - constexpr BuildType(const BackingEnum backing_enum, const ConfigurationType config, const LinkageType linkage) + constexpr BuildType(const BackingEnum backing_enum, + const ConfigurationType config, + const Build::LinkageType linkage) : backing_enum(backing_enum), m_config(config), m_linkage(linkage) { } @@ -29,28 +36,29 @@ namespace vcpkg::PostBuildLint constexpr operator BackingEnum() const { return backing_enum; } const ConfigurationType& config() const; - const LinkageType& linkage() const; + const Build::LinkageType& linkage() const; const std::regex& crt_regex() const; const std::string& to_string() const; private: BackingEnum backing_enum; ConfigurationType m_config; - LinkageType m_linkage; + Build::LinkageType m_linkage; }; namespace BuildTypeC { - namespace CC = ConfigurationTypeC; - namespace LC = LinkageTypeC; + using Build::LinkageType; using BE = BuildType::BackingEnum; static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::BuildType"; - static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, CC::DEBUG, LC::STATIC}; - static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, CC::DEBUG, LC::DYNAMIC}; - static constexpr BuildType RELEASE_STATIC = {BE::RELEASE_STATIC, CC::RELEASE, LC::STATIC}; - static constexpr BuildType RELEASE_DYNAMIC = {BE::RELEASE_DYNAMIC, CC::RELEASE, LC::DYNAMIC}; + static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageType::STATIC}; + static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageType::DYNAMIC}; + static constexpr BuildType RELEASE_STATIC = { + BE::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageType::STATIC}; + static constexpr BuildType RELEASE_DYNAMIC = { + BE::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageType::DYNAMIC}; static constexpr std::array<BuildType, 4> VALUES = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC}; diff --git a/toolsrc/include/PostBuildLint_ConfigurationType.h b/toolsrc/include/PostBuildLint_ConfigurationType.h deleted file mode 100644 index 8157415b0..000000000 --- a/toolsrc/include/PostBuildLint_ConfigurationType.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "CStringView.h" -#include <string> - -namespace vcpkg::PostBuildLint -{ - struct ConfigurationType - { - enum class BackingEnum - { - NULLVALUE = 0, - DEBUG = 1, - RELEASE = 2 - }; - - constexpr ConfigurationType() : backing_enum(BackingEnum::NULLVALUE) {} - constexpr explicit ConfigurationType(BackingEnum backing_enum) : backing_enum(backing_enum) {} - constexpr operator BackingEnum() const { return backing_enum; } - - const std::string& to_string() const; - - private: - BackingEnum backing_enum; - }; - - namespace ConfigurationTypeC - { - static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::ConfigurationType"; - - static constexpr ConfigurationType NULLVALUE(ConfigurationType::BackingEnum::NULLVALUE); - static constexpr ConfigurationType DEBUG(ConfigurationType::BackingEnum::DEBUG); - static constexpr ConfigurationType RELEASE(ConfigurationType::BackingEnum::RELEASE); - - static constexpr std::array<ConfigurationType, 2> VALUES = {DEBUG, RELEASE}; - } -} diff --git a/toolsrc/include/PostBuildLint_LinkageType.h b/toolsrc/include/PostBuildLint_LinkageType.h deleted file mode 100644 index 8d19dc5a4..000000000 --- a/toolsrc/include/PostBuildLint_LinkageType.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include "CStringView.h" -#include <string> - -namespace vcpkg::PostBuildLint -{ - struct LinkageType final - { - enum class BackingEnum - { - NULLVALUE = 0, - DYNAMIC, - STATIC - }; - - static LinkageType value_of(const std::string& as_string); - - constexpr LinkageType() : backing_enum(BackingEnum::NULLVALUE) {} - constexpr explicit LinkageType(BackingEnum backing_enum) : backing_enum(backing_enum) {} - constexpr operator BackingEnum() const { return backing_enum; } - - const std::string& to_string() const; - - private: - BackingEnum backing_enum; - }; - - namespace LinkageTypeC - { - static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::LinkageType"; - - static constexpr LinkageType NULLVALUE(LinkageType::BackingEnum::NULLVALUE); - static constexpr LinkageType DYNAMIC(LinkageType::BackingEnum::DYNAMIC); - static constexpr LinkageType STATIC(LinkageType::BackingEnum::STATIC); - - static constexpr std::array<LinkageType, 2> VALUES = {DYNAMIC, STATIC}; - } -} diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 19f558170..a53158f3f 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -1,5 +1,9 @@ #pragma once +#include "vcpkg_System.h" +#include "vcpkg_expected.h" + +#include <string> #include <unordered_map> #include <vector> @@ -15,24 +19,68 @@ namespace vcpkg const std::string& to_string(const Dependency& dep); + struct ParseControlErrorInfo + { + std::string name; + std::string remaining_fields_as_string; + std::string valid_fields_as_string; + std::error_code error; + }; + /// <summary> /// Port metadata (CONTROL file) /// </summary> struct SourceParagraph { - SourceParagraph(); + static ExpectedT<SourceParagraph, ParseControlErrorInfo> parse_control_file( + std::unordered_map<std::string, std::string> fields); - explicit SourceParagraph(std::unordered_map<std::string, std::string> fields); + SourceParagraph() = default; std::string name; std::string version; std::string description; std::string maintainer; + std::vector<std::string> supports; std::vector<Dependency> depends; }; + void print_error_message(const ParseControlErrorInfo& info); + void print_error_message(std::vector<ParseControlErrorInfo> error_info_list); + std::vector<std::string> filter_dependencies(const std::vector<Dependency>& deps, const Triplet& t); std::vector<Dependency> expand_qualified_dependencies(const std::vector<std::string>& depends); - std::vector<std::string> parse_depends(const std::string& depends_string); + std::vector<std::string> parse_comma_list(const std::string& str); + + struct Supports + { + static ExpectedT<Supports, std::vector<std::string>> parse(const std::vector<std::string>& strs); + + using Architecture = System::CPUArchitecture; + + enum class Platform + { + WINDOWS, + UWP, + }; + enum class Linkage + { + DYNAMIC, + STATIC, + }; + enum class ToolsetVersion + { + V140, + V141, + }; + + bool supports(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools); + + private: + std::vector<Architecture> architectures; + std::vector<Platform> platforms; + std::vector<Linkage> crt_linkages; + std::vector<ToolsetVersion> toolsets; + }; } diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h index 25c1728b9..95cd4bc28 100644 --- a/toolsrc/include/VcpkgPaths.h +++ b/toolsrc/include/VcpkgPaths.h @@ -48,7 +48,12 @@ namespace vcpkg const fs::path& get_cmake_exe() const; const fs::path& get_git_exe() const; const fs::path& get_nuget_exe() const; - const Toolset& get_toolset() const; + + /// <summary>Retrieve a toolset matching a VS version</summary> + /// <remarks> + /// Valid version strings are "v140", "v141", and "". Empty string gets the latest. + /// </remarks> + const Toolset& get_toolset(const std::string& toolset_version) const; Files::Filesystem& get_filesystem() const; @@ -56,6 +61,6 @@ namespace vcpkg Lazy<fs::path> cmake_exe; Lazy<fs::path> git_exe; Lazy<fs::path> nuget_exe; - Lazy<Toolset> toolset; + Lazy<std::vector<Toolset>> toolsets; }; } diff --git a/toolsrc/include/vcpkg_Build.h b/toolsrc/include/vcpkg_Build.h index e0a5ae1ce..e13f66029 100644 --- a/toolsrc/include/vcpkg_Build.h +++ b/toolsrc/include/vcpkg_Build.h @@ -2,18 +2,50 @@ #include "CStringView.h" #include "PackageSpec.h" -#include "PostBuildLint_LinkageType.h" #include "StatusParagraphs.h" #include "VcpkgPaths.h" #include "vcpkg_Files.h" #include "vcpkg_optional.h" +#include <array> #include <map> #include <unordered_map> #include <vector> namespace vcpkg::Build { + enum class UseHeadVersion + { + NO = 0, + YES + }; + + inline UseHeadVersion to_use_head_version(const bool value) + { + return value ? UseHeadVersion::YES : UseHeadVersion::NO; + } + + inline bool to_bool(const UseHeadVersion value) { return value == UseHeadVersion::YES; } + + enum class AllowDownloads + { + NO = 0, + YES + }; + + inline AllowDownloads to_allow_downloads(const bool value) + { + return value ? AllowDownloads::YES : AllowDownloads::NO; + } + + inline bool to_bool(const AllowDownloads value) { return value == AllowDownloads::YES; } + + struct BuildPackageOptions + { + UseHeadVersion use_head_version; + AllowDownloads allow_downloads; + }; + enum class BuildResult { NULLVALUE = 0, @@ -59,17 +91,18 @@ namespace vcpkg::Build struct BuildPackageConfig { - BuildPackageConfig(const SourceParagraph& src, const Triplet& triplet, fs::path&& port_dir) - : src(src), triplet(triplet), port_dir(std::move(port_dir)), use_head_version(false), no_downloads(false) + BuildPackageConfig(const SourceParagraph& src, + const Triplet& triplet, + fs::path&& port_dir, + const BuildPackageOptions& build_package_options) + : src(src), triplet(triplet), port_dir(std::move(port_dir)), build_package_options(build_package_options) { } const SourceParagraph& src; const Triplet& triplet; fs::path port_dir; - - bool use_head_version; - bool no_downloads; + const BuildPackageOptions& build_package_options; }; ExtendedBuildResult build_package(const VcpkgPaths& paths, @@ -108,10 +141,18 @@ namespace vcpkg::Build std::map<BuildPolicy, bool> m_policies; }; + enum class LinkageType : char + { + DYNAMIC, + STATIC, + }; + + Optional<LinkageType> to_linkage_type(const std::string& str); + struct BuildInfo { - PostBuildLint::LinkageType crt_linkage; - PostBuildLint::LinkageType library_linkage; + LinkageType crt_linkage; + LinkageType library_linkage; Optional<std::string> version; diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index 14d468352..006971e47 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/include/vcpkg_Commands.h @@ -4,6 +4,8 @@ #include "VcpkgCmdArguments.h" #include "VcpkgPaths.h" #include "VersionT.h" +#include "vcpkg_Build.h" +#include "vcpkg_Dependencies.h" #include <array> namespace vcpkg::Commands @@ -48,6 +50,11 @@ namespace vcpkg::Commands const fs::path& listfile() const; }; + Build::BuildResult perform_install_plan_action(const VcpkgPaths& paths, + const Dependencies::InstallPlanAction& action, + const Build::BuildPackageOptions& install_plan_options, + StatusParagraphs& status_db); + void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& dirs); diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index 6648302ac..1bd1bcc4a 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -34,6 +34,12 @@ namespace vcpkg::Util cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); } + template<class Container, class V> + auto find(const Container& cont, V&& v) + { + return std::find(cont.cbegin(), cont.cend(), v); + } + template<class Container, class Pred> auto find_if(const Container& cont, Pred pred) { diff --git a/toolsrc/include/vcpkg_expected.h b/toolsrc/include/vcpkg_expected.h index 3a920022b..15dbf5e79 100644 --- a/toolsrc/include/vcpkg_expected.h +++ b/toolsrc/include/vcpkg_expected.h @@ -5,27 +5,63 @@ namespace vcpkg { - template<class T> - class Expected + template<class Err> + struct ErrorHolder { - public: - // Constructors are intentionally implicit - Expected(const std::error_code& ec) : m_error_code(ec), m_t() {} + 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)) {} + + constexpr bool has_error() const { return m_is_error; } + + const Err& error() const { return m_err; } + Err& error() { return m_err; } + + CStringView to_string() const { return "value was error"; } + + private: + bool m_is_error; + Err m_err; + }; + + template<> + struct ErrorHolder<std::error_code> + { + ErrorHolder() = default; + ErrorHolder(const std::error_code& err) : m_err(err) {} + + constexpr bool has_error() const { return bool(m_err); } - Expected(std::errc ec) : Expected(std::make_error_code(ec)) {} + const std::error_code& error() const { return m_err; } + std::error_code& error() { return m_err; } - Expected(const T& t) : m_error_code(), m_t(t) {} + CStringView to_string() const { return "value was error"; } - Expected(T&& t) : m_error_code(), m_t(std::move(t)) {} + private: + std::error_code m_err; + }; + + template<class T, class S> + class ExpectedT + { + public: + constexpr ExpectedT() = default; + + // Constructors are intentionally implicit + + ExpectedT(const S& s) : m_s(s) {} + ExpectedT(S&& s) : m_s(std::move(s)) {} - Expected() : Expected(std::error_code(), T()) {} + ExpectedT(const T& t) : m_t(t) {} + ExpectedT(T&& t) : m_t(std::move(t)) {} - Expected(const Expected&) = default; - Expected(Expected&&) = default; - Expected& operator=(const Expected&) = default; - Expected& operator=(Expected&&) = default; + ExpectedT(const ExpectedT&) = default; + ExpectedT(ExpectedT&&) = default; + ExpectedT& operator=(const ExpectedT&) = default; + ExpectedT& operator=(ExpectedT&&) = default; - std::error_code error_code() const { return this->m_error_code; } + explicit constexpr operator bool() const noexcept { return !m_s.has_error(); } + constexpr bool has_value() const noexcept { return !m_s.has_error(); } T&& value_or_exit(const LineInfo& line_info) && { @@ -39,9 +75,13 @@ namespace vcpkg return this->m_t; } + const S& error() const & { return this->m_s.error(); } + + S&& error() && { return std::move(this->m_s.error()); } + const T* get() const { - if (m_error_code) + if (!this->has_value()) { return nullptr; } @@ -50,7 +90,7 @@ namespace vcpkg T* get() { - if (m_error_code) + if (!this->has_value()) { return nullptr; } @@ -60,10 +100,13 @@ namespace vcpkg private: void exit_if_error(const LineInfo& line_info) const { - Checks::check_exit(line_info, !this->m_error_code, this->m_error_code.message()); + Checks::check_exit(line_info, !m_s.has_error(), m_s.to_string()); } - std::error_code m_error_code; + ErrorHolder<S> m_s; T m_t; }; + + template<class T> + using Expected = ExpectedT<T, std::error_code>; } |
