Skip to content

Commit

Permalink
Add manifest-info.json to record manifest path in vcpkg_installed (#1568
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JavierMatosD authored Jan 17, 2025
1 parent c7fd737 commit 89ab1aa
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
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-malformed-shadowing",
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

# ... and with command line overlay-ports being 'dot'
pushd "$manifestRoot/cli-overlays"
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
15 changes: 15 additions & 0 deletions docs/manifest-info.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-manifest-info.schema.json",
"type": "object",
"properties": {
"manifest-path": {
"description": "Identifies the path of the vcpkg manifest file that produced this installed tree.",
"type": "string"
}
},
"additionalProperties": true,
"required": [
"manifest-path"
]
}
1 change: 1 addition & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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 @@ -278,6 +279,18 @@ namespace vcpkg
}
}

const auto manifest = paths.get_manifest().get();
const auto installed_paths = paths.maybe_installed().get();
if (manifest && installed_paths)
{
// See docs/manifest-info.schema.json
Json::Object manifest_info;
manifest_info.insert("manifest-path", Json::Value::string(manifest->path));
const auto json_file_path = installed_paths->vcpkg_dir() / FileManifestInfo;
const auto json_contents = Json::stringify(manifest_info);
fs.write_contents(json_file_path, json_contents, VCPKG_LINE_INFO);
}

Checks::exit_success(VCPKG_LINE_INFO);
}

Expand Down

0 comments on commit 89ab1aa

Please sign in to comment.