[vcpkg] Move default binary cache from `$root/archives` to user-wide directory
* [vcpkg] Move default binary cache from `$root/archives` to user-wide directory
Teach nuget/nugetconfig binary sources to use read/write.
* [vcpkg] Reformat
MODIFY
include/vcpkg/binarycaching.h
include/vcpkg/binarycaching.h
@@ -42,8 +42,7 @@ namespace vcpkg
IBinaryProvider& null_binary_provider();
- ExpectedS<std::unique_ptr<IBinaryProvider>> create_binary_provider_from_configs(const VcpkgPaths& paths,
- View<std::string> args);
+ ExpectedS<std::unique_ptr<IBinaryProvider>> create_binary_provider_from_configs(View<std::string> args);
ExpectedS<std::unique_ptr<IBinaryProvider>> create_binary_provider_from_configs_pure(const std::string& env_string,
View<std::string> args);

MODIFY
src/vcpkg-test/binaryconfigparser.cpp
src/vcpkg-test/binaryconfigparser.cpp
@@ -89,15 +89,15 @@ TEST_CASE ("BinaryConfigParser nuget source provider", "[binaryconfigparser]")
REQUIRE(!parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",upload", {});
+ auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",readwrite", {});
REQUIRE(parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",upload,extra", {});
+ auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",readwrite,extra", {});
REQUIRE(!parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nuget,,upload", {});
+ auto parsed = create_binary_provider_from_configs_pure("nuget,,readwrite", {});
REQUIRE(!parsed.has_value());
}
}
@@ -125,15 +125,23 @@ TEST_CASE ("BinaryConfigParser nuget config provider", "[binaryconfigparser]")
REQUIRE(!parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",upload", {});
+ auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",read", {});
REQUIRE(parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",upload,extra", {});
+ auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",write", {});
+ REQUIRE(parsed.has_value());
+ }
+ {
+ auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",readwrite", {});
+ REQUIRE(parsed.has_value());
+ }
+ {
+ auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",readwrite,extra", {});
REQUIRE(!parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("nugetconfig,,upload", {});
+ auto parsed = create_binary_provider_from_configs_pure("nugetconfig,,readwrite", {});
REQUIRE(!parsed.has_value());
}
}
@@ -185,7 +193,7 @@ TEST_CASE ("BinaryConfigParser interactive provider", "[binaryconfigparser]")
REQUIRE(parsed.has_value());
}
{
- auto parsed = create_binary_provider_from_configs_pure("interactive,upload", {});
+ auto parsed = create_binary_provider_from_configs_pure("interactive,read", {});
REQUIRE(!parsed.has_value());
}
}
@@ -196,6 +204,14 @@ TEST_CASE ("BinaryConfigParser multiple providers", "[binaryconfigparser]")
auto parsed = create_binary_provider_from_configs_pure("clear;default", {});
REQUIRE(parsed.has_value());
}
+ {
+ auto parsed = create_binary_provider_from_configs_pure("clear;default,read", {});
+ REQUIRE(parsed.has_value());
+ }
+ {
+ auto parsed = create_binary_provider_from_configs_pure("clear;default,write", {});
+ REQUIRE(parsed.has_value());
+ }
{
auto parsed = create_binary_provider_from_configs_pure("clear;default,readwrite", {});
REQUIRE(parsed.has_value());

MODIFY
src/vcpkg/binarycaching.cpp
src/vcpkg/binarycaching.cpp
@@ -651,23 +651,13 @@ IBinaryProvider& vcpkg::null_binary_provider()
return p;
}
-ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_configs(const VcpkgPaths& paths,
- View<std::string> args)
+ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_configs(View<std::string> args)
{
std::string env_string = System::get_environment_variable("VCPKG_BINARY_SOURCES").value_or("");
- // Preserve existing behavior until CI can be updated
- // TODO: remove
- if (args.size() == 0 && env_string.empty())
- {
- auto p = paths.root / fs::u8path("archives");
- return {std::make_unique<ArchivesBinaryProvider>(std::vector<fs::path>{p}, std::vector<fs::path>{p})};
- }
-
return create_binary_provider_from_configs_pure(env_string, args);
}
-ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_configs_pure(
- const std::string& env_string, View<std::string> args)
+namespace
{
struct State
{
@@ -755,6 +745,41 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
}
}
+ template<class T>
+ void handle_readwrite(std::vector<T>& read,
+ std::vector<T>& write,
+ T&& t,
+ const std::vector<std::pair<SourceLoc, std::string>>& segments,
+ size_t segment_idx)
+ {
+ if (segment_idx >= segments.size())
+ {
+ read.push_back(std::move(t));
+ return;
+ }
+
+ auto& mode = segments[segment_idx].second;
+
+ if (mode == "read")
+ {
+ read.push_back(std::move(t));
+ }
+ else if (mode == "write")
+ {
+ write.push_back(std::move(t));
+ }
+ else if (mode == "readwrite")
+ {
+ read.push_back(t);
+ write.push_back(std::move(t));
+ }
+ else
+ {
+ return add_error("unexpected argument: expected 'read', readwrite', or 'write'",
+ segments[segment_idx].first);
+ }
+ }
+
void handle_segments(std::vector<std::pair<SourceLoc, std::string>>&& segments)
{
if (segments.empty()) return;
@@ -779,38 +804,11 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
return add_error("expected arguments: path arguments for binary config strings must be absolute",
segments[1].first);
}
-
- std::string mode;
- switch (segments.size())
- {
- case 2: mode = "read"; break;
- case 3: mode = segments[2].second; break;
- default:
+ handle_readwrite(state->archives_to_read, state->archives_to_write, std::move(p), segments, 2);
+ if (segments.size() > 3)
return add_error("unexpected arguments: binary config 'files' requires 1 or 2 arguments",
segments[3].first);
}
-
- if (mode == "read")
- {
- state->archives_to_read.push_back(std::move(p));
- }
- else if (mode == "write")
- {
- state->archives_to_write.push_back(std::move(p));
- }
- else if (mode == "readwrite")
- {
- state->archives_to_read.push_back(p);
- state->archives_to_write.push_back(std::move(p));
- }
- else
- {
- Checks::check_exit(VCPKG_LINE_INFO, segments.size() > 2);
- return add_error("unexpected arguments: binary config 'files' can only accept"
- " 'read', readwrite', or 'write' as a second argument",
- segments[2].first);
- }
- }
else if (segments[0].second == "interactive")
{
if (segments.size() > 1)
@@ -829,29 +827,11 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
if (!p.is_absolute())
return add_error("expected arguments: path arguments for binary config strings must be absolute",
segments[1].first);
-
+ handle_readwrite(state->configs_to_read, state->configs_to_write, std::move(p), segments, 2);
if (segments.size() > 3)
- {
- return add_error(
- "unexpected arguments: binary config 'nugetconfig' does not take more than 2 arguments",
+ return add_error("unexpected arguments: binary config 'nugetconfig' requires 1 or 2 arguments",
segments[3].first);
}
- else if (segments.size() == 3)
- {
- if (segments[2].second != "upload")
- {
- return add_error(
- "unexpected arguments: binary config 'nugetconfig' can only accept 'upload' as "
- "a second argument",
- segments[2].first);
- }
- else
- {
- state->configs_to_write.push_back(p);
- }
- }
- state->configs_to_read.push_back(std::move(p));
- }
else if (segments[0].second == "nuget")
{
if (segments.size() < 2)
@@ -861,26 +841,12 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
auto&& p = segments[1].second;
if (p.empty())
return add_error("unexpected arguments: binary config 'nuget' requires non-empty source");
+
+ handle_readwrite(state->sources_to_read, state->sources_to_write, std::move(p), segments, 2);
if (segments.size() > 3)
- {
- return add_error("unexpected arguments: binary config 'nuget' does not take more than 2 arguments",
+ return add_error("unexpected arguments: binary config 'nuget' requires 1 or 2 arguments",
segments[3].first);
}
- else if (segments.size() == 3)
- {
- if (segments[2].second != "upload")
- {
- return add_error("unexpected arguments: binary config 'nuget' can only accept 'upload' as "
- "a second argument",
- segments[2].first);
- }
- else
- {
- state->sources_to_write.push_back(p);
- }
- }
- state->sources_to_read.push_back(std::move(p));
- }
else if (segments[0].second == "default")
{
if (segments.size() > 2)
@@ -899,34 +865,7 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
return add_error("default path was not absolute: " + p.u8string(), segments[0].first);
}
- std::string mode;
- switch (segments.size())
- {
- case 1: mode = "read"; break;
- case 2: mode = segments[1].second; break;
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
-
- if (mode == "read")
- {
- state->archives_to_read.push_back(std::move(p));
- }
- else if (mode == "write")
- {
- state->archives_to_write.push_back(std::move(p));
- }
- else if (mode == "readwrite")
- {
- state->archives_to_read.push_back(p);
- state->archives_to_write.push_back(std::move(p));
- }
- else
- {
- Checks::check_exit(VCPKG_LINE_INFO, segments.size() > 1);
- return add_error("unexpected arguments: binary config 'default' can only accept"
- " 'read', readwrite', or 'write' as a first argument",
- segments[1].first);
- }
+ handle_readwrite(state->archives_to_read, state->archives_to_write, std::move(p), segments, 1);
}
else
{
@@ -937,9 +876,16 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
}
}
};
+}
+ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_configs_pure(
+ const std::string& env_string, View<std::string> args)
+{
State s;
+ BinaryConfigParser default_parser("default,readwrite", "<defaults>", &s);
+ default_parser.parse();
+
BinaryConfigParser env_parser(env_string, "VCPKG_BINARY_SOURCES", &s);
env_parser.parse();
if (auto err = env_parser.get_error()) return err->format();

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -164,8 +164,7 @@ namespace vcpkg::Build
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
std::string first_arg = args.command_arguments.at(0);
- auto binaryprovider =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ auto binaryprovider = create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
const FullPackageSpec spec = Input::check_and_get_full_package_spec(
std::move(first_arg), default_triplet, COMMAND_STRUCTURE.example_text);

MODIFY
src/vcpkg/commands.buildexternal.cpp
src/vcpkg/commands.buildexternal.cpp
@@ -21,8 +21,7 @@ namespace vcpkg::Commands::BuildExternal
{
const ParsedArguments options = args.parse_arguments(COMMAND_STRUCTURE);
- auto binaryprovider =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ auto binaryprovider = create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
const FullPackageSpec spec = Input::check_and_get_full_package_spec(
std::string(args.command_arguments.at(0)), default_triplet, COMMAND_STRUCTURE.example_text);

MODIFY
src/vcpkg/commands.ci.cpp
src/vcpkg/commands.ci.cpp
@@ -404,7 +404,7 @@ namespace vcpkg::Commands::CI
if (args.binary_caching_enabled())
{
binaryproviderStorage =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
}
IBinaryProvider& binaryprovider = binaryproviderStorage ? *binaryproviderStorage : null_binary_provider();

MODIFY
src/vcpkg/commands.setinstalled.cpp
src/vcpkg/commands.setinstalled.cpp
@@ -141,8 +141,7 @@ namespace vcpkg::Commands::SetInstalled
Input::check_triplet(spec.package_spec.triplet(), paths);
}
- auto binary_provider =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ auto binary_provider = create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
const bool dry_run = Util::Sets::contains(options.switches, OPTION_DRY_RUN);

MODIFY
src/vcpkg/commands.upgrade.cpp
src/vcpkg/commands.upgrade.cpp
@@ -41,8 +41,7 @@ namespace vcpkg::Commands::Upgrade
const bool no_dry_run = Util::Sets::contains(options.switches, OPTION_NO_DRY_RUN);
const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING));
- auto binaryprovider =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ auto binaryprovider = create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
StatusParagraphs status_db = database_load_check(paths);

MODIFY
src/vcpkg/install.cpp
src/vcpkg/install.cpp
@@ -672,8 +672,7 @@ namespace vcpkg::Install
const ParsedArguments options =
args.parse_arguments(paths.manifest_mode_enabled() ? MANIFEST_COMMAND_STRUCTURE : COMMAND_STRUCTURE);
- auto binaryprovider =
- create_binary_provider_from_configs(paths, args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
+ auto binaryprovider = create_binary_provider_from_configs(args.binary_sources).value_or_exit(VCPKG_LINE_INFO);
const bool dry_run = Util::Sets::contains(options.switches, OPTION_DRY_RUN);
const bool use_head_version = Util::Sets::contains(options.switches, (OPTION_USE_HEAD_VERSION));

[vcpkg] Move default binary cache from `$root/archives` to user-wide directory (#12256)

* [vcpkg] Move default binary cache from `$root/archives` to user-wide directory

Teach nuget/nugetconfig binary sources to use read/write.

* [vcpkg] Reformat

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>