@@ -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
56113function 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
232303Add-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
0 commit comments