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

Editing asset cache output when using x-script #1541

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw "Script download error"
28 changes: 28 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/asset-caching.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,31 @@ $actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$d
if (-not ($actual.Contains("Asset cache hit for example3.html; downloaded from: file://$AssetCache"))) {
throw "Failure: azurl (yes), x-block-origin (yes), asset-cache (hit), download (n/a)"
}

# Testing x-download failure with asset cache (x-script) and x-block-origin settings
$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,pwsh $PSScriptRoot/../e2e-assets/asset-caching/failing-script.ps1 {url} {sha512} {dst};x-block-origin"
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a"))
# Check for the expected messages in order
$expectedOrder = @(
"error: <mirror-script> failed with exit code: (1).",
"error: Missing example3.html and downloads are blocked by x-block-origin."
)

# Verify order
$index = 0
foreach ($message in $expectedOrder) {
$index = $actual.IndexOf($message, $index)
if ($index -lt 0) {
throw "Failure: Expected message '$message' not found in the correct order."
}
$index += $message.Length
}

# Testing x-download success with asset cache (x-script) and x-block-origin settings
Refresh-TestRoot
$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,$TestScriptAssetCacheExe {url} {sha512} {dst};x-block-origin"
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com/hello-world.txt", "--sha512", "09e1e2a84c92b56c8280f4a1203c7cffd61b162cfe987278d4d6be9afbf38c0e8934cdadf83751f4e99d111352bffefc958e5a4852c8a7a29c95742ce59288a8"))
if (-not ($actual.Contains("Successfully downloaded example3.html."))) {
throw "Failure: x-script download success message"
}

7 changes: 4 additions & 3 deletions src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ namespace vcpkg
RedirectedProcessLaunchSettings settings;
settings.environment = get_clean_environment();
settings.echo_in_debug = EchoInDebug::Show;

auto maybe_res = flatten(cmd_execute_and_capture_output(cmd, settings), "<mirror-script>");
if (maybe_res)
{
Expand All @@ -982,14 +983,14 @@ namespace vcpkg
if (maybe_success)
{
fs.rename(download_path_part_path, download_path, VCPKG_LINE_INFO);
msg::println(msgDownloadSuccesful, msg::path = download_path.filename());
return urls[0];
}

errors.push_back(std::move(maybe_success).error());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is being fairly careful to put the errors in errors rather than emitting them here directly; can you explain why this case is different than the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this error occurs when there is a sha mismatch. I'm printing rather than putting in errors so that the order of the failure messages makes sense and is consistent with the download failure messages below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I would really like to see at least a comment here explaining what the criteria for 'errors' vs being printed directly is, since changing which is which on and ad-hoc basis like this seems likely to create as many bugs as solved every time it is touched.

However, this function is already awful about that so not going to block over this.

msg::println_error(maybe_success.error());
}
else
{
errors.push_back(std::move(maybe_res).error());
msg::println_error(maybe_res.error());
}
}
}
Expand Down
Loading