Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/cache-compile…
Browse files Browse the repository at this point in the history
…r-hash-2
  • Loading branch information
BillyONeal committed Jan 16, 2025
2 parents 00fd53b + 52e8ac9 commit cf39054
Show file tree
Hide file tree
Showing 82 changed files with 4,785 additions and 2,351 deletions.
3 changes: 3 additions & 0 deletions azure-pipelines/e2e-assets/asset-caching/bad-hash-script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Param([string]$File)
Write-Host "Creating file with the wrong hash"
Set-Content -Path $File -Value "This is a file with the wrong hash" -Encoding Ascii -NoNewline
3 changes: 2 additions & 1 deletion azure-pipelines/e2e-assets/asset-caching/failing-script.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
throw "Script download error"
Write-Host "Script download error"
exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Host "Not creating a file"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"overlay-ports": [ "." ]
}
5 changes: 5 additions & 0 deletions azure-pipelines/e2e-projects/overlays-dot/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"a"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "a",
"version": "0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This port is intentionally malformed and should not be loaded, because ../../a should be loaded instead
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "a",
"version": "0",
"intentionally-malformed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$comment": "'config-overlays/a' in . should get loaded first, so we should never consider 'config-overlays/malformed/a'",
"overlay-ports": [ "config-overlays", "config-overlays/malformed" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"a"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file exists only to ensure that git creates the directory containing it, so that ./hello/.. is a valid path.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"overlay-ports": [ "./hello/.." ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"a"
]
}
435 changes: 337 additions & 98 deletions azure-pipelines/end-to-end-tests-dir/asset-caching.ps1

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions azure-pipelines/end-to-end-tests-dir/commands.extract.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if (-Not (Test-Path $extractedFilePath)) {

if (-Not $IsWindows) {
$unixMode = (Get-Item $extractedFilePath).UnixMode
if ($unixMode -ne "-rwxr-xr-x") {
throw "File does not have +x permission. UnixMode: $unixMode"
if (-not ($unixMode -match 'x.*x.*x')) {
throw "File does not have +x permission. $extractedFilePath UnixMode: $unixMode"
}
}

Expand Down
10 changes: 5 additions & 5 deletions azure-pipelines/end-to-end-tests-dir/fetch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$VcpkgToolsJsonSchemaFile = (Get-Item "$PSScriptRoot/../../docs/vcpkg-tools.schema.json").FullName
if (-not (Test-Json -ea:0 -LiteralPath "$VcpkgRoot/scripts/vcpkg-tools.json" -SchemaFile $VcpkgToolsJsonSchemaFile)) {
throw "real vcpkg-tools.json doesn't conform to schema"
throw "real vcpkg-tools.json doesn't conform to schema"
}

if (-not $IsMacOS -and -not $IsLinux) {
Expand All @@ -20,7 +20,7 @@ if (-not $IsMacOS -and -not $IsLinux) {
{
"schema-version": 1,
"tools": [{
"name": "7zip",
"name": "7zip_msi",
"os": "windows",
"version": "19.00",
"executable": "Files\\7-Zip\\7z.exe",
Expand Down Expand Up @@ -86,13 +86,13 @@ if (-not $IsMacOS -and -not $IsLinux) {
'@ | % { $_ -replace "`r","" } | Out-File -enc ascii $VcpkgToolsJson

if (-not (Test-Json -ea:0 -LiteralPath $VcpkgToolsJson -SchemaFile $VcpkgToolsJsonSchemaFile)) {
throw "testing vcpkg-tools.json doesn't conform to schema"
throw "testing vcpkg-tools.json doesn't conform to schema"
}

$env:VCPKG_DOWNLOADS = Join-Path $TestingRoot 'down loads'
Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip", "--vcpkg-root=$TestingRoot"))
Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "7zip_msi", "--vcpkg-root=$TestingRoot"))
Throw-IfFailed
Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip-19.00-windows/Files/7-Zip/7z.exe"
Require-FileExists "$env:VCPKG_DOWNLOADS/tools/7zip_msi-19.00-windows/Files/7-Zip/7z.exe"

Run-Vcpkg -TestArgs ($commonArgs + @("fetch", "ninja-testing", "--vcpkg-root=$TestingRoot"))
Throw-IfFailed
Expand Down
45 changes: 40 additions & 5 deletions azure-pipelines/end-to-end-tests-dir/overlays.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Tests a simple project with overlay ports and triplets configured on a vcpkg-configuration.json file
Copy-Item -Recurse -LiteralPath @(
"$PSScriptRoot/../e2e-projects/overlays-project-with-config",
"$PSScriptRoot/../e2e-projects/overlays-malformed-shadowing",
"$PSScriptRoot/../e2e-projects/overlays-project-config-embedded",
"$PSScriptRoot/../e2e-projects/overlays-bad-paths"
"$PSScriptRoot/../e2e-projects/overlays-project-with-config"
) $TestingRoot

$manifestRoot = "$TestingRoot/overlays-project-with-config"
Expand All @@ -27,13 +27,32 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
--triplet fancy-config-embedded-triplet
Throw-IfFailed

# ... and with command line overlay-ports being 'dot'
pushd "$manifestRoot/cli-overlays"
try {
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-ports=. `
--overlay-triplets=$manifestRoot/my-triplets `
--x-install-root=$installRoot `
--triplet fancy-config-embedded-triplet
Throw-IfFailed
} finally {
popd
}

# Config with bad paths
$manifestRoot = "$TestingRoot/overlays-bad-paths"
$manifestRoot = "$PSScriptRoot/../e2e-projects/overlays-bad-paths"
$env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env_overlays"
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-triplets=$manifestRoot/my-triplets `
--x-install-root=$installRoot
Throw-IfNotFailed
Remove-Item env:VCPKG_OVERLAY_PORTS

# Test that once an overlay port is loaded for a name, subsequent ports are not considered
$manifestRoot = "$TestingRoot/overlays-malformed-shadowing"
Run-Vcpkg install --x-manifest-root=$manifestRoot
Throw-IfFailed

# Test overlay_triplet paths remain relative to the manifest root after x-update-baseline
$manifestRoot = "$TestingRoot/overlays-project-with-config"
Expand All @@ -47,11 +66,27 @@ $overlaysAfter = $configurationAfter."overlay-triplets"
$notEqual = @(Compare-Object $overlaysBefore $overlaysAfter -SyncWindow 0).Length -ne 0

if ($notEqual) {
Throw "Overlay triplets paths changed after x-update-baseline"
Throw "Overlay triplets paths changed after x-update-baseline"
}

# Test that trying to declare overlay-ports as '.' fails
$manifestRoot = "$PSScriptRoot/../e2e-projects/overlays-dot"
$output = Run-VcpkgAndCaptureStdErr install --x-manifest-root=$manifestRoot --x-install-root=$installRoot
Throw-IfNotFailed
Throw-IfNonContains -Actual $output -Expected @"
error: The manifest directory cannot be the same as a directory configured in overlay-ports, so "overlay-ports" values cannot be ".".
"@

# Test that trying to declare overlay-ports as the same directory in a roundabout way fails
$manifestRoot = "$PSScriptRoot/../e2e-projects/overlays-not-quite-dot"
$canonicalManifestRoot = (Get-Item $manifestRoot).FullName
$output = Run-VcpkgAndCaptureStdErr install --x-manifest-root=$manifestRoot --x-install-root=$installRoot
Throw-IfNotFailed
Throw-IfNonContains -Actual $output -Expected @"
The manifest directory ($canonicalManifestRoot) cannot be the same as a directory configured in overlay-ports.
"@

# Test that removals can happen without the overlay triplets
Remove-Item env:VCPKG_OVERLAY_PORTS
Refresh-TestRoot
Run-Vcpkg install another-vcpkg-empty-port:fancy-triplet `
--overlay-ports=$PSScriptRoot/../e2e-projects/overlays-project-with-config/cli-overlays `
Expand Down
2 changes: 2 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ the line when someone complains!

## Running end to end (e2e) tests

Before running the tests you must have installed the `Pester` module.
This can be done by running `Install-Module -Name Pester -MinimumVersion 5.6.1 -MaximumVersion 5.99 -Force` in a PowerShell session.
To run the e2e test run the following command:
`pwsh azure-pipelines/end-to-end-tests.ps1`
**Parameters**:
Expand Down
18 changes: 10 additions & 8 deletions include/vcpkg/base/api-stable-format.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vcpkg/base/expected.h>
#include <vcpkg/base/diagnostics.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>

#include <string>
Expand All @@ -10,21 +11,22 @@ namespace vcpkg
namespace details
{
template<class F>
void api_stable_format_cb(void* f, std::string& s, StringView sv)
bool api_stable_format_cb(void* f, std::string& s, StringView sv)
{
(*(F*)(f))(s, sv);
return (*(F*)(f))(s, sv);
}

ExpectedL<std::string> api_stable_format_impl(StringView fmtstr,
void (*cb)(void*, std::string&, StringView),
void* data);
Optional<std::string> api_stable_format_impl(DiagnosticContext& context,
StringView fmtstr,
bool (*cb)(void*, std::string&, StringView),
void* data);
}

// This function exists in order to provide an API-stable formatting function similar to `std::format()` that does
// not depend on the feature set of fmt or the C++ standard library and thus can be contractual for user interfaces.
template<class F>
ExpectedL<std::string> api_stable_format(StringView fmtstr, F&& handler)
Optional<std::string> api_stable_format(DiagnosticContext& context, StringView fmtstr, F&& handler)
{
return details::api_stable_format_impl(fmtstr, &details::api_stable_format_cb<F>, &handler);
return details::api_stable_format_impl(context, fmtstr, &details::api_stable_format_cb<F>, &handler);
}
}
Loading

0 comments on commit cf39054

Please sign in to comment.