diff options
| author | Alexander Neumann <alexander.neumann@hamburg.de> | 2019-09-20 12:24:23 +0200 |
|---|---|---|
| committer | Alexander Neumann <alexander.neumann@hamburg.de> | 2019-09-20 12:24:23 +0200 |
| commit | 5b1e426929b40a9b60809284993b424b841a28fc (patch) | |
| tree | bd12300ad859bababb7d4acc03700fd31949fddc /toolsrc/include | |
| parent | 279e25aecfe30f55296881ea9b0236c1d6ee030a (diff) | |
| parent | 358ec0954d9b71b0def4fd4b4dbafdd0b8478d81 (diff) | |
| download | vcpkg-5b1e426929b40a9b60809284993b424b841a28fc.tar.gz vcpkg-5b1e426929b40a9b60809284993b424b841a28fc.zip | |
Merge remote-tracking branch 'upstream/master' into path_separator
# Conflicts:
# scripts/cmake/vcpkg_common_definitions.cmake
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/vcpkg/base/hash.h | 44 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/strings.h | 12 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/base/stringview.h | 5 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/build.h | 8 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg/commands.h | 5 |
5 files changed, 69 insertions, 5 deletions
diff --git a/toolsrc/include/vcpkg/base/hash.h b/toolsrc/include/vcpkg/base/hash.h index 9e6f118c0..d62fd3921 100644 --- a/toolsrc/include/vcpkg/base/hash.h +++ b/toolsrc/include/vcpkg/base/hash.h @@ -6,6 +6,46 @@ namespace vcpkg::Hash { - std::string get_string_hash(const std::string& s, const std::string& hash_type); - std::string get_file_hash(const Files::Filesystem& fs, const fs::path& path, const std::string& hash_type); + enum class Algorithm + { + Sha1, + Sha256, + Sha512, + }; + + const char* to_string(Algorithm algo) noexcept; + Optional<Algorithm> algorithm_from_string(StringView sv) noexcept; + + struct Hasher + { + virtual void add_bytes(const void* start, const void* end) noexcept = 0; + + // one may only call this once before calling `clear()` or the dtor + virtual std::string get_hash() noexcept = 0; + virtual void clear() noexcept = 0; + virtual ~Hasher() = default; + }; + + std::unique_ptr<Hasher> get_hasher_for(Algorithm algo) noexcept; + + std::string get_bytes_hash(const void* first, const void* last, Algorithm algo) noexcept; + std::string get_string_hash(StringView s, Algorithm algo) noexcept; + std::string get_file_hash(const Files::Filesystem& fs, + const fs::path& path, + Algorithm algo, + std::error_code& ec) noexcept; + inline std::string get_file_hash(LineInfo li, + const Files::Filesystem& fs, + const fs::path& path, + Algorithm algo) noexcept + { + std::error_code ec; + const auto result = get_file_hash(fs, path, algo, ec); + if (ec) + { + Checks::exit_with_message(li, "Failure to read file for hashing: %s", ec.message()); + } + + return result; + } } diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h index 0f25607df..481e686d1 100644 --- a/toolsrc/include/vcpkg/base/strings.h +++ b/toolsrc/include/vcpkg/base/strings.h @@ -12,15 +12,25 @@ namespace vcpkg::Strings::details { template<class T> - auto to_printf_arg(const T& t) -> decltype(t.to_string()) + auto to_string(const T& t) -> decltype(t.to_string()) { return t.to_string(); } + // first looks up to_string on `T` using ADL; then, if that isn't found, + // uses the above definition which returns t.to_string() + template<class T, class = std::enable_if_t<!std::is_arithmetic<T>::value>> + auto to_printf_arg(const T& t) -> decltype(to_string(t)) + { + return to_string(t); + } + inline const char* to_printf_arg(const std::string& s) { return s.c_str(); } inline const char* to_printf_arg(const char* s) { return s; } + inline const wchar_t* to_printf_arg(const wchar_t* s) { return s; } + template<class T, class = std::enable_if_t<std::is_arithmetic<T>::value>> T to_printf_arg(T s) { diff --git a/toolsrc/include/vcpkg/base/stringview.h b/toolsrc/include/vcpkg/base/stringview.h index fef5bef4e..8503f5f10 100644 --- a/toolsrc/include/vcpkg/base/stringview.h +++ b/toolsrc/include/vcpkg/base/stringview.h @@ -40,10 +40,11 @@ namespace vcpkg std::string to_string() const; void to_string(std::string& out) const; - bool operator==(StringView other) const; - private: const char* m_ptr = 0; size_t m_size = 0; }; + + bool operator==(StringView lhs, StringView rhs) noexcept; + bool operator!=(StringView lhs, StringView rhs) noexcept; } diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 4f6397662..b535698dc 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -39,6 +39,12 @@ namespace vcpkg::Build YES }; + enum class OnlyDownloads + { + NO = 0, + YES + }; + enum class CleanBuildtrees { NO = 0, @@ -86,6 +92,7 @@ namespace vcpkg::Build { UseHeadVersion use_head_version; AllowDownloads allow_downloads; + OnlyDownloads only_downloads; CleanBuildtrees clean_buildtrees; CleanPackages clean_packages; CleanDownloads clean_downloads; @@ -103,6 +110,7 @@ namespace vcpkg::Build FILE_CONFLICTS, CASCADED_DUE_TO_MISSING_DEPENDENCIES, EXCLUDED, + DOWNLOADED }; static constexpr std::array<BuildResult, 6> BUILD_RESULT_VALUES = { diff --git a/toolsrc/include/vcpkg/commands.h b/toolsrc/include/vcpkg/commands.h index 8a502122e..e73077e1d 100644 --- a/toolsrc/include/vcpkg/commands.h +++ b/toolsrc/include/vcpkg/commands.h @@ -100,6 +100,11 @@ namespace vcpkg::Commands void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); } + namespace PortHistory + { + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); + } + namespace Autocomplete { void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); |
