From 347d8ef530aaf39ca6d89043ca9ce9a8bac9a70f Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 10 Mar 2020 23:44:48 -0700 Subject: Implement a warning when running vcpkg inside a developer command prompt if the set of packages to install all target a different architecture than the prompt. --- toolsrc/include/vcpkg/base/optional.h | 38 +++++++++++++++++++++++++++++++++++ toolsrc/include/vcpkg/base/system.h | 4 ++++ toolsrc/include/vcpkg/triplet.h | 7 +++++-- 3 files changed, 47 insertions(+), 2 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/base/optional.h b/toolsrc/include/vcpkg/base/optional.h index fc3733ead..50586ecc8 100644 --- a/toolsrc/include/vcpkg/base/optional.h +++ b/toolsrc/include/vcpkg/base/optional.h @@ -283,6 +283,21 @@ namespace vcpkg } } + friend bool operator==(const Optional& lhs, const Optional& rhs) + { + if (lhs.m_base.has_value()) + { + if (rhs.m_base.has_value()) + { + return lhs.m_base.value() == rhs.m_base.value(); + } + + return false; + } + + return !rhs.m_base.has_value(); + } + private: details::OptionalStorage m_base; }; @@ -317,4 +332,27 @@ namespace vcpkg if (auto p = o.get()) return t != *p; return true; } + + template + auto common_projection(const Container& input, Projection proj) + -> Optional> + { + const auto last = input.end(); + auto first = input.begin(); + if (first == last) + { + return nullopt; + } + + const auto& prototype = proj(*first); + while (++first != last) + { + if (prototype != proj(*first)) + { + return nullopt; + } + } + + return prototype; + } } diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h index 907a692a2..4172f0c50 100644 --- a/toolsrc/include/vcpkg/base/system.h +++ b/toolsrc/include/vcpkg/base/system.h @@ -21,6 +21,8 @@ namespace vcpkg::System Optional to_cpu_architecture(StringView arch); + ZStringView to_zstring_view(CPUArchitecture arch) noexcept; + CPUArchitecture get_host_processor(); std::vector get_supported_host_architectures(); @@ -30,4 +32,6 @@ namespace vcpkg::System const Optional& get_program_files_platform_bitness(); int get_num_logical_cores(); + + Optional guess_visual_studio_prompt_target_architecture(); } diff --git a/toolsrc/include/vcpkg/triplet.h b/toolsrc/include/vcpkg/triplet.h index 8d8c3e879..d836dd230 100644 --- a/toolsrc/include/vcpkg/triplet.h +++ b/toolsrc/include/vcpkg/triplet.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include namespace vcpkg { @@ -15,17 +17,18 @@ namespace vcpkg static const Triplet X86_WINDOWS; static const Triplet X64_WINDOWS; + static const Triplet ARM_WINDOWS; + static const Triplet ARM64_WINDOWS; static const Triplet X86_UWP; static const Triplet X64_UWP; static const Triplet ARM_UWP; static const Triplet ARM64_UWP; - static const Triplet ARM_WINDOWS; - static const Triplet ARM64_WINDOWS; const std::string& canonical_name() const; const std::string& to_string() const; void to_string(std::string& out) const; size_t hash_code() const; + Optional guess_architecture() const noexcept; bool operator==(Triplet other) const { return this->m_instance == other.m_instance; } bool operator<(Triplet other) const { return canonical_name() < other.canonical_name(); } -- cgit v1.2.3