Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ DECLARE_MESSAGE(CmdCheckSupportExample1,
"This is a command line, only the <>s part should be localized",
"vcpkg x-check-support <port name>")
DECLARE_MESSAGE(CmdCheckSupportSynopsis, (), "", "Tests whether a port is supported without building it")
DECLARE_MESSAGE(CmdCheckToolsShaSynopsis,
(),
"",
"Checks the sha512 entries in a tools data file by downloading all entries and computing the hashes")
DECLARE_MESSAGE(CmdCreateExample1,
(),
"This is a command line, only the <>s part should be localized",
Expand Down
11 changes: 11 additions & 0 deletions include/vcpkg/commands.check-tools-sha.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <vcpkg/base/fwd/files.h>

#include <vcpkg/fwd/vcpkgcmdarguments.h>

namespace vcpkg
{
extern const CommandMetadata CommandCheckToolsShaMetadata;
void command_check_tools_sha_and_exit(const VcpkgCmdArguments& args, const Filesystem& paths);
}
1 change: 1 addition & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
"CmdCheckSupportExample1": "vcpkg x-check-support <port name>",
"_CmdCheckSupportExample1.comment": "This is a command line, only the <>s part should be localized",
"CmdCheckSupportSynopsis": "Tests whether a port is supported without building it",
"CmdCheckToolsShaSynopsis": "Checks the sha512 entries in a tools data file by downloading all entries and computing the hashes",
"CmdCiCleanSynopsis": "Clears all files to prepare for a CI run",
"_CmdCiCleanSynopsis.comment": "CI is continuous integration (building everything together)",
"CmdCiSynopsis": "Tries building all ports for CI testing",
Expand Down
71 changes: 71 additions & 0 deletions src/vcpkg/commands.check-tools-sha.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <vcpkg/base/files.h>
#include <vcpkg/base/hash.h>

#include <vcpkg/commands.check-tools-sha.h>
#include <vcpkg/tools.test.h>
#include <vcpkg/vcpkgcmdarguments.h>

#include "vcpkg/base/downloads.h"

namespace vcpkg
{
constexpr CommandMetadata CommandCheckToolsShaMetadata{
"x-check-tools-sha",
msgCmdCheckToolsShaSynopsis,
{"vcpkg x-check-tools-sha scripts/vcpkg-tools.json"},
Undocumented,
AutocompletePriority::Internal,
1,
1,
{},
nullptr,
};

void command_check_tools_sha_and_exit(const VcpkgCmdArguments& args, const Filesystem& fs)
{
const auto parsed = args.parse_arguments(CommandCheckToolsShaMetadata);

const auto file_to_check = (fs.current_path(VCPKG_LINE_INFO) / parsed.command_arguments[0]).lexically_normal();

const auto dest_path = fs.create_or_get_temp_directory(VCPKG_LINE_INFO);

auto content = fs.read_contents(file_to_check, VCPKG_LINE_INFO);

auto data = parse_tool_data(content, file_to_check).value_or_exit(VCPKG_LINE_INFO);

std::unordered_map<std::string, std::string> seen_urls;

std::vector<std::pair<std::string, Path>> urls;
for (auto& entry : data)
{
if (entry.url.empty()) continue;
auto iter = seen_urls.emplace(entry.url, entry.sha512);

Checks::check_exit(VCPKG_LINE_INFO, iter.first->second == entry.sha512);
if (iter.second)
{
urls.emplace_back(entry.url, dest_path / entry.archiveName + " - " + entry.sha512.substr(0, 10));
}
}

fmt::println("Downloading {} tools", urls.size());
auto result = download_files_no_cache(console_diagnostic_context, urls, {}, {});

auto http_codes_iter = result.begin();
for (auto& url : urls)
{
if (*http_codes_iter == 200)
{
auto sha = Hash::get_file_hash(fs, url.second, Hash::Algorithm::Sha512).value_or_exit(VCPKG_LINE_INFO);
if (seen_urls[url.first] != sha)
{
fmt::println("Error: Wrong sha for {}", url.first);
}
}
fs.remove(url.second, VCPKG_LINE_INFO);
++http_codes_iter;
}

Checks::exit_success(VCPKG_LINE_INFO);
}
}
3 changes: 3 additions & 0 deletions src/vcpkg/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#include <vcpkg/commands.z-upload-metrics.h>
#include <vcpkg/vcpkgcmdarguments.h>

#include "vcpkg/commands.check-tools-sha.h"

namespace vcpkg
{
static constexpr CommandRegistration<BasicCommandFn> basic_commands_storage[] = {
Expand All @@ -65,6 +67,7 @@ namespace vcpkg
{CommandDownloadMetadata, command_download_and_exit},
{CommandFormatFeatureBaselineMetadata, command_format_feature_baseline_and_exit},
{CommandHashMetadata, command_hash_and_exit},
{CommandCheckToolsShaMetadata, command_check_tools_sha_and_exit},
{CommandInitRegistryMetadata, command_init_registry_and_exit},
{CommandVersionMetadata, command_version_and_exit},
#if defined(_WIN32)
Expand Down
Loading