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

Add manifest-info.json to record manifest path in vcpkg_installed #1568

Merged
merged 11 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
36 changes: 36 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/manifests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $commonArgs += @("--x-builtin-ports-root=$PSScriptRoot/../e2e-ports")
$manifestDirArgs = $commonArgs + @("--x-manifest-root=$manifestDir")
$noDefaultFeatureArgs = $manifestDirArgs + @('--x-no-default-features')

$vcpkgDir = Join-Path -Path $installRoot -ChildPath "vcpkg"
$manifestInfoPath = Join-Path -Path $vcpkgDir -ChildPath "manifest-info.json"
function feature {
@{
'description' = '';
Expand Down Expand Up @@ -53,13 +55,18 @@ Throw-IfNotFailed
Write-Trace "test manifest features: no-default-features, features = []"
Run-Vcpkg install @manifestDirArgs --x-no-default-features
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: default-features, features = [core]"
Run-Vcpkg install @manifestDirArgs --x-feature=core
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

# test having both
Write-Trace "test manifest features: no-default-features, features = [core]"
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=core
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [default-fail]"
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=default-fail
Expand All @@ -71,26 +78,38 @@ Throw-IfNotFailed
Write-Trace "test manifest features: no-default-features, features = [copied-feature]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [copied-feature, copied-feature]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature --x-feature=copied-feature
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [multiple-dep-1, multiple-dep-2]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=multiple-dep-1 --x-feature=multiple-dep-2
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [no-default-features-1]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [no-default-features-2]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-2
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [no-default-features-1,no-default-features-3]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1 --x-feature=no-default-features-3
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: no-default-features, features = [no-default-features-3]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-3
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir


$vcpkgJson = @{
'default-features' = @( 'default-fail' );
Expand Down Expand Up @@ -122,38 +141,51 @@ Throw-IfNotFailed
Write-Trace "test nameless manifest features: no-default-features, features = []"
Run-Vcpkg install @manifestDirArgs --x-no-default-features
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: default-features, features = [core]"
Run-Vcpkg install @manifestDirArgs --x-feature=core
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

# test having both
Write-Trace "test nameless manifest features: no-default-features, features = [core]"
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=core
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: no-default-features, features = [default-fail]"
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=default-fail
Throw-IfNotFailed

Write-Trace "test nameless manifest features: default-features, features = [core, default-fail]"
Run-Vcpkg install @manifestDirArgs --x-feature=core --x-feature=default-fail
Throw-IfNotFailed

Write-Trace "test nameless manifest features: no-default-features, features = [copied-feature]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: no-default-features, features = [copied-feature, copied-feature]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature --x-feature=copied-feature
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: no-default-features, features = [multiple-dep-1, multiple-dep-2]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=multiple-dep-1 --x-feature=multiple-dep-2
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: no-default-features, features = [no-default-features-1]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test nameless manifest features: no-default-features, features = [no-default-features-2]"
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-2
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

$vcpkgJson = @{
'name' = "manifest-test";
Expand Down Expand Up @@ -181,10 +213,12 @@ Set-Content -Path "$manifestDir/manifest-test/vcpkg.json" `
Write-Trace "test manifest features: self-reference, features = [a]"
Run-Vcpkg install @manifestDirArgs --x-feature=a
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest features: self-reference, features = [a], with overlay"
Run-Vcpkg install @manifestDirArgs --x-feature=a "--overlay-ports=$manifestDir/manifest-test"
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

Write-Trace "test manifest install with specific package names fails"
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs vcpkg-empty-port
Expand All @@ -194,6 +228,8 @@ Throw-IfNonContains -Expected 'error: In manifest mode, `vcpkg install` does not
Write-Trace "test manifest install with specific package names forced to classic mode succeeds"
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs --classic vcpkg-empty-port
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir

$expected = @"
The following packages will be built and installed:
vcpkg-empty-port:
Expand Down
5 changes: 5 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/overlays.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

$vcpkgDir = Join-Path -Path $installRoot -ChildPath "vcpkg"
$manifestInfoPath = Join-Path -Path $vcpkgDir -ChildPath "manifest-info.json"

# 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",
Expand All @@ -16,6 +19,7 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
--x-install-root=$installRoot `
--triplet fancy-triplet
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestRoot

# Tests overlays configured in env and cli on a project with configuration embedded on the manifest file
$manifestRoot = "$TestingRoot/overlays-project-config-embedded"
Expand All @@ -26,6 +30,7 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
--x-install-root=$installRoot `
--triplet fancy-config-embedded-triplet
Throw-IfFailed
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestRoot

# Config with bad paths
$manifestRoot = "$TestingRoot/overlays-bad-paths"
Expand Down
18 changes: 18 additions & 0 deletions azure-pipelines/end-to-end-tests-prelude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,22 @@ function Throw-IfNonContains {
}
}

function Test-ManifestInfo {
param (
[string]$ManifestInfoPath,
[string]$VcpkgDir,
[string]$ManifestRoot
)

if (-not (Test-Path $ManifestInfoPath)) {
Throw "manifest-info.json missing from $VcpkgDir"
}

$manifestInfoContent = Get-Content $ManifestInfoPath -Raw | ConvertFrom-Json

if ($manifestInfoContent.'manifest-path' -ne (Join-Path -Path $ManifestRoot -ChildPath "vcpkg.json")) {
Throw "Mismatch in manifest-path. Expected: $ManifestRoot, Found: $($manifestInfoContent.'manifest-path')"
}
}

Refresh-TestRoot
1 change: 1 addition & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ namespace vcpkg
inline constexpr StringLiteral FileVcpkgConfigurationDotJson = "vcpkg-configuration.json";
inline constexpr StringLiteral FileVcpkgDotJson = "vcpkg.json";
inline constexpr StringLiteral FileVcpkgLock = "vcpkg-lock.json";
inline constexpr StringLiteral FileManifestInfo = "manifest-info.json";
inline constexpr StringLiteral FileVcpkgPathTxt = "vcpkg.path.txt";
inline constexpr StringLiteral FileVcpkgPortConfig = "vcpkg-port-config.cmake";
inline constexpr StringLiteral FileVcpkgSpdxJson = "vcpkg.spdx.json";
Expand Down
13 changes: 13 additions & 0 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vcpkg/commands.install.h>
#include <vcpkg/commands.set-installed.h>
#include <vcpkg/input.h>
#include <vcpkg/installedpaths.h>
#include <vcpkg/metrics.h>
#include <vcpkg/portfileprovider.h>
#include <vcpkg/registries.h>
Expand Down Expand Up @@ -277,6 +278,18 @@ namespace vcpkg
}
}

if (auto manifest = paths.get_manifest().get())
{
Json::Object manifest_info;
manifest_info.insert("manifest-path", Json::Value::string(manifest->path));
if (const auto installed_paths = paths.maybe_installed().get())
{
const auto json_file_path = installed_paths->vcpkg_dir() / FileManifestInfo;
const auto json_contents = Json::stringify(manifest_info, Json::JsonStyle::with_spaces(2));
JavierMatosD marked this conversation as resolved.
Show resolved Hide resolved
fs.write_contents(json_file_path, json_contents, VCPKG_LINE_INFO);
}
}

Checks::exit_success(VCPKG_LINE_INFO);
}

Expand Down