[vcpkg] Remove vcpkg::Archives from vcpkg::base. Add vcpkg::Hash.
RENAME
include/vcpkg/base/archives.h
include/vcpkg/archives.h
MODIFY
include/vcpkg/base/downloads.h
include/vcpkg/base/downloads.h
@@ -9,7 +9,7 @@ namespace vcpkg::Downloads
const fs::path& path,
const std::string& sha512);
- void download_file(vcpkg::Files::Filesystem& fs,
+ void download_file(Files::Filesystem& fs,
const std::string& url,
const fs::path& download_path,
const std::string& sha512);

ADD
include/vcpkg/base/hash.h
+#pragma once
+
+#include <vcpkg/base/files.h>
+
+#include <string>
+
+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);
+}

MODIFY
include/vcpkg/commands.h
include/vcpkg/commands.h
@@ -131,9 +131,6 @@ namespace vcpkg::Commands
namespace 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);
-
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
}

RENAME
src/vcpkg/base/archives.cpp
src/vcpkg/archives.cpp
#include "pch.h"
-#include <vcpkg/base/archives.h>
+#include <vcpkg/archives.h>
#include <vcpkg/commands.h>
namespace vcpkg::Archives

MODIFY
src/vcpkg/base/downloads.cpp
src/vcpkg/base/downloads.cpp
#include "pch.h"
#include <vcpkg/base/downloads.h>
+#include <vcpkg/base/hash.h>
#include <vcpkg/base/util.h>
-#include <vcpkg/commands.h>
#if defined(_WIN32)
#include <VersionHelpers.h>
+#else
+#include <vcpkg/base/system.h>
#endif
namespace vcpkg::Downloads
@@ -32,10 +34,12 @@ namespace vcpkg::Downloads
target_file_path,
std::to_string(err));
- auto hSession = WinHttpOpen(
- L"vcpkg/1.0",
- IsWindows8Point1OrGreater() ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY : WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
- WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
+ auto hSession = WinHttpOpen(L"vcpkg/1.0",
+ IsWindows8Point1OrGreater() ? WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY
+ : WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
+ WINHTTP_NO_PROXY_NAME,
+ WINHTTP_NO_PROXY_BYPASS,
+ 0);
Checks::check_exit(VCPKG_LINE_INFO, hSession, "WinHttpOpen() failed: %d", GetLastError());
// Use Windows 10 defaults on Windows 7
@@ -98,7 +102,7 @@ namespace vcpkg::Downloads
const fs::path& path,
const std::string& sha512)
{
- const std::string actual_hash = Commands::Hash::get_file_hash(fs, path, "SHA512");
+ const std::string actual_hash = vcpkg::Hash::get_file_hash(fs, path, "SHA512");
Checks::check_exit(VCPKG_LINE_INFO,
sha512 == actual_hash,
"File does not have the expected hash:\n"
@@ -144,5 +148,4 @@ namespace vcpkg::Downloads
download_path.u8string(),
ec.message());
}
-
}

RENAME
src/vcpkg/commands.hash.cpp
src/vcpkg/base/hash.cpp
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/util.h>
-#include <vcpkg/commands.h>
-#include <vcpkg/help.h>
-namespace vcpkg::Commands::Hash
+#if defined(_WIN32)
+#include <bcrypt.h>
+
+#ifndef NT_SUCCESS
+#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
+#endif
+#endif
+
+namespace vcpkg::Hash
{
static void verify_has_only_allowed_chars(const std::string& s)
{
@@ -18,17 +24,7 @@ namespace vcpkg::Commands::Hash
" % s",
s);
}
-}
-
#if defined(_WIN32)
-#include <bcrypt.h>
-
-#ifndef NT_SUCCESS
-#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
-#endif
-
-namespace vcpkg::Commands::Hash
-{
namespace
{
std::string to_hex(const unsigned char* string, const size_t bytes)
@@ -165,11 +161,8 @@ namespace vcpkg::Commands::Hash
verify_has_only_allowed_chars(s);
return BCryptHasher{hash_type}.hash_string(s);
}
-}
#else
-namespace vcpkg::Commands::Hash
-{
static std::string get_digest_size(const std::string& hash_type)
{
if (!Strings::case_insensitive_ascii_starts_with(hash_type, "SHA"))
@@ -217,28 +210,5 @@ namespace vcpkg::Commands::Hash
const std::string cmd_line = Strings::format(R"(echo -n "%s" | shasum -a %s)", s, digest_size);
return run_shasum_and_post_process(cmd_line);
}
-}
#endif
-
-namespace vcpkg::Commands::Hash
-{
- const CommandStructure COMMAND_STRUCTURE = {
- Strings::format("The argument should be a file path\n%s",
- Help::create_example_string("hash boost_1_62_0.tar.bz2")),
- 1,
- 2,
- {},
- nullptr,
- };
-
- void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
- {
- Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
-
- const fs::path file_to_hash = args.command_arguments[0];
- const std::string algorithm = args.command_arguments.size() == 2 ? args.command_arguments[1] : "SHA512";
- const std::string hash = get_file_hash(paths.get_filesystem(), file_to_hash, algorithm);
- System::println(hash);
- Checks::exit_success(VCPKG_LINE_INFO);
- }
}

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
#include "pch.h"
+#include <vcpkg/base/hash.h>
#include <vcpkg/base/checks.h>
#include <vcpkg/base/chrono.h>
#include <vcpkg/base/enums.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringliteral.h>
#include <vcpkg/base/system.h>
+
#include <vcpkg/build.h>
#include <vcpkg/commands.h>
#include <vcpkg/dependencies.h>
@@ -467,9 +469,9 @@ namespace vcpkg::Build
abi_tag_entries.insert(abi_tag_entries.end(), dependency_abis.begin(), dependency_abis.end());
abi_tag_entries.emplace_back(
- AbiEntry{"portfile", Commands::Hash::get_file_hash(fs, config.port_dir / "portfile.cmake", "SHA1")});
+ AbiEntry{"portfile", vcpkg::Hash::get_file_hash(fs, config.port_dir / "portfile.cmake", "SHA1")});
abi_tag_entries.emplace_back(
- AbiEntry{"control", Commands::Hash::get_file_hash(fs, config.port_dir / "CONTROL", "SHA1")});
+ AbiEntry{"control", vcpkg::Hash::get_file_hash(fs, config.port_dir / "CONTROL", "SHA1")});
if (pre_build_info.cmake_system_name == "Linux")
{
@@ -509,7 +511,7 @@ namespace vcpkg::Build
const auto abi_file_path = paths.buildtrees / name / (triplet.canonical_name() + ".vcpkg_abi_info.txt");
fs.write_contents(abi_file_path, full_abi_info);
- return AbiTagAndFile{Commands::Hash::get_file_hash(fs, abi_file_path, "SHA1"), abi_file_path};
+ return AbiTagAndFile{Hash::get_file_hash(fs, abi_file_path, "SHA1"), abi_file_path};
}
System::println(
@@ -804,7 +806,7 @@ namespace vcpkg::Build
{
return it_hash->second;
}
- auto hash = Commands::Hash::get_file_hash(paths.get_filesystem(), triplet_file_path, "SHA1");
+ auto hash = Hash::get_file_hash(paths.get_filesystem(), triplet_file_path, "SHA1");
s_hash_cache.emplace(triplet_file_path, hash);
return hash;

MODIFY
src/vcpkg/commands.cpp
src/vcpkg/commands.cpp
#include "pch.h"
+#include <vcpkg/base/hash.h>
+
#include <vcpkg/build.h>
#include <vcpkg/commands.h>
#include <vcpkg/export.h>
@@ -78,3 +80,26 @@ namespace vcpkg::Commands::Fetch
Checks::exit_success(VCPKG_LINE_INFO);
}
}
+
+namespace vcpkg::Commands::Hash
+{
+ const CommandStructure COMMAND_STRUCTURE = {
+ Strings::format("The argument should be a file path\n%s",
+ Help::create_example_string("hash boost_1_62_0.tar.bz2")),
+ 1,
+ 2,
+ {},
+ nullptr,
+ };
+
+ void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
+ {
+ Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
+
+ const fs::path file_to_hash = args.command_arguments[0];
+ const std::string algorithm = args.command_arguments.size() == 2 ? args.command_arguments[1] : "SHA512";
+ const std::string hash = vcpkg::Hash::get_file_hash(paths.get_filesystem(), file_to_hash, algorithm);
+ System::println(hash);
+ Checks::exit_success(VCPKG_LINE_INFO);
+ }
+}

MODIFY
src/vcpkg/metrics.cpp
src/vcpkg/metrics.cpp
#include <vcpkg/base/chrono.h>
#include <vcpkg/base/files.h>
+#include <vcpkg/base/hash.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.h>
@@ -261,7 +262,7 @@ namespace vcpkg::Metrics
const auto match = *next;
if (match[0] != "00-00-00-00-00-00")
{
- return vcpkg::Commands::Hash::get_string_hash(match[0], "SHA256");
+ return vcpkg::Hash::get_string_hash(match[0], "SHA256");
}
++next;
}

MODIFY
src/vcpkg/tools.cpp
src/vcpkg/tools.cpp
#include "pch.h"
+#include <vcpkg/archives.h>
#include <vcpkg/tools.h>
#include <vcpkg/vcpkgpaths.h>
-#include <vcpkg/base/archives.h>
+#include <vcpkg/base/checks.h>
#include <vcpkg/base/downloads.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringrange.h>
+#include <vcpkg/base/strings.h>
+#include <vcpkg/base/system.h>
#include <vcpkg/base/util.h>
namespace vcpkg

MODIFY
vcpkglib/vcpkglib.vcxproj
vcpkglib/vcpkglib.vcxproj
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\include\pch.h" />
- <ClInclude Include="..\include\vcpkg\base\archives.h" />
+ <ClInclude Include="..\include\vcpkg\archives.h" />
<ClInclude Include="..\include\vcpkg\base\cache.h" />
<ClInclude Include="..\include\vcpkg\base\checks.h" />
<ClInclude Include="..\include\vcpkg\base\chrono.h" />
<ClInclude Include="..\include\vcpkg\base\expected.h" />
<ClInclude Include="..\include\vcpkg\base\files.h" />
<ClInclude Include="..\include\vcpkg\base\graphs.h" />
+ <ClInclude Include="..\include\vcpkg\base\hash.h" />
<ClInclude Include="..\include\vcpkg\base\lazy.h" />
<ClInclude Include="..\include\vcpkg\base\lineinfo.h" />
<ClInclude Include="..\include\vcpkg\base\machinetype.h" />
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
- <ClCompile Include="..\src\vcpkg\base\archives.cpp" />
+ <ClCompile Include="..\src\vcpkg\archives.cpp" />
<ClCompile Include="..\src\vcpkg\base\checks.cpp" />
<ClCompile Include="..\src\vcpkg\base\chrono.cpp" />
<ClCompile Include="..\src\vcpkg\base\cofffilereader.cpp" />
<ClCompile Include="..\src\vcpkg\base\downloads.cpp" />
<ClCompile Include="..\src\vcpkg\base\enums.cpp" />
<ClCompile Include="..\src\vcpkg\base\files.cpp" />
+ <ClCompile Include="..\src\vcpkg\base\hash.cpp" />
<ClCompile Include="..\src\vcpkg\base\lineinfo.cpp" />
<ClCompile Include="..\src\vcpkg\base\machinetype.cpp" />
<ClCompile Include="..\src\vcpkg\base\stringrange.cpp" />
<ClCompile Include="..\src\vcpkg\commands.edit.cpp" />
<ClCompile Include="..\src\vcpkg\commands.env.cpp" />
<ClCompile Include="..\src\vcpkg\commands.exportifw.cpp" />
- <ClCompile Include="..\src\vcpkg\commands.hash.cpp" />
<ClCompile Include="..\src\vcpkg\commands.import.cpp" />
<ClCompile Include="..\src\vcpkg\commands.integrate.cpp" />
<ClCompile Include="..\src\vcpkg\commands.list.cpp" />

MODIFY
vcpkglib/vcpkglib.vcxproj.filters
vcpkglib/vcpkglib.vcxproj.filters
<ClCompile Include="..\src\vcpkg\commands.exportifw.cpp">
<Filter>Source Files\vcpkg</Filter>
</ClCompile>
- <ClCompile Include="..\src\vcpkg\commands.hash.cpp">
- <Filter>Source Files\vcpkg</Filter>
- </ClCompile>
<ClCompile Include="..\src\vcpkg\commands.import.cpp">
<Filter>Source Files\vcpkg</Filter>
</ClCompile>
<ClCompile Include="..\src\vcpkg\commands.upgrade.cpp">
<Filter>Source Files\vcpkg</Filter>
</ClCompile>
- <ClCompile Include="..\src\vcpkg\base\downloads.cpp">
- <Filter>Source Files\vcpkg\base</Filter>
- </ClCompile>
- <ClCompile Include="..\src\vcpkg\base\archives.cpp">
- <Filter>Source Files\vcpkg\base</Filter>
+ <ClCompile Include="..\src\vcpkg\archives.cpp">
+ <Filter>Source Files\vcpkg</Filter>
</ClCompile>
<ClCompile Include="..\src\vcpkg\visualstudio.cpp">
<Filter>Source Files\vcpkg</Filter>
<ClCompile Include="..\src\vcpkg\tools.cpp">
<Filter>Source Files\vcpkg</Filter>
</ClCompile>
+ <ClCompile Include="..\src\vcpkg\base\hash.cpp">
+ <Filter>Source Files\vcpkg\base</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\vcpkg\base\downloads.cpp">
+ <Filter>Source Files\vcpkg\base</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\pch.h">
<ClInclude Include="..\include\vcpkg\base\stringliteral.h">
<Filter>Header Files\vcpkg\base</Filter>
</ClInclude>
- <ClInclude Include="..\include\vcpkg\base\downloads.h">
- <Filter>Header Files\vcpkg\base</Filter>
- </ClInclude>
- <ClInclude Include="..\include\vcpkg\base\archives.h">
- <Filter>Header Files\vcpkg\base</Filter>
+ <ClInclude Include="..\include\vcpkg\archives.h">
+ <Filter>Header Files\vcpkg</Filter>
</ClInclude>
<ClInclude Include="..\include\vcpkg\visualstudio.h">
- <Filter>Header Files\vcpkg\base</Filter>
+ <Filter>Header Files\vcpkg</Filter>
</ClInclude>
<ClInclude Include="..\include\vcpkg\base\stringrange.h">
<Filter>Header Files\vcpkg\base</Filter>
<ClInclude Include="..\include\vcpkg\tools.h">
<Filter>Header Files\vcpkg</Filter>
</ClInclude>
+ <ClInclude Include="..\include\vcpkg\base\hash.h">
+ <Filter>Header Files\vcpkg\base</Filter>
+ </ClInclude>
+ <ClInclude Include="..\include\vcpkg\base\downloads.h">
+ <Filter>Header Files\vcpkg\base</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file

[vcpkg] Remove vcpkg::Archives from vcpkg::base. Add vcpkg::Hash.