Skip to content

Commit 4433017

Browse files
committed
PR comments WIP
1 parent bc7816e commit 4433017

File tree

11 files changed

+300
-219
lines changed

11 files changed

+300
-219
lines changed

azure-pipelines/end-to-end-tests-dir/asset-caching.ps1

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,10 @@ if (-not ($actual -match $expected)) {
188188
}
189189

190190
# ... also with multiple authoritative URLs
191-
if ($IsWindows) {
192-
Refresh-TestRoot
193-
$expected = @(
194-
"^Downloading example3\.html, trying https://nonexistent\.example\.com",
195-
"Trying https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt",
196-
"Successfully downloaded example3\.html",
197-
"$"
198-
) -join "`n"
199-
200-
$actual = Run-VcpkgAndCaptureOutput @commonArgs x-download "$TestDownloadsRoot/example3.html" --sha512 65077997890f66f6041bb3284bb7b88e27631411ccbc253201ca4e00c4bcc58c0d77edffda4975498797cc10772c7fd68fbeb13cc4ac493a3471a9d49e5b6f24 --url https://nonexistent.example.com --url https://raw.githubusercontent.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE.txt
201-
Throw-IfFailed
202-
if (-not ($actual -match $expected)) {
203-
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed)"
204-
}
205-
}
206-
207-
# Force curl with --header
208191
Refresh-TestRoot
209192
$expected = @(
210193
"^Downloading example3\.html, trying https://nonexistent\.example\.com",
194+
"error: curl operation failed with error code 6 \(Couldn't resolve host name\)\. This is a non-transient error, won't retry downloading from https://nonexistent\.example\.com",
211195
"Trying https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt"
212196
"Successfully downloaded example3\.html",
213197
"$"

include/vcpkg/base/contractual-constants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ namespace vcpkg
207207
inline constexpr StringLiteral SwitchDebug = "debug";
208208
inline constexpr StringLiteral SwitchDebugBin = "debug-bin";
209209
inline constexpr StringLiteral SwitchDebugEnv = "debug-env";
210-
inline constexpr StringLiteral SwitchDeleteFileAfterUpload = "delete-file-after-upload";
211210
inline constexpr StringLiteral SwitchDgml = "dgml";
212211
inline constexpr StringLiteral SwitchDisableMetrics = "disable-metrics";
213212
inline constexpr StringLiteral SwitchDot = "dot";

include/vcpkg/base/curl.h

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
1+
#pragma once
12

2-
#ifdef _MSC_VER
3-
#pragma warning(push) // Save current warning state
4-
#pragma warning(disable : 6101) // Disable specific warning (e.g., warning 4996)
5-
#endif
3+
#include <vcpkg/base/fwd/span.h>
64

5+
#include <vcpkg/base/pragmas.h>
6+
7+
#include <vcpkg/commands.version.h>
8+
9+
VCPKG_MSVC_WARNING(push)
10+
// note: disable warning triggered by curl headers
11+
// ws2tcpip.h(968): warning C6101: Returning uninitialized memory '*Mtu': A successful path through the function does
12+
// not set the named _Out_ parameter.
13+
VCPKG_MSVC_WARNING(disable : 6101)
714
#include <curl/curl.h>
815
#include <curl/multi.h>
9-
10-
#ifdef _MSC_VER
11-
#pragma warning(pop)
12-
#endif
16+
VCPKG_MSVC_WARNING(pop)
1317

1418
namespace vcpkg
1519
{
16-
CURLcode curl_global_init_status() noexcept;
20+
CURLcode get_curl_global_init_status() noexcept;
21+
22+
struct CurlEasyHandle
23+
{
24+
CurlEasyHandle();
25+
CurlEasyHandle(CurlEasyHandle&& other) noexcept;
26+
CurlEasyHandle& operator=(CurlEasyHandle&& other) noexcept;
27+
~CurlEasyHandle();
28+
29+
CURL* get();
30+
31+
private:
32+
CURL* m_ptr = nullptr;
33+
};
34+
35+
struct CurlMultiHandle
36+
{
37+
CurlMultiHandle();
38+
CurlMultiHandle(CurlMultiHandle&& other) noexcept;
39+
CurlMultiHandle& operator=(CurlMultiHandle&& other) noexcept;
40+
~CurlMultiHandle();
41+
42+
// Adds an easy handle to the multi handle but doesn't take ownership of it.
43+
// Makes sure that the easy handle is removed from the multi handle on cleanup.
44+
void add_easy_handle(CurlEasyHandle& easy_handle);
45+
46+
CURLM* get();
47+
48+
private:
49+
CURLM* m_ptr = nullptr;
50+
std::vector<CURL*> m_easy_handles;
51+
};
52+
53+
struct CurlHeaders
54+
{
55+
CurlHeaders();
56+
CurlHeaders(View<std::string> headers);
57+
CurlHeaders(CurlHeaders&& other) noexcept;
58+
CurlHeaders& operator=(CurlHeaders&& other) noexcept;
59+
~CurlHeaders();
60+
61+
curl_slist* get() const;
62+
63+
private:
64+
curl_slist* m_headers = nullptr;
65+
};
66+
67+
constexpr char vcpkg_curl_user_agent[] =
68+
"vcpkg/" VCPKG_BASE_VERSION_AS_STRING "-" VCPKG_VERSION_AS_STRING " (curl)";
1769
}

include/vcpkg/base/message-data.inc.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ DECLARE_MESSAGE(CmdUpdateRegistryAllOrTargets,
863863
(),
864864
"",
865865
"Update registry requires either a list of artifact registry names or URiIs to update, or --all.")
866-
DECLARE_MESSAGE(CmdUploadMetricsDeleteFileAfterUpload, (), "", "Delete metrics payload file after upload")
867866
DECLARE_MESSAGE(CmdUpgradeOptNoDryRun, (), "", "Actually upgrade")
868867
DECLARE_MESSAGE(CmdUpgradeOptNoKeepGoing, (), "", "Stop installing packages on failure")
869868
DECLARE_MESSAGE(CmdUseExample1,
@@ -964,13 +963,17 @@ DECLARE_MESSAGE(CreatingNuGetPackage, (), "", "Creating NuGet package...")
964963
DECLARE_MESSAGE(CreatingZipArchive, (), "", "Creating zip archive...")
965964
DECLARE_MESSAGE(CreationFailed, (msg::path), "", "Creating {path} failed.")
966965
DECLARE_MESSAGE(CurlFailedGeneric,
967-
(msg::exit_code, msg::error_msg),
966+
(msg::exit_code),
968967
"curl is the name of a program, see curl.se.",
969-
"curl operation failed with error code {exit_code} ({error_msg}).")
970-
DECLARE_MESSAGE(CurlFailedGenericWithRetry,
971-
(msg::exit_code, msg::error_msg, msg::count, msg::value),
972-
"curl is the name of a program, see curl.se. {value} is the maximum amount of retries.",
973-
"curl operation failed with error code {exit_code} ({error_msg}) retry {count} of {value}.")
968+
"curl operation failed with error code {exit_code}")
969+
DECLARE_MESSAGE(CurlFailedGenericNoRetryAddendum,
970+
(msg::url),
971+
"curl is the name of a program, see curl.se.",
972+
"This is a non-transient error, won't retry downloading from {url}.")
973+
DECLARE_MESSAGE(CurlFailedTimeoutRetry,
974+
(msg::count, msg::value),
975+
"{count} is the current retry atttempt, {value} is the maximum amount of retries.",
976+
"The operation timed out retry {count} of {value}.")
974977
DECLARE_MESSAGE(CurlFailedHttpResponse,
975978
(msg::exit_code),
976979
"curl is the name of a program, see curl.se.",
@@ -979,10 +982,10 @@ DECLARE_MESSAGE(CurlFailedHttpResponseWithRetry,
979982
(msg::exit_code, msg::count, msg::value),
980983
"curl is the name of a program, see curl.se. {value} is the maximum amount of retries.",
981984
"curl operation failed with HTTP response code {exit_code} retry {count} of {value}.")
982-
DECLARE_MESSAGE(CurlFailedToPutHttp,
983-
(msg::exit_code, msg::error_msg, msg::url, msg::value),
985+
DECLARE_MESSAGE(CurlFailedToPut,
986+
(msg::url, msg::value),
984987
"curl is the name of a program, see curl.se. {value} is an HTTP status code",
985-
"curl failed to put file to {url} with exit code {exit_code} ({error_msg}) and http code {value}.")
988+
"curl failed to PUT file to {url} with response code {value}.")
986989
DECLARE_MESSAGE(CurrentCommitBaseline,
987990
(msg::commit_sha),
988991
"",

include/vcpkg/metrics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,5 @@ namespace vcpkg
198198
extern std::atomic<bool> g_should_send_metrics;
199199

200200
void flush_global_metrics(const Filesystem&);
201-
bool curl_upload_metrics(StringView payload);
201+
bool curl_upload_metrics(const std::string& payload);
202202
}

locales/messages.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@
502502
"CmdUpdateRegistrySynopsis": "Re-downloads an artifact registry",
503503
"CmdUpgradeOptNoDryRun": "Actually upgrade",
504504
"CmdUpgradeOptNoKeepGoing": "Stop installing packages on failure",
505-
"CmdUploadMetricsDeleteFileAfterUpload": "Delete metrics payload file after upload",
506505
"CmdUseExample1": "vcpkg use <artifact name>",
507506
"_CmdUseExample1.comment": "This is a command line, only the <artifact name> part should be localized.",
508507
"CmdUseSynopsis": "Activate a single artifact in this shell",
@@ -561,16 +560,18 @@
561560
"CreatingZipArchive": "Creating zip archive...",
562561
"CreationFailed": "Creating {path} failed.",
563562
"_CreationFailed.comment": "An example of {path} is /foo/bar.",
564-
"CurlFailedGeneric": "curl operation failed with error code {exit_code} ({error_msg}).",
565-
"_CurlFailedGeneric.comment": "curl is the name of a program, see curl.se. An example of {exit_code} is 127. An example of {error_msg} is File Not Found.",
566-
"CurlFailedGenericWithRetry": "curl operation failed with error code {exit_code} ({error_msg}) retry {count} of {value}.",
567-
"_CurlFailedGenericWithRetry.comment": "curl is the name of a program, see curl.se. {value} is the maximum amount of retries. An example of {exit_code} is 127. An example of {error_msg} is File Not Found. An example of {count} is 42.",
563+
"CurlFailedGeneric": "curl operation failed with error code {exit_code}",
564+
"_CurlFailedGeneric.comment": "curl is the name of a program, see curl.se. An example of {exit_code} is 127.",
565+
"CurlFailedGenericNoRetryAddendum": "This is a non-transient error, won't retry downloading from {url}.",
566+
"_CurlFailedGenericNoRetryAddendum.comment": "curl is the name of a program, see curl.se. An example of {url} is https://github.com/microsoft/vcpkg.",
568567
"CurlFailedHttpResponse": "curl operation failed with HTTP response code {exit_code}.",
569568
"_CurlFailedHttpResponse.comment": "curl is the name of a program, see curl.se. An example of {exit_code} is 127.",
570569
"CurlFailedHttpResponseWithRetry": "curl operation failed with HTTP response code {exit_code} retry {count} of {value}.",
571570
"_CurlFailedHttpResponseWithRetry.comment": "curl is the name of a program, see curl.se. {value} is the maximum amount of retries. An example of {exit_code} is 127. An example of {count} is 42.",
572-
"CurlFailedToPutHttp": "curl failed to put file to {url} with exit code {exit_code} ({error_msg}) and http code {value}.",
573-
"_CurlFailedToPutHttp.comment": "curl is the name of a program, see curl.se. {value} is an HTTP status code An example of {exit_code} is 127. An example of {error_msg} is File Not Found. An example of {url} is https://github.com/microsoft/vcpkg.",
571+
"CurlFailedTimeoutRetry": "The operation timed out retry {count} of {value}.",
572+
"_CurlFailedTimeoutRetry.comment": "{count} is the current retry atttempt, {value} is the maximum amount of retries. An example of {count} is 42.",
573+
"CurlFailedToPut": "curl failed to PUT file to {url} with response code {value}.",
574+
"_CurlFailedToPut.comment": "curl is the name of a program, see curl.se. {value} is an HTTP status code An example of {url} is https://github.com/microsoft/vcpkg.",
574575
"CurrentCommitBaseline": "You can use the current commit as a baseline, which is:\n\t\"builtin-baseline\": \"{commit_sha}\"",
575576
"_CurrentCommitBaseline.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
576577
"CycleDetectedDuring": "cycle detected during {spec}:",

src/vcpkg.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ namespace
136136

137137
void inner(const Filesystem& fs, const VcpkgCmdArguments& args, const BundleSettings& bundle)
138138
{
139-
// Ensure that we call curl_global_init only once in the program.
140-
if (CURLE_OK != curl_global_init_status())
141-
{
142-
Debug::println("Failed to initialize CURL");
143-
}
144-
145139
// track version on each invocation
146140
get_global_metrics_collector().track_string(StringMetric::VcpkgVersion, vcpkg_executable_version);
147141

src/vcpkg/base/curl.cpp

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#include <vcpkg/base/checks.h>
12
#include <vcpkg/base/curl.h>
23

3-
namespace vcpkg
4+
namespace
45
{
56
struct CurlGlobalInit
67
{
@@ -17,10 +18,107 @@ namespace vcpkg
1718
private:
1819
CURLcode init_status;
1920
};
21+
}
2022

21-
CURLcode curl_global_init_status() noexcept
23+
namespace vcpkg
24+
{
25+
CURLcode get_curl_global_init_status() noexcept
2226
{
2327
static CurlGlobalInit g_curl_global_init;
2428
return g_curl_global_init.get_init_status();
2529
}
30+
31+
CurlEasyHandle::CurlEasyHandle() : m_ptr(nullptr) { vcpkg::get_curl_global_init_status(); }
32+
CurlEasyHandle::CurlEasyHandle(CurlEasyHandle&& other) noexcept : m_ptr(std::exchange(other.m_ptr, nullptr)) { }
33+
CurlEasyHandle& CurlEasyHandle::operator=(CurlEasyHandle&& other) noexcept
34+
{
35+
m_ptr = std::exchange(other.m_ptr, nullptr);
36+
return *this;
37+
}
38+
CurlEasyHandle::~CurlEasyHandle()
39+
{
40+
if (m_ptr)
41+
{
42+
curl_easy_cleanup(m_ptr);
43+
}
44+
}
45+
CURL* CurlEasyHandle::get()
46+
{
47+
if (!m_ptr)
48+
{
49+
m_ptr = curl_easy_init();
50+
if (!m_ptr)
51+
{
52+
Checks::unreachable(VCPKG_LINE_INFO);
53+
}
54+
}
55+
return m_ptr;
56+
}
57+
58+
CurlMultiHandle::CurlMultiHandle() : m_ptr(nullptr) { vcpkg::get_curl_global_init_status(); }
59+
CurlMultiHandle::CurlMultiHandle(CurlMultiHandle&& other) noexcept
60+
: m_ptr(std::exchange(other.m_ptr, nullptr)), m_easy_handles(std::move(other.m_easy_handles))
61+
{
62+
}
63+
CurlMultiHandle& CurlMultiHandle::operator=(CurlMultiHandle&& other) noexcept
64+
{
65+
m_ptr = std::exchange(other.m_ptr, nullptr);
66+
m_easy_handles = std::move(other.m_easy_handles);
67+
return *this;
68+
}
69+
CurlMultiHandle::~CurlMultiHandle()
70+
{
71+
for (auto* easy_handle : m_easy_handles)
72+
{
73+
curl_multi_remove_handle(m_ptr, easy_handle);
74+
}
75+
76+
if (m_ptr)
77+
{
78+
curl_multi_cleanup(m_ptr);
79+
}
80+
}
81+
void CurlMultiHandle::add_easy_handle(CurlEasyHandle& easy_handle)
82+
{
83+
auto* handle = easy_handle.get();
84+
if (curl_multi_add_handle(this->get(), handle) == CURLM_OK)
85+
{
86+
m_easy_handles.push_back(handle);
87+
}
88+
}
89+
CURLM* CurlMultiHandle::get()
90+
{
91+
if (!m_ptr)
92+
{
93+
m_ptr = curl_multi_init();
94+
if (!m_ptr)
95+
{
96+
Checks::unreachable(VCPKG_LINE_INFO);
97+
}
98+
}
99+
return m_ptr;
100+
}
101+
102+
CurlHeaders::CurlHeaders() : m_headers(nullptr) { }
103+
CurlHeaders::CurlHeaders(View<std::string> headers) : m_headers(nullptr)
104+
{
105+
for (const auto& header : headers)
106+
{
107+
m_headers = curl_slist_append(m_headers, header.c_str());
108+
}
109+
}
110+
CurlHeaders::CurlHeaders(CurlHeaders&& other) noexcept : m_headers(std::exchange(other.m_headers, nullptr)) { }
111+
CurlHeaders& CurlHeaders::operator=(CurlHeaders&& other) noexcept
112+
{
113+
m_headers = std::exchange(other.m_headers, nullptr);
114+
return *this;
115+
}
116+
CurlHeaders::~CurlHeaders()
117+
{
118+
if (m_headers)
119+
{
120+
curl_slist_free_all(m_headers);
121+
}
122+
}
123+
curl_slist* CurlHeaders::get() const { return m_headers; }
26124
}

0 commit comments

Comments
 (0)