Merge pull request #2431 from procxx/certutil_replace

[vcpkg-hash] Use cmake built-in hash commands instead of certutil.exe call
This commit is contained in:
Alexander Karatarakis 2018-01-02 23:23:41 +02:00 committed by GitHub
commit e48a655df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -119,7 +119,7 @@ namespace vcpkg::Commands
namespace Hash namespace Hash
{ {
void perform_and_exit(const VcpkgCmdArguments& args); void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
} }
template<class T> template<class T>

View File

@ -41,7 +41,9 @@ namespace vcpkg::Commands
{"import", &Import::perform_and_exit}, {"import", &Import::perform_and_exit},
{"cache", &Cache::perform_and_exit}, {"cache", &Cache::perform_and_exit},
{"portsdiff", &PortsDiff::perform_and_exit}, {"portsdiff", &PortsDiff::perform_and_exit},
{"autocomplete", &Autocomplete::perform_and_exit}}; {"autocomplete", &Autocomplete::perform_and_exit},
{"hash", &Hash::perform_and_exit},
};
return t; return t;
} }
@ -49,8 +51,7 @@ namespace vcpkg::Commands
{ {
static std::vector<PackageNameAndFunction<CommandTypeC>> t = { static std::vector<PackageNameAndFunction<CommandTypeC>> t = {
{"version", &Version::perform_and_exit}, {"version", &Version::perform_and_exit},
{"contact", &Contact::perform_and_exit}, {"contact", &Contact::perform_and_exit}
{"hash", &Hash::perform_and_exit},
}; };
return t; return t;
} }

View File

@ -7,15 +7,17 @@
namespace vcpkg::Commands::Hash namespace vcpkg::Commands::Hash
{ {
static void do_file_hash(fs::path const& path, std::string const& hash_type) static void do_file_hash(fs::path const &cmake_exe_path, fs::path const& path, std::string const& hash_type)
{ {
const auto cmd_line = Strings::format(R"(CertUtil.exe -hashfile "%s" %s)", path.u8string().c_str(), hash_type); const std::string cmd_line = Strings::format(
R"("%s" -E %ssum %s)", cmake_exe_path.u8string(), Strings::ascii_to_lowercase(hash_type), path.u8string());
const auto ec_data = System::cmd_execute_and_capture_output(cmd_line); const auto ec_data = System::cmd_execute_and_capture_output(cmd_line);
Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line); Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line);
std::string const& output = ec_data.output; std::string const& output = ec_data.output;
const auto start = output.find_first_of("\r\n"); const auto start = output.find_first_of(" ");
Checks::check_exit( Checks::check_exit(
VCPKG_LINE_INFO, start != std::string::npos, "Unexpected output format from command: %s", cmd_line); VCPKG_LINE_INFO, start != std::string::npos, "Unexpected output format from command: %s", cmd_line);
@ -23,7 +25,7 @@ namespace vcpkg::Commands::Hash
Checks::check_exit( Checks::check_exit(
VCPKG_LINE_INFO, end != std::string::npos, "Unexpected output format from command: %s", cmd_line); VCPKG_LINE_INFO, end != std::string::npos, "Unexpected output format from command: %s", cmd_line);
auto hash = output.substr(start, end - start); auto hash = output.substr(0, start);
Util::erase_remove_if(hash, isspace); Util::erase_remove_if(hash, isspace);
System::println(hash); System::println(hash);
} }
@ -37,17 +39,17 @@ namespace vcpkg::Commands::Hash
nullptr, nullptr,
}; };
void perform_and_exit(const VcpkgCmdArguments& args) void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{ {
args.parse_arguments(COMMAND_STRUCTURE); args.parse_arguments(COMMAND_STRUCTURE);
if (args.command_arguments.size() == 1) if (args.command_arguments.size() == 1)
{ {
do_file_hash(args.command_arguments[0], "SHA512"); do_file_hash(paths.get_cmake_exe(), args.command_arguments[0], "SHA512");
} }
if (args.command_arguments.size() == 2) if (args.command_arguments.size() == 2)
{ {
do_file_hash(args.command_arguments[0], args.command_arguments[1]); do_file_hash(paths.get_cmake_exe(), args.command_arguments[0], args.command_arguments[1]);
} }
Checks::exit_success(VCPKG_LINE_INFO); Checks::exit_success(VCPKG_LINE_INFO);