@@ -99,6 +99,21 @@ function Select-DirectoryInPatch
9999 return $result
100100}
101101
102+ <#
103+ When updating a portfile, we look for a section that looks like this:
104+
105+ vcpkg_from_github(
106+ OUT_SOURCE_PATH SOURCE_PATH
107+ REPO <user/repo>
108+ REF <commith hash>
109+ SHA512 <code .tar.gz hash>
110+ HEAD_REF master
111+ PATCHES
112+ patch-1.patch
113+ patch-2.patch
114+ )
115+ #>
116+
102117# Adds a patch to a portfile.cmake
103118function Add-PatchToPortFile
104119{
@@ -109,22 +124,7 @@ function Add-PatchToPortFile
109124 [string ]$PatchName
110125 )
111126
112- <#
113- We're looking for a section that looks like this:
114-
115- vcpkg_from_github(
116- OUT_SOURCE_PATH SOURCE_PATH
117- REPO <user/repo>
118- REF <commith hash>
119- SHA512 <hash>
120- HEAD_REF master
121- PATCHES
122- patch-1.patch
123- patch-2.patch
124- )
125-
126- We look for the line that says "PATCHES" and add the new patch before the closing parenthesis
127- #>
127+ # Look for the line that says "PATCHES" and add the new patch before the closing parenthesis
128128
129129 $portFilePath = Join-Path $OverlayRoot $Port " portfile.cmake"
130130 $originalPortFile = Get-Content $portFilePath
@@ -179,8 +179,57 @@ function Add-PatchToPort
179179 Add-PatchToPortFile - Port $Port - PatchName $PatchName
180180}
181181
182+ # Sets the value of an existing function parameter.
183+ # For example, REF in vcpkg_from_github
184+ function Set-ParameterInPortFile
185+ {
186+ param (
187+ [Parameter (Mandatory )]
188+ [string ]$Port ,
189+ [Parameter (Mandatory )]
190+ [string ]$ParameterName ,
191+ [Parameter (Mandatory )]
192+ [string ]$CurrentValuePattern ,
193+ [Parameter (Mandatory )]
194+ [string ]$NewValue
195+ )
196+
197+ $portFilePath = Join-Path $OverlayRoot $Port ' portfile.cmake'
198+ $originalPortFile = Get-Content $portFilePath
199+
200+ # Explanation for the regex:
201+ # '(?<=)' - lookbehind without matching
202+ # '^ +' - the parameter is only preceeded by spaces (and followed by a single space)
203+ # '(?=)' - lookahead without matching
204+ # ' |$' - the parameter may be the end of the line, or be followed by something else after a space (e.g. a comment)
205+ $regex = " (?<=^ +$ParameterName )$CurrentValuePattern (?= |$)"
206+
207+ $modifiedPortFile = $originalPortFile -replace $regex , $NewValue
208+ $modifiedPortFile | Out-File $portFilePath
209+ }
210+
211+ # Updates the source commit used for a port.
212+ # Takes the commit hash, and the hash of the archive with the code that vcpkg will download.
213+ function Update-PortSource
214+ {
215+ param (
216+ [Parameter (Mandatory )]
217+ [string ]$Port ,
218+ [Parameter (Mandatory )]
219+ [string ]$Commit ,
220+ [Parameter (Mandatory )]
221+ [string ]$SourceHash
222+ )
223+
224+ $portDir = Join-Path $OverlayRoot $Port
225+
226+ Set-ParameterInPortFile $Port - ParameterName ' REF' - CurrentValuePattern ' [0-9a-f]{40}' - NewValue $Commit
227+ Set-ParameterInPortFile $Port - ParameterName ' SHA512' - CurrentValuePattern ' [0-9a-f]{128}' - NewValue $SourceHash
228+ }
229+
230+
182231New-PortOverlay cpprestsdk
183- Add-PatchToPort cpprestsdk - PatchRepo " microsoft/winget-cli" - PatchCommit " 888b4ed8f4f7d25cb05a47210e083fe29348163b" - PatchName " add-server-certificate-validation.patch" - PatchRoot " src/cpprestsdk/cpprestsdk"
232+ Add-PatchToPort cpprestsdk - PatchRepo ' microsoft/winget-cli' - PatchCommit ' 888b4ed8f4f7d25cb05a47210e083fe29348163b' - PatchName ' add-server-certificate-validation.patch' - PatchRoot ' src/cpprestsdk/cpprestsdk'
184233
185234New-PortOverlay libyaml
186- Add-PatchToPort libyaml - PatchRepo " yaml/libyaml " - PatchCommit " 51843fe48257c6b7b6e70cdec1db634f64a40818 " - PatchName " fix-parser-nesting.patch "
235+ Update-PortSource libyaml - Commit ' 840b65c40675e2d06bf40405ad3f12dec7f35923 ' - SourceHash ' de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302 '
0 commit comments