Skip to content

Commit 99eb50f

Browse files
authored
Cherry-pick servicing changes for v1.11 (microsoft#5571)
This is a cherry-pick of microsoft#5570, microsoft#5568 and microsoft#5567 to the v1.11 branch. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5571)
1 parent 14e8917 commit 99eb50f

File tree

10 files changed

+183
-471
lines changed

10 files changed

+183
-471
lines changed

src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ProjectGuid>{5890d6ed-7c3b-40f3-b436-b54f640d9e65}</ProjectGuid>
1010
<Keyword>Win32Proj</Keyword>
1111
<RootNamespace>AppInstallerLoggingCore</RootNamespace>
12-
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
12+
<WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>
1313
<WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
1414
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
1515
</PropertyGroup>
@@ -500,4 +500,4 @@
500500
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
501501
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.230706.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
502502
</Target>
503-
</Project>
503+
</Project>

src/PowerShell/Microsoft.WinGet.Client.Engine/Helpers/AppxModuleHelper.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ private HashSet<Architecture> InitFrameworkArchitectures()
357357
{
358358
HashSet<Architecture> architectures = new HashSet<Architecture>();
359359

360+
// Read the override from the environment variable if it exists.
360361
string? environmentVariable = Environment.GetEnvironmentVariable(DependencyArchitectureEnvironmentVariable);
361362
if (environmentVariable != null)
362363
{
@@ -377,6 +378,7 @@ private HashSet<Architecture> InitFrameworkArchitectures()
377378
return architectures;
378379
}
379380

381+
// If there are any framework packages already installed, use the same architecture as them.
380382
var result = this.ExecuteAppxCmdlet(
381383
GetAppxPackage,
382384
new Dictionary<string, object>
@@ -406,6 +408,31 @@ private HashSet<Architecture> InitFrameworkArchitectures()
406408
}
407409
}
408410

411+
// Fall back to guessing from the current OS architecture.
412+
// This may have issues on ARM64 because RuntimeInformation.OSArchitecture seems to just lie sometimes.
413+
// See https://github.com/microsoft/winget-cli/issues/5020
414+
if (architectures.Count == 0)
415+
{
416+
var arch = RuntimeInformation.OSArchitecture;
417+
this.pwshCmdlet.Write(StreamType.Verbose, $"OS architecture: {arch.ToString()}");
418+
419+
if (arch == Architecture.X64)
420+
{
421+
architectures.Add(Architecture.X64);
422+
}
423+
else if (arch == Architecture.X86)
424+
{
425+
architectures.Add(Architecture.X86);
426+
}
427+
else if (arch == Architecture.Arm64)
428+
{
429+
// Let deployment figure it out
430+
architectures.Add(Architecture.Arm64);
431+
architectures.Add(Architecture.X64);
432+
architectures.Add(Architecture.X86);
433+
}
434+
}
435+
409436
return architectures;
410437
}
411438

src/VcpkgPortOverlay/CreatePortOverlay.ps1

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,111 @@ $OverlayRoot = $PSScriptRoot
44

55
$ErrorActionPreference = "Stop"
66

7-
# Hacky way of getting a single directory from the vcpkg repo:
8-
# - Download the vcpkg repo as a zip to a memory stream
9-
# - Parse the zip archive
10-
# - Extract the files we want
11-
function Get-VcpkgRepoAsZipArchive
7+
8+
# Gets the versions of a port available from the official registry.
9+
# This is read from the versions JSON in the main branch.
10+
# A version looks like this:
11+
# {
12+
# "git-tree": "9f5e160191038cbbd2470e534c43f051c80e7d44",
13+
# "version": "2.10.19",
14+
# "port-version": 3
15+
# }
16+
function Get-PortVersions
1217
{
13-
$vcpkgZipUri = "https://github.com/microsoft/vcpkg/archive/refs/heads/master.zip"
14-
$response = Invoke-WebRequest -Uri $vcpkgZipUri
18+
param(
19+
[Parameter(Mandatory)]
20+
[string]$Port
21+
)
22+
23+
$initial = $Port[0]
24+
$jsonUri = "https://raw.githubusercontent.com/microsoft/vcpkg/heads/master/versions/$initial-/$Port.json"
25+
$versions = (Invoke-WebRequest -Uri $jsonUri).Content | ConvertFrom-Json -Depth 5
26+
return $versions.versions
27+
}
28+
29+
# Gets the git-tree associated with a specific version of a port.
30+
# The git-tree is a git object hash that represents the port directory
31+
# from the appropriate version of the registry.
32+
function Get-PortVersionGitTree
33+
{
34+
param(
35+
[Parameter(Mandatory)]
36+
[string]$Port,
37+
[Parameter(Mandatory)]
38+
[string]$Version,
39+
[Parameter(Mandatory)]
40+
[string]$PortVersion
41+
)
42+
43+
$versions = Get-PortVersions $Port
44+
$versionData = $versions | Where-Object { ($_.version -eq $Version) -and ($_."port-version" -eq $portVersion) }
45+
return $versionData."git-tree"
46+
}
47+
48+
# Fetches and parses a git-tree as a ZIP file
49+
function Get-GitTreeAsArchive
50+
{
51+
param(
52+
[Parameter(Mandatory)]
53+
[string]$GitTree
54+
)
55+
56+
$archiveUri = "https://github.com/microsoft/vcpkg/archive/$gitTree.zip"
57+
$response = Invoke-WebRequest -Uri $archiveUri
1558
$zipStream = [System.IO.MemoryStream]::new($response.Content)
1659
$zipArchive = [System.IO.Compression.ZipArchive]::new($zipStream)
1760
return $zipArchive
1861
}
1962

20-
$VcpkgAsArchive = Get-VcpkgRepoAsZipArchive
21-
22-
# Copies an port from the official registry to this overlay
23-
function New-PortOverlay
63+
# Expands an in-memory archive and writes it to disk
64+
function Expand-ArchiveFromMemory
2465
{
2566
param(
2667
[Parameter(Mandatory)]
27-
[string]$Port
68+
[System.IO.Compression.ZipArchive]$Archive,
69+
[Parameter(Mandatory)]
70+
[string]$Destination
2871
)
2972

30-
$portDir = Join-Path $OverlayRoot $Port
31-
32-
# Delete existing port if needed
33-
if (Test-Path $portDir)
73+
# Delete existing directory
74+
if (Test-Path $Destination)
3475
{
35-
Remove-Item -Force -Recurse $portDir
76+
Remove-Item -Force -Recurse $Destination
3677
}
3778

3879
# Remove length=0 to ignore the directory itself
39-
$portZipEntries = $VcpkgAsArchive.Entries |
40-
Where-Object { ($_.Length -ne 0) -and $_.FullName.StartsWith("vcpkg-master/ports/$Port/") }
41-
42-
if (-not $portZipEntries)
80+
$entries = $archive.Entries | Where-Object { $_.Length -ne 0 }
81+
if (-not $entries)
4382
{
44-
throw "Port $port not found"
83+
throw "Archive is empty"
4584
}
4685

47-
New-Item -Type Directory $portDir | Out-Null
48-
foreach ($zipEntry in $portZipEntries)
86+
New-Item -Type Directory $Destination | Out-Null
87+
foreach ($entry in $entries)
4988
{
50-
$targetPath = Join-Path $portDir $zipEntry.Name
51-
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry, $targetPath)
89+
$targetPath = Join-Path $Destination $entry.Name
90+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $targetPath)
5291
}
5392
}
5493

94+
# Creates a copy of a port version from the official registry in this overlay
95+
function New-PortOverlay
96+
{
97+
param(
98+
[Parameter(Mandatory)]
99+
[string]$Port,
100+
[Parameter(Mandatory)]
101+
[string]$Version,
102+
[Parameter(Mandatory)]
103+
[string]$PortVersion
104+
)
105+
106+
$gitTree = Get-PortVersionGitTree $Port $Version $PortVersion
107+
$archive = Get-GitTreeAsArchive $gitTree
108+
$portDir = Join-Path $OverlayRoot $Port
109+
Expand-ArchiveFromMemory $archive $portDir
110+
}
111+
55112
# Gets a git patch from a GitHub commit
56113
function Get-GitHubPatch
57114
{
@@ -223,13 +280,28 @@ function Update-PortSource
223280

224281
$portDir = Join-Path $OverlayRoot $Port
225282

226-
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}' -NewValue $Commit
283+
# For the REF, we also delete any comments after it that may say the wrong version
284+
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}( #.*)?$' -NewValue "$Commit # Unreleased"
227285
Set-ParameterInPortFile $Port -ParameterName 'SHA512' -CurrentValuePattern '[0-9a-f]{128}' -NewValue $SourceHash
228286
}
229287

288+
# Updates the port version by one.
289+
function Update-PortVersion
290+
{
291+
param(
292+
[Parameter(Mandatory)]
293+
[string]$Port
294+
)
295+
296+
$portJsonPath = Join-Path $OverlayRoot $Port "vcpkg.json"
297+
$portDefinition = Get-Content $portJsonPath | ConvertFrom-Json
298+
$portDefinition."port-version" += 1
299+
$portDefinition | ConvertTo-Json -Depth 5 | Out-File $portJsonPath
300+
}
230301

231-
New-PortOverlay cpprestsdk
302+
New-PortOverlay cpprestsdk -Version 2.10.18 -PortVersion 4
232303
Add-PatchToPort cpprestsdk -PatchRepo 'microsoft/winget-cli' -PatchCommit '888b4ed8f4f7d25cb05a47210e083fe29348163b' -PatchName 'add-server-certificate-validation.patch' -PatchRoot 'src/cpprestsdk/cpprestsdk'
233304

234-
New-PortOverlay libyaml
235-
Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302'
305+
New-PortOverlay libyaml -Version 0.2.5 -PortVersion 5
306+
Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302'
307+
Update-PortVersion libyaml

src/VcpkgPortOverlay/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The whole directory can be re-created with `.\CreatePortOverlay.ps1`
88
## cpprestsdk
99

1010
We add support for certificate pinning.
11+
Note that we use v2.10.18, which is not the latest.
1112

1213
Changes:
1314
* Add patch file: `add-server-certificate-validation.patch`
@@ -18,4 +19,5 @@ Changes:
1819
We use an unreleased version that fixes a vulnerability.
1920

2021
Changes:
21-
* New source commit: https://github.com/yaml/libyaml/commit/840b65c40675e2d06bf40405ad3f12dec7f35923
22+
* New source commit: https://github.com/yaml/libyaml/commit/840b65c40675e2d06bf40405ad3f12dec7f35923
23+
* Increase the port version so that Component Governance doesn't see it as the vulnerable version anymore

0 commit comments

Comments
 (0)