Skip to content

Commit 89ab1aa

Browse files
authored
Add manifest-info.json to record manifest path in vcpkg_installed (#1568)
1 parent c7fd737 commit 89ab1aa

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

azure-pipelines/end-to-end-tests-dir/manifests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ $commonArgs += @("--x-builtin-ports-root=$PSScriptRoot/../e2e-ports")
77
$manifestDirArgs = $commonArgs + @("--x-manifest-root=$manifestDir")
88
$noDefaultFeatureArgs = $manifestDirArgs + @('--x-no-default-features')
99

10+
$vcpkgDir = Join-Path -Path $installRoot -ChildPath "vcpkg"
11+
$manifestInfoPath = Join-Path -Path $vcpkgDir -ChildPath "manifest-info.json"
1012
function feature {
1113
@{
1214
'description' = '';
@@ -53,13 +55,18 @@ Throw-IfNotFailed
5355
Write-Trace "test manifest features: no-default-features, features = []"
5456
Run-Vcpkg install @manifestDirArgs --x-no-default-features
5557
Throw-IfFailed
58+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
59+
5660
Write-Trace "test manifest features: default-features, features = [core]"
5761
Run-Vcpkg install @manifestDirArgs --x-feature=core
5862
Throw-IfFailed
63+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
64+
5965
# test having both
6066
Write-Trace "test manifest features: no-default-features, features = [core]"
6167
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=core
6268
Throw-IfFailed
69+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
6370

6471
Write-Trace "test manifest features: no-default-features, features = [default-fail]"
6572
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=default-fail
@@ -71,26 +78,38 @@ Throw-IfNotFailed
7178
Write-Trace "test manifest features: no-default-features, features = [copied-feature]"
7279
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature
7380
Throw-IfFailed
81+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
82+
7483
Write-Trace "test manifest features: no-default-features, features = [copied-feature, copied-feature]"
7584
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature --x-feature=copied-feature
7685
Throw-IfFailed
86+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
7787

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

8293
Write-Trace "test manifest features: no-default-features, features = [no-default-features-1]"
8394
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1
8495
Throw-IfFailed
96+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
97+
8598
Write-Trace "test manifest features: no-default-features, features = [no-default-features-2]"
8699
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-2
87100
Throw-IfFailed
101+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
102+
88103
Write-Trace "test manifest features: no-default-features, features = [no-default-features-1,no-default-features-3]"
89104
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1 --x-feature=no-default-features-3
90105
Throw-IfFailed
106+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
107+
91108
Write-Trace "test manifest features: no-default-features, features = [no-default-features-3]"
92109
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-3
93110
Throw-IfFailed
111+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
112+
94113

95114
$vcpkgJson = @{
96115
'default-features' = @( 'default-fail' );
@@ -122,38 +141,51 @@ Throw-IfNotFailed
122141
Write-Trace "test nameless manifest features: no-default-features, features = []"
123142
Run-Vcpkg install @manifestDirArgs --x-no-default-features
124143
Throw-IfFailed
144+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
145+
125146
Write-Trace "test nameless manifest features: default-features, features = [core]"
126147
Run-Vcpkg install @manifestDirArgs --x-feature=core
127148
Throw-IfFailed
149+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
150+
128151
# test having both
129152
Write-Trace "test nameless manifest features: no-default-features, features = [core]"
130153
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=core
131154
Throw-IfFailed
155+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
132156

133157
Write-Trace "test nameless manifest features: no-default-features, features = [default-fail]"
134158
Run-Vcpkg install @manifestDirArgs --x-no-default-features --x-feature=default-fail
135159
Throw-IfNotFailed
160+
136161
Write-Trace "test nameless manifest features: default-features, features = [core, default-fail]"
137162
Run-Vcpkg install @manifestDirArgs --x-feature=core --x-feature=default-fail
138163
Throw-IfNotFailed
139164

140165
Write-Trace "test nameless manifest features: no-default-features, features = [copied-feature]"
141166
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature
142167
Throw-IfFailed
168+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
169+
143170
Write-Trace "test nameless manifest features: no-default-features, features = [copied-feature, copied-feature]"
144171
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=copied-feature --x-feature=copied-feature
145172
Throw-IfFailed
173+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
146174

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

151180
Write-Trace "test nameless manifest features: no-default-features, features = [no-default-features-1]"
152181
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-1
153182
Throw-IfFailed
183+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
184+
154185
Write-Trace "test nameless manifest features: no-default-features, features = [no-default-features-2]"
155186
Run-Vcpkg install @noDefaultFeatureArgs --x-feature=no-default-features-2
156187
Throw-IfFailed
188+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
157189

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

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

189223
Write-Trace "test manifest install with specific package names fails"
190224
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs vcpkg-empty-port
@@ -194,6 +228,8 @@ Throw-IfNonContains -Expected 'error: In manifest mode, `vcpkg install` does not
194228
Write-Trace "test manifest install with specific package names forced to classic mode succeeds"
195229
$output = Run-VcpkgAndCaptureOutput install @manifestDirArgs --classic vcpkg-empty-port
196230
Throw-IfFailed
231+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestDir
232+
197233
$expected = @"
198234
The following packages will be built and installed:
199235
vcpkg-empty-port:

azure-pipelines/end-to-end-tests-dir/overlays.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
. $PSScriptRoot/../end-to-end-tests-prelude.ps1
22

3+
$vcpkgDir = Join-Path -Path $installRoot -ChildPath "vcpkg"
4+
$manifestInfoPath = Join-Path -Path $vcpkgDir -ChildPath "manifest-info.json"
5+
36
# Tests a simple project with overlay ports and triplets configured on a vcpkg-configuration.json file
47
Copy-Item -Recurse -LiteralPath @(
58
"$PSScriptRoot/../e2e-projects/overlays-malformed-shadowing",
@@ -16,6 +19,7 @@ Run-Vcpkg install --x-manifest-root=$manifestRoot `
1619
--x-install-root=$installRoot `
1720
--triplet fancy-triplet
1821
Throw-IfFailed
22+
Test-ManifestInfo -ManifestInfoPath $ManifestInfoPath -VcpkgDir $vcpkgDir -ManifestRoot $manifestRoot
1923

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

3035
# ... and with command line overlay-ports being 'dot'
3136
pushd "$manifestRoot/cli-overlays"

azure-pipelines/end-to-end-tests-prelude.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,22 @@ function Throw-IfNonContains {
265265
}
266266
}
267267

268+
function Test-ManifestInfo {
269+
param (
270+
[string]$ManifestInfoPath,
271+
[string]$VcpkgDir,
272+
[string]$ManifestRoot
273+
)
274+
275+
if (-not (Test-Path $ManifestInfoPath)) {
276+
Throw "manifest-info.json missing from $VcpkgDir"
277+
}
278+
279+
$manifestInfoContent = Get-Content $ManifestInfoPath -Raw | ConvertFrom-Json
280+
281+
if ($manifestInfoContent.'manifest-path' -ne (Join-Path -Path $ManifestRoot -ChildPath "vcpkg.json")) {
282+
Throw "Mismatch in manifest-path. Expected: $ManifestRoot, Found: $($manifestInfoContent.'manifest-path')"
283+
}
284+
}
285+
268286
Refresh-TestRoot

docs/manifest-info.schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-manifest-info.schema.json",
4+
"type": "object",
5+
"properties": {
6+
"manifest-path": {
7+
"description": "Identifies the path of the vcpkg manifest file that produced this installed tree.",
8+
"type": "string"
9+
}
10+
},
11+
"additionalProperties": true,
12+
"required": [
13+
"manifest-path"
14+
]
15+
}

include/vcpkg/base/contractual-constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ namespace vcpkg
364364
inline constexpr StringLiteral FileVcpkgConfigurationDotJson = "vcpkg-configuration.json";
365365
inline constexpr StringLiteral FileVcpkgDotJson = "vcpkg.json";
366366
inline constexpr StringLiteral FileVcpkgLock = "vcpkg-lock.json";
367+
inline constexpr StringLiteral FileManifestInfo = "manifest-info.json";
367368
inline constexpr StringLiteral FileVcpkgPathTxt = "vcpkg.path.txt";
368369
inline constexpr StringLiteral FileVcpkgPortConfig = "vcpkg-port-config.cmake";
369370
inline constexpr StringLiteral FileVcpkgSpdxJson = "vcpkg.spdx.json";

src/vcpkg/commands.set-installed.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vcpkg/commands.install.h>
99
#include <vcpkg/commands.set-installed.h>
1010
#include <vcpkg/input.h>
11+
#include <vcpkg/installedpaths.h>
1112
#include <vcpkg/metrics.h>
1213
#include <vcpkg/portfileprovider.h>
1314
#include <vcpkg/registries.h>
@@ -278,6 +279,18 @@ namespace vcpkg
278279
}
279280
}
280281

282+
const auto manifest = paths.get_manifest().get();
283+
const auto installed_paths = paths.maybe_installed().get();
284+
if (manifest && installed_paths)
285+
{
286+
// See docs/manifest-info.schema.json
287+
Json::Object manifest_info;
288+
manifest_info.insert("manifest-path", Json::Value::string(manifest->path));
289+
const auto json_file_path = installed_paths->vcpkg_dir() / FileManifestInfo;
290+
const auto json_contents = Json::stringify(manifest_info);
291+
fs.write_contents(json_file_path, json_contents, VCPKG_LINE_INFO);
292+
}
293+
281294
Checks::exit_success(VCPKG_LINE_INFO);
282295
}
283296

0 commit comments

Comments
 (0)