Skip to content

Commit

Permalink
[vcpkg] Add support for VCPKG_BINARY_SOURCES and --x-binarysource=<> (m…
Browse files Browse the repository at this point in the history
…icrosoft#10476)

* [vcpkg] Add support for VCPKG_BINARY_SOURCES and --binarysource=<>

* [vcpkg] Rename --binarysource to --x-binarysource to denote internal/experimental

* [vcpkg] Address review comments & add tests for BinaryConfigParser

* [vcpkg] Replace do {} while(1); with for(;;)

Avoids conditional expresion is constant warnings

* [vcpkg] Invert if/else

* [vcpkg] Fix warning in export.prefab.cpp

* [vcpkg] Resolve merge regressions
  • Loading branch information
ras0219-msft authored Apr 29, 2020
1 parent 09e0a74 commit 6b0c1f4
Show file tree
Hide file tree
Showing 17 changed files with 570 additions and 122 deletions.
2 changes: 2 additions & 0 deletions include/vcpkg/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace vcpkg::System
{
Optional<std::string> get_environment_variable(ZStringView varname) noexcept;

ExpectedS<std::string> get_home_dir() noexcept;

Optional<std::string> get_registry_string(void* base_hkey, StringView subkey, StringView valuename);

enum class CPUArchitecture
Expand Down
6 changes: 5 additions & 1 deletion include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <vcpkg/base/expected.h>
#include <vcpkg/base/files.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/vcpkgpaths.h>
Expand Down Expand Up @@ -35,5 +36,8 @@ namespace vcpkg
bool purge_tombstones) = 0;
};

std::unique_ptr<IBinaryProvider> create_archives_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_pure(const std::string& env_string,
View<std::string> args);
}
3 changes: 2 additions & 1 deletion include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace vcpkg::Build
void perform_and_exit_ex(const FullPackageSpec& full_spec,
const SourceControlFileLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
IBinaryProvider& binaryprovider,
const VcpkgPaths& paths);

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
Expand Down Expand Up @@ -209,7 +210,7 @@ namespace vcpkg::Build

ExtendedBuildResult build_package(const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& config,
IBinaryProvider* binaries_provider,
IBinaryProvider& binaries_provider,
const StatusParagraphs& status_db);

enum class BuildPolicy
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace vcpkg::Install
const KeepGoing keep_going,
const VcpkgPaths& paths,
StatusParagraphs& status_db,
IBinaryProvider& binaryprovider,
const CMakeVars::CMakeVarProvider& var_provider);

extern const CommandStructure COMMAND_STRUCTURE;
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace vcpkg
std::unique_ptr<std::string> triplet;
std::unique_ptr<std::vector<std::string>> overlay_ports;
std::unique_ptr<std::vector<std::string>> overlay_triplets;
std::vector<std::string> binarysources;
Optional<bool> debug = nullopt;
Optional<bool> sendmetrics = nullopt;
Optional<bool> printmetrics = nullopt;
Expand Down
183 changes: 183 additions & 0 deletions src/vcpkg-test/binaryconfigparser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include <catch2/catch.hpp>
#include <vcpkg/binarycaching.h>

using namespace vcpkg;

#if defined(_WIN32)
#define ABSOLUTE_PATH "C:\\foo"
#else
#define ABSOLUTE_PATH "/foo"
#endif

TEST_CASE ("BinaryConfigParser empty", "[binaryconfigparser]")
{
auto parsed = create_binary_provider_from_configs_pure("", {});
REQUIRE(parsed.has_value());
}

TEST_CASE ("BinaryConfigParser unacceptable provider", "[binaryconfigparser]")
{
auto parsed = create_binary_provider_from_configs_pure("unacceptable", {});
REQUIRE(!parsed.has_value());
}

TEST_CASE ("BinaryConfigParser files provider", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure("files", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files,relative-path", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files,C:foo", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH, {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",nonsense", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",upload", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",upload,extra", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files,,upload", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser default provider", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure("default", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,nonsense", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,upload", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("default,upload,extra", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser clear provider", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure("clear", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("clear,upload", {});
REQUIRE(!parsed.has_value());
}
}

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,upload", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("clear;default,upload;clear;clear", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("clear;files,relative;default", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure(";;;clear;;;;", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure(";;;,;;;;", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser escaping", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure(";;;;;;;`", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure(";;;;;;;`defaul`t", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH "`", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH "`,", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH "``", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH "```", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH "````", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH ",", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser args", "[binaryconfigparser]")
{
{
auto parsed =
create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH, std::vector<std::string>{"clear"});
REQUIRE(parsed.has_value());
}
{
auto parsed =
create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH, std::vector<std::string>{"clear;default"});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH,
std::vector<std::string>{"clear;default,"});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH,
std::vector<std::string>{"clear", "clear;default,"});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("files," ABSOLUTE_PATH,
std::vector<std::string>{"clear", "clear"});
REQUIRE(parsed.has_value());
}
}
13 changes: 13 additions & 0 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ namespace vcpkg
#endif // defined(_WIN32)
}

ExpectedS<std::string> System::get_home_dir() noexcept
{
#ifdef _WIN32
auto maybe_home = System::get_environment_variable("USERPROFILE");
if (!maybe_home.has_value() || maybe_home.get()->empty())
return {"unable to read %USERPROFILE%", ExpectedRightTag{}};
#else
auto maybe_home = System::get_environment_variable("HOME");
if (!maybe_home.has_value() || maybe_home.get()->empty()) return {"unable to read $HOME", ExpectedRightTag{}};
#endif
return {std::move(*maybe_home.get()), ExpectedLeftTag{}};
}

#if defined(_WIN32)
static bool is_string_keytype(const DWORD hkey_type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ namespace vcpkg

std::wstring out_env;

while (1)
for (;;)
{
auto eq = std::find(it, e, '=');
if (eq == e) break;
Expand Down
Loading

0 comments on commit 6b0c1f4

Please sign in to comment.