Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[vcpkg] Implementation of --x-binarysource=nuget (and friends) #12058

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2b1b0e8
[vcpkg] Initial implementation of --x-binarysource=nuget
ras0219-msft Jun 11, 2020
9c45e7b
Merge branch 'master' into dev/roschuma/nuget-binarycaching
ras0219-msft Jun 17, 2020
8c690a7
[vcpkg] Remove double-double quoting of CMake arguments
ras0219-msft Jun 17, 2020
862d73c
[vcpkg] Update nuget.exe to 5.5.1 to support Azure DevOps Artifacts
ras0219-msft Jun 17, 2020
ec56388
[vcpkg] Enable batching of NuGet server calls with prefetch(). Add `i…
ras0219-msft Jun 17, 2020
fbcc5de
[vcpkg] Add `nugetconfig` binary source
ras0219-msft Jun 17, 2020
fb4db0c
Merge remote-tracking branch 'origin/master' into dev/roschuma/nuget-…
ras0219-msft Jun 22, 2020
c512b02
[vcpkg] Short circuit querying remote NuGet servers once all refs are…
ras0219-msft Jun 22, 2020
b23aa70
[vcpkg] Add experimental help for binary caching
ras0219-msft Jun 22, 2020
17a7963
[vcpkg] Improved NuGet cache package descriptions and version formatting
ras0219-msft Jun 22, 2020
1e140ad
Merge remote-tracking branch 'origin/master' into dev/roschuma/nuget-…
ras0219-msft Jun 23, 2020
c41125d
[vcpkg] Rename `CmdLineBuilder::build()` to extract()
ras0219-msft Jun 25, 2020
78edd0d
[vcpkg-help] Ascii-betize help topics
ras0219-msft Jun 25, 2020
b0574f4
[vcpkg] Add tests for cmdlinebuilder. Improve handling of quotes and …
ras0219-msft Jun 25, 2020
54caa05
[vcpkg] Addressing code review comments
ras0219-msft Jun 26, 2020
add3ae9
[vcpkg] Add tests for vcpkg::reformat_version()
ras0219-msft Jun 26, 2020
0903807
[vcpkg] Added test for vcpkg::generate_nuspec()
ras0219-msft Jun 26, 2020
db1c64f
[vcpkg] Add tests for vcpkg::XmlSerializer
ras0219-msft Jun 26, 2020
45b2376
[vcpkg] Addressed code review comment
ras0219-msft Jun 26, 2020
c887b2b
[vcpkg] Add test for vcpkg::Strings::find_first_of
ras0219-msft Jun 26, 2020
1d238b5
[vcpkg] Fix machine-specific paths in test for vcpkg::generate_nuspec()
ras0219-msft Jun 26, 2020
0a39c1c
Merge remote-tracking branch 'origin/master' into dev/roschuma/nuget-…
ras0219-msft Jun 26, 2020
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
6 changes: 3 additions & 3 deletions scripts/vcpkgTools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
<sha512>f477842d0cebefcd6bf9c6d536ab8ea20ec5b0aa967ee963ab6a101aeff9df8742ca600d35f39e2e7158d76d8231f1ed2bef6104dce84d2bf8d6b07d17d706a1</sha512>
</tool>
<tool name="nuget" os="windows">
<version>4.8.1</version>
<version>5.5.1</version>
<exeRelativePath>nuget.exe</exeRelativePath>
<url>https://dist.nuget.org/win-x86-commandline/v4.8.1/nuget.exe</url>
<sha512>42cb744338af8decc033a75bce5b4c4df28e102bafc45f9a8ba86d7bc010f5b43ebacae80d7b28c4f85ac900eefc2a349620ae65f27f6ca1c21c53b63b92924b</sha512>
<url>https://dist.nuget.org/win-x86-commandline/v5.5.1/nuget.exe</url>
<sha512>22ea847d8017cd977664d0b13c889cfb13c89143212899a511be217345a4e243d4d8d4099700114a11d26a087e83eb1a3e2b03bdb5e0db48f10403184cd26619</sha512>
</tool>
<tool name="installerbase" os="windows">
<version>3.1.81</version>
Expand Down
2 changes: 2 additions & 0 deletions toolsrc/include/vcpkg/base/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ namespace vcpkg::Strings

std::vector<std::string> split(const std::string& s, const char delimiter);

const char* find_first_of(StringView input, StringView chars);

std::vector<StringView> find_all_enclosed(StringView input, StringView left_delim, StringView right_delim);

StringView find_exactly_one_enclosed(StringView input, StringView left_tag, StringView right_tag);
Expand Down
12 changes: 12 additions & 0 deletions toolsrc/include/vcpkg/base/system.process.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ namespace vcpkg::System
const fs::path& cmake_script,
const std::vector<CMakeVariable>& pass_variables);

struct CmdLineBuilder
ras0219 marked this conversation as resolved.
Show resolved Hide resolved
{
CmdLineBuilder& path_arg(const fs::path& p) { return string_arg(p.u8string()); }
CmdLineBuilder& string_arg(StringView s);
std::string build() { return std::move(buf); }
ras0219 marked this conversation as resolved.
Show resolved Hide resolved

operator ZStringView() const { return buf; }

private:
std::string buf;
};

fs::path get_exe_path_of_current_process();

struct ExitCodeAndOutput
Expand Down
12 changes: 11 additions & 1 deletion toolsrc/include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace vcpkg::Dependencies
{
struct InstallPlanAction;
struct ActionPlan;
}
namespace vcpkg::Build
{
Expand All @@ -27,10 +28,17 @@ namespace vcpkg
struct IBinaryProvider
{
virtual ~IBinaryProvider() = default;
virtual void prefetch() = 0;
/// Gives the BinaryProvider an opportunity to batch any downloading or server communication for executing
/// `plan`.
virtual void prefetch(const VcpkgPaths& paths, const Dependencies::ActionPlan& plan) = 0;
/// Attempts to restore the package referenced by `action` into the packages directory.
virtual RestoreResult try_restore(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
/// Called upon a successful build of `action`
virtual void push_success(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
/// Called upon a failure during the build of `action`
virtual void push_failure(const VcpkgPaths& paths, const std::string& abi_tag, const PackageSpec& spec) = 0;
/// Requests the result of `try_restore()` without actually downloading the package. Used by CI to determine
/// missing packages.
virtual RestoreResult precheck(const VcpkgPaths& paths,
const Dependencies::InstallPlanAction& action,
bool purge_tombstones) = 0;
Expand All @@ -42,4 +50,6 @@ namespace vcpkg
View<std::string> args);
ExpectedS<std::unique_ptr<IBinaryProvider>> create_binary_provider_from_configs_pure(const std::string& env_string,
View<std::string> args);

void help_topic_binary_caching(const VcpkgPaths& paths);
}
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace vcpkg
void example(StringView example_text);
void header(StringView name);
void blank();
void text(StringView text, int indent = 0);

std::string m_str;
};
Expand Down
84 changes: 84 additions & 0 deletions toolsrc/src/vcpkg-test/binaryconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,78 @@ TEST_CASE ("BinaryConfigParser files provider", "[binaryconfigparser]")
}
}

TEST_CASE ("BinaryConfigParser nuget source provider", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure("nuget", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget,relative-path", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget,http://example.org/", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH, {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",nonsense", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",upload", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget," ABSOLUTE_PATH ",upload,extra", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nuget,,upload", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser nuget config provider", "[binaryconfigparser]")
{
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig,relative-path", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig,http://example.org/", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH, {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",nonsense", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",upload", {});
REQUIRE(parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig," ABSOLUTE_PATH ",upload,extra", {});
REQUIRE(!parsed.has_value());
}
{
auto parsed = create_binary_provider_from_configs_pure("nugetconfig,,upload", {});
REQUIRE(!parsed.has_value());
}
}

TEST_CASE ("BinaryConfigParser default provider", "[binaryconfigparser]")
{
{
Expand Down Expand Up @@ -89,6 +161,18 @@ TEST_CASE ("BinaryConfigParser clear provider", "[binaryconfigparser]")
}
}

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

TEST_CASE ("BinaryConfigParser multiple providers", "[binaryconfigparser]")
{
{
Expand Down
5 changes: 5 additions & 0 deletions toolsrc/src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ std::vector<std::string> Strings::split(const std::string& s, const char delimit
}
}

const char* Strings::find_first_of(StringView input, StringView chars)
{
return std::find_first_of(input.begin(), input.end(), chars.begin(), chars.end());
ras0219 marked this conversation as resolved.
Show resolved Hide resolved
}

std::vector<StringView> Strings::find_all_enclosed(StringView input, StringView left_delim, StringView right_delim)
{
auto it_left = input.begin();
Expand Down
27 changes: 22 additions & 5 deletions toolsrc/src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace vcpkg
}

System::CMakeVariable::CMakeVariable(const StringView varname, const char* varvalue)
: s(Strings::format(R"("-D%s=%s")", varname, varvalue))
: s(Strings::format("-D%s=%s", varname, varvalue))
{
}
System::CMakeVariable::CMakeVariable(const StringView varname, const std::string& varvalue)
Expand All @@ -183,10 +183,27 @@ namespace vcpkg
const fs::path& cmake_script,
const std::vector<CMakeVariable>& pass_variables)
{
return Strings::format(R"("%s" %s -P "%s")",
cmake_tool_path.u8string(),
Strings::join(" ", pass_variables, [](auto&& v) { return v.s; }),
cmake_script.generic_u8string());
System::CmdLineBuilder cmd;
cmd.path_arg(cmake_tool_path);
for (auto&& var : pass_variables)
cmd.string_arg(var.s);
ras0219 marked this conversation as resolved.
Show resolved Hide resolved
cmd.string_arg("-P").path_arg(cmake_script);
return cmd.build();
}

System::CmdLineBuilder& System::CmdLineBuilder::string_arg(StringView s)
{
if (!buf.empty()) buf.push_back(' ');
if (Strings::find_first_of(s, " \t\n\r\"\\,;&`^|'") != s.end())
{
// TODO: improve this to properly handle all escaping
ras0219 marked this conversation as resolved.
Show resolved Hide resolved
Strings::append(buf, '"', s, '"');
}
else
{
Strings::append(buf, s);
}
return *this;
}

#if defined(_WIN32)
Expand Down
Loading