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

This commit is contained in:
Robert Schumacher 2018-07-07 02:55:03 -07:00
parent 802f51a142
commit d977ac231e
13 changed files with 114 additions and 98 deletions

View File

@ -1,9 +1,9 @@
#pragma once
#include <vcpkg/base/files.h>
#include <vcpkg/vcpkgpaths.h>
namespace vcpkg::Archives
{
void extract_archive(const VcpkgPaths& paths, const fs::path& archive, const fs::path& to_path);
}
#pragma once
#include <vcpkg/base/files.h>
#include <vcpkg/vcpkgpaths.h>
namespace vcpkg::Archives
{
void extract_archive(const VcpkgPaths& paths, const fs::path& archive, const fs::path& to_path);
}

View File

@ -1,16 +1,16 @@
#pragma once
#include <vcpkg/base/files.h>
namespace vcpkg::Downloads
{
void verify_downloaded_file_hash(const Files::Filesystem& fs,
const std::string& url,
const fs::path& path,
const std::string& sha512);
void download_file(vcpkg::Files::Filesystem& fs,
const std::string& url,
const fs::path& download_path,
const std::string& sha512);
}
#pragma once
#include <vcpkg/base/files.h>
namespace vcpkg::Downloads
{
void verify_downloaded_file_hash(const Files::Filesystem& fs,
const std::string& url,
const fs::path& path,
const std::string& sha512);
void download_file(Files::Filesystem& fs,
const std::string& url,
const fs::path& download_path,
const std::string& sha512);
}

View File

@ -0,0 +1,11 @@
#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);
}

View File

@ -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);
}

View File

@ -1,6 +1,6 @@
#include "pch.h"
#include <vcpkg/base/archives.h>
#include <vcpkg/archives.h>
#include <vcpkg/commands.h>
namespace vcpkg::Archives

View File

@ -1,11 +1,13 @@
#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());
}
}

View File

@ -4,10 +4,16 @@
#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);
}
}

View File

@ -1,11 +1,13 @@
#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;

View File

@ -1,5 +1,7 @@
#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);
}
}

View File

@ -5,6 +5,7 @@
#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;
}

View File

@ -1,13 +1,16 @@
#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

View File

@ -137,7 +137,7 @@
</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" />
@ -148,6 +148,7 @@
<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" />
@ -198,13 +199,14 @@
<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" />
@ -223,7 +225,6 @@
<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" />

View File

@ -69,9 +69,6 @@
<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>
@ -198,11 +195,8 @@
<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>
@ -213,6 +207,12 @@
<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">
@ -359,14 +359,11 @@
<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>
@ -377,5 +374,11 @@
<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>