Skip to content

Commit

Permalink
Editing asset cache output when using x-script (#1541)
Browse files Browse the repository at this point in the history
* improve messaging for x-script

* add newlines @ EOF

* format

* respond to Billy feedback

* test order of messaging

---------

Co-authored-by: Javier Matos <[email protected]>
  • Loading branch information
JavierMatosD and Javier Matos authored Nov 19, 2024
1 parent d176cbe commit 99de266
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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());
msg::println_error(maybe_success.error());
}
else
{
errors.push_back(std::move(maybe_res).error());
msg::println_error(maybe_res.error());
}
}
}
Expand Down

0 comments on commit 99de266

Please sign in to comment.