Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Http binary cache: One must use the {sha} variable if other variables are used. #1459

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1211,6 +1211,10 @@ DECLARE_MESSAGE(MissingAssetBlockOrigin,
(msg::path),
"x-block-origin is a vcpkg term. Do not translate",
"Missing {path} and downloads are blocked by x-block-origin.")
DECLARE_MESSAGE(MissingShaVariable,
(),
"{{sha}} should not be translated",
"The {{sha}} variable must be used in the template if other variables are used.")
DECLARE_MESSAGE(AssetCacheMissBlockOrigin,
(msg::path),
"x-block-origin is a vcpkg term. Do not translate",
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@
"_MissingRequiredField.comment": "Example completely formatted message:\nerror: missing required field 'dependencies' (an array of dependencies) An example of {json_field} is identifer. An example of {json_type} is an array of identifiers.",
"MissingRequiredField2": "missing required field '{json_field}'",
"_MissingRequiredField2.comment": "An example of {json_field} is identifer.",
"MissingShaVariable": "The {{sha}} variable must be used in the template if other variables are used.",
"_MissingShaVariable.comment": "{{sha}} should not be translated",
"MixingBooleanOperationsNotAllowed": "mixing & and | is not allowed; use () to specify order of operations",
"MonoInstructions": "This may be caused by an incomplete mono installation. Full mono is available on some systems via `sudo apt install mono-complete`. Ubuntu 18.04 users may need a newer version of mono, available at https://www.mono-project.com/download/stable/",
"MultiArch": "Multi-Arch must be 'same' but was {option}",
Expand Down
29 changes: 29 additions & 0 deletions src/vcpkg-test/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,35 @@ TEST_CASE ("BinaryConfigParser GCS provider", "[binaryconfigparser]")
}
}

TEST_CASE ("BinaryConfigParser HTTP provider", "[binaryconfigparser]")
{
{
auto parsed = parse_binary_provider_configs("http,http://example.org/", {});
auto state = parsed.value_or_exit(VCPKG_LINE_INFO);

REQUIRE(state.url_templates_to_get.size() == 1);
REQUIRE(state.url_templates_to_get[0].url_template == "http://example.org/{sha}.zip");
}
{
auto parsed = parse_binary_provider_configs("http,http://example.org", {});
auto state = parsed.value_or_exit(VCPKG_LINE_INFO);

REQUIRE(state.url_templates_to_get.size() == 1);
REQUIRE(state.url_templates_to_get[0].url_template == "http://example.org/{sha}.zip");
}
{
auto parsed = parse_binary_provider_configs("http,http://example.org/{triplet}/{sha}", {});
auto state = parsed.value_or_exit(VCPKG_LINE_INFO);

REQUIRE(state.url_templates_to_get.size() == 1);
REQUIRE(state.url_templates_to_get[0].url_template == "http://example.org/{triplet}/{sha}");
}
{
auto parsed = parse_binary_provider_configs("http,http://example.org/{triplet}", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("AssetConfigParser azurl provider", "[assetconfigparser]")
{
CHECK(parse_download_configuration({}));
Expand Down
24 changes: 24 additions & 0 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,30 @@ namespace
{
return add_error(std::move(err), segments[1].first);
}
bool has_sha = false;
bool has_other = false;
api_stable_format(url_template.url_template, [&](std::string&, StringView key) {
if (key == "sha")
{
has_sha = true;
}
else
{
has_other = true;
autoantwort marked this conversation as resolved.
Show resolved Hide resolved
}
});
if (!has_sha)
{
if (has_other)
{
return add_error(msg::format(msgMissingShaVariable), segments[1].first);
}
if (url_template.url_template.back() != '/')
{
url_template.url_template.push_back('/');
}
url_template.url_template.append("{sha}.zip");
}
if (segments.size() == 4)
{
url_template.headers.push_back(segments[3].second);
Expand Down
Loading