Skip to content

Commit 491ead5

Browse files
pl4ntyclaude
andcommitted
PowerShell 5 support in CreatePortOverlay.ps1
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ab78fa9 commit 491ead5

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/VcpkgPortOverlay/CreatePortOverlay.ps1

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ $OverlayRoot = $PSScriptRoot
1111

1212
$ErrorActionPreference = "Stop"
1313

14+
# Windows PowerShell 5.1 (.NET Framework) does not load these assemblies by default.
15+
Add-Type -AssemblyName System.IO.Compression
16+
Add-Type -AssemblyName System.IO.Compression.FileSystem
17+
18+
# Windows PowerShell 5.1's Out-File defaults to UTF-16; vcpkg requires UTF-8 port files.
19+
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
20+
1421

1522
# Gets the versions of a port available from the official registry.
1623
# This is read from the versions JSON in the main branch.
@@ -29,7 +36,7 @@ function Get-PortVersions
2936

3037
$initial = $Port[0]
3138
$jsonUri = "https://raw.githubusercontent.com/microsoft/vcpkg/heads/master/versions/$initial-/$Port.json"
32-
$versions = (Invoke-WebRequest -Uri $jsonUri).Content | ConvertFrom-Json -Depth 5
39+
$versions = (Invoke-WebRequest -Uri $jsonUri -UseBasicParsing).Content | ConvertFrom-Json
3340
return $versions.versions
3441
}
3542

@@ -62,7 +69,7 @@ function Get-GitTreeAsArchive
6269
)
6370

6471
$archiveUri = "https://github.com/$Repo/archive/$gitTree.zip"
65-
$response = Invoke-WebRequest -Uri $archiveUri
72+
$response = Invoke-WebRequest -Uri $archiveUri -UseBasicParsing
6673
$zipStream = [System.IO.MemoryStream]::new($response.Content)
6774
$zipArchive = [System.IO.Compression.ZipArchive]::new($zipStream)
6875
return $zipArchive
@@ -154,7 +161,7 @@ function Expand-PortfileTemplate
154161
[string]$CommentedFunction = 'vcpkg_from_github'
155162
)
156163

157-
$portFilePath = Join-Path $OverlayRoot $Port 'portfile.cmake'
164+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, 'portfile.cmake')
158165
$lines = Get-Content $portFilePath
159166

160167
$result = [System.Collections.Generic.List[string]]::new()
@@ -227,7 +234,7 @@ function Get-GitHubPatch
227234
)
228235

229236
$patchUri = "https://github.com/$repo/commit/$commit.patch"
230-
$response = Invoke-WebRequest -Uri $patchUri
237+
$response = Invoke-WebRequest -Uri $patchUri -UseBasicParsing
231238
return $response.Content
232239
}
233240

@@ -290,7 +297,7 @@ function Add-PatchToPortFile
290297

291298
# Look for the line that says "PATCHES" and add the new patch before the closing parenthesis
292299

293-
$portFilePath = Join-Path $OverlayRoot $Port "portfile.cmake"
300+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, "portfile.cmake")
294301
$originalPortFile = Get-Content $portFilePath
295302

296303
$modifiedPortFile = @()
@@ -325,7 +332,7 @@ function Remove-PortPatches
325332

326333
# Look for the line that says "PATCHES"
327334

328-
$portFilePath = Join-Path $OverlayRoot $Port "portfile.cmake"
335+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, "portfile.cmake")
329336
$originalPortFile = Get-Content $portFilePath
330337

331338
$modifiedPortFile = @()
@@ -392,9 +399,9 @@ function Add-LocalPatch
392399
[string]$PatchName
393400
)
394401

395-
Copy-Item (Join-Path $OverlayRoot 'patches' $Port $PatchName) (Join-Path $OverlayRoot $Port)
402+
Copy-Item ([System.IO.Path]::Combine($OverlayRoot, 'patches', $Port, $PatchName)) (Join-Path $OverlayRoot $Port)
396403

397-
$portFilePath = Join-Path $OverlayRoot $Port 'portfile.cmake'
404+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, 'portfile.cmake')
398405
$lines = Get-Content $portFilePath
399406
$hasPatchesKeyword = $lines | Where-Object { $_ -match '\bPATCHES\b' }
400407

@@ -435,7 +442,7 @@ function Set-ParameterInPortFile
435442
[string]$NewValue
436443
)
437444

438-
$portFilePath = Join-Path $OverlayRoot $Port 'portfile.cmake'
445+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, 'portfile.cmake')
439446
$originalPortFile = Get-Content $portFilePath
440447

441448
# Explanation for the regex:
@@ -459,7 +466,7 @@ function Set-CmakeConfigureOptions
459466
[string[]]$Options
460467
)
461468

462-
$portFilePath = Join-Path $OverlayRoot $Port 'portfile.cmake'
469+
$portFilePath = [System.IO.Path]::Combine($OverlayRoot, $Port, 'portfile.cmake')
463470
$originalPortFile = Get-Content $portFilePath
464471

465472
$modifiedPortFile = @()
@@ -499,7 +506,7 @@ function Set-PortFilePlaceholder
499506
[string]$Value
500507
)
501508

502-
$filePath = Join-Path $OverlayRoot $Port $File
509+
$filePath = [System.IO.Path]::Combine($OverlayRoot, $Port, $File)
503510
$content = (Get-Content -Raw $filePath) -replace "<$Placeholder>", $Value
504511
[System.IO.File]::WriteAllText($filePath, $content, [System.Text.Encoding]::UTF8)
505512
}
@@ -531,7 +538,7 @@ function Update-PortVersion
531538
[string]$Port
532539
)
533540

534-
$portJsonPath = Join-Path $OverlayRoot $Port "vcpkg.json"
541+
$portJsonPath = [System.IO.Path]::Combine($OverlayRoot, $Port, "vcpkg.json")
535542
$portDefinition = Get-Content $portJsonPath | ConvertFrom-Json
536543
$portDefinition."port-version" += 1
537544
$portDefinition | ConvertTo-Json -Depth 5 | Out-File $portJsonPath

0 commit comments

Comments
 (0)