Skip to content

Commit

Permalink
[vcpkg] Add write-only binary caching for CI. (microsoft#12130)
Browse files Browse the repository at this point in the history
Changes to the binary caching spec made as comments over at microsoft#11204 (review)
  • Loading branch information
BillyONeal authored Jun 26, 2020
1 parent 5b85633 commit e27fb97
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 39 deletions.
28 changes: 22 additions & 6 deletions src/vcpkg-test/binaryconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ TEST_CASE ("BinaryConfigParser files provider", "[binaryconfigparser]")
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",upload", {});
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",read", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",upload,extra", {});
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",write", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",readwrite", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",readwrite,extra", {});
REQUIRE(!parsed.has_value());
}
{
Expand Down Expand Up @@ -140,11 +148,19 @@ TEST_CASE ("BinaryConfigParser default provider", "[binaryconfigparser]")
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,upload", {});
auto parsed = create_binary_provider_from_configs_pure("default,read", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,readwrite", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,write", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,upload,extra", {});
auto parsed = create_binary_provider_from_configs_pure("default,read,extra", {});
REQUIRE(!parsed.has_value());
}
}
Expand Down Expand Up @@ -180,11 +196,11 @@ TEST_CASE ("BinaryConfigParser multiple providers", "[binaryconfigparser]")
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("clear;default,upload", {});
auto parsed = create_binary_provider_from_configs_pure("clear;default,readwrite", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("clear;default,upload;clear;clear", {});
auto parsed = create_binary_provider_from_configs_pure("clear;default,readwrite;clear;clear", {});
REQUIRE(parsed.has_value());
}
{
Expand Down
99 changes: 66 additions & 33 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ namespace
}
}
void push_failure(const VcpkgPaths&, const std::string&, const PackageSpec&) override {}
RestoreResult precheck(const VcpkgPaths&, const Dependencies::InstallPlanAction&, bool) override
RestoreResult precheck(const VcpkgPaths&, const Dependencies::InstallPlanAction&) override
{
return RestoreResult::missing;
}
Expand Down Expand Up @@ -572,12 +572,11 @@ namespace
}
}
RestoreResult precheck(const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action,
bool purge_tombstones) override
const Dependencies::InstallPlanAction& action) override
{
for (auto&& provider : m_providers)
{
auto result = provider->precheck(paths, action, purge_tombstones);
auto result = provider->precheck(paths, action);
switch (result)
{
case RestoreResult::build_failed:
Expand All @@ -600,8 +599,8 @@ namespace
{
return RestoreResult::missing;
}
void push_success(const VcpkgPaths&, const Dependencies::InstallPlanAction&) override {}
void push_failure(const VcpkgPaths&, const std::string&, const PackageSpec&) override {}
void push_success(const VcpkgPaths&, const Dependencies::InstallPlanAction&) override { }
void push_failure(const VcpkgPaths&, const std::string&, const PackageSpec&) override { }
RestoreResult precheck(const VcpkgPaths&, const Dependencies::InstallPlanAction&) override
{
return RestoreResult::missing;
Expand Down Expand Up @@ -815,33 +814,48 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
else if (segments[0].second == "files")
{
if (segments.size() < 2)
{
return add_error("expected arguments: binary config 'files' requires at least a path argument",
segments[0].first);
}

auto p = fs::u8path(segments[1].second);
if (!p.is_absolute())
{
return add_error("expected arguments: path arguments for binary config strings must be absolute",
segments[1].first);
}

if (segments.size() > 3)
std::string mode;
switch (segments.size())
{
return add_error("unexpected arguments: binary config 'files' does not take more than 2 arguments",
segments[3].first);
case 2: mode = "read"; break;
case 3: mode = segments[2].second; break;
default:
return add_error("unexpected arguments: binary config 'files' requires 1 or 2 arguments",
segments[3].first);
}
else if (segments.size() == 3)

if (mode == "read")
{
if (segments[2].second != "upload")
{
return add_error("unexpected arguments: binary config 'files' can only accept 'upload' as "
"a second argument",
segments[2].first);
}
else
{
state->archives_to_write.push_back(p);
}
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);
}
state->archives_to_read.push_back(std::move(p));
}
else if (segments[0].second == "interactive")
{
Expand Down Expand Up @@ -916,30 +930,49 @@ ExpectedS<std::unique_ptr<IBinaryProvider>> vcpkg::create_binary_provider_from_c
else if (segments[0].second == "default")
{
if (segments.size() > 2)
{
return add_error("unexpected arguments: binary config 'default' does not take more than 1 argument",
segments[0].first);
}

auto&& maybe_home = System::get_platform_cache_home();
if (!maybe_home.has_value()) return add_error(maybe_home.error(), segments[0].first);

auto p = *maybe_home.get();
p /= fs::u8path("vcpkg/archives");
if (!p.is_absolute())
{
return add_error("default path was not absolute: " + p.u8string(), segments[0].first);
if (segments.size() == 2)
}

std::string mode;
switch (segments.size())
{
if (segments[1].second != "upload")
{
return add_error(
"unexpected arguments: binary config 'default' can only accept 'upload' as an argument",
segments[1].first);
}
else
{
state->archives_to_write.push_back(p);
}
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);
}
state->archives_to_read.push_back(std::move(p));
}
else
{
Expand Down

0 comments on commit e27fb97

Please sign in to comment.