Skip to content

Commit c1e8828

Browse files
committed
Add patch to build extensions with PHP 8.5
1 parent 0363710 commit c1e8828

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$replacements = @{
2+
'ext/standard/php_smart_string.h' = 'Zend/zend_smart_string.h'
3+
'ext/standard/php_smart_string_public.h' = 'Zend/zend_smart_string.h'
4+
'zend_exception_get_default()' = 'zend_ce_exception'
5+
'zend_exception_get_default(TSRMLS_C)' = 'zend_ce_exception'
6+
}
7+
8+
$extensions = @('*.c', '*.h', '*.cpp', '*.hpp')
9+
10+
Get-ChildItem -Path . -Recurse -File -Include $extensions | ForEach-Object {
11+
$file = $_.FullName
12+
$content = Get-Content -Path $file -Raw
13+
$original = $content
14+
foreach ($old in $replacements.Keys) {
15+
$new = $replacements[$old]
16+
$content = $content.Replace($old, $new)
17+
}
18+
if ($content -ne $original) {
19+
Set-Content -Path $file -Value $content
20+
}
21+
}

extension/BuildPhpExtension/private/Add-Patches.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
Function Add-Patches {
22
<#
33
.SYNOPSIS
4-
Add patches to the extension.
5-
.PARAMETER Extension
6-
The extension name.
4+
Add patches to the extension source
5+
.PARAMETER PatchPath
6+
Path to the patch script
77
#>
88
[OutputType()]
99
param(
10-
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension')]
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Path to the patch script')]
1111
[ValidateNotNull()]
1212
[ValidateLength(1, [int]::MaxValue)]
13-
[string] $Extension
13+
[string] $PatchPath
1414
)
1515
begin {
1616
}
1717
process {
1818
# Apply patches only for php/php-windows-builder and shivammathur/php-windows-builder
1919
if($null -ne $env:GITHUB_REPOSITORY) {
2020
if($env:GITHUB_REPOSITORY -eq 'php/php-windows-builder' -or $env:GITHUB_REPOSITORY -eq 'shivammathur/php-windows-builder') {
21-
if(Test-Path -PATH $PSScriptRoot\..\patches\$Extension.ps1) {
22-
. $PSScriptRoot\..\patches\$Extension.ps1
21+
if(Test-Path -PATH $PSScriptRoot\..\patches\$PatchPath) {
22+
. $PSScriptRoot\..\patches\$PatchPath
2323
}
2424
}
2525
}

extension/BuildPhpExtension/private/Get-Extension.ps1

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function Get-Extension {
66
Extension URL
77
.PARAMETER ExtensionRef
88
Extension Reference
9+
.PARAMETER PhpVersion
10+
PHP Version
911
.PARAMETER BuildDirectory
1012
Build directory
1113
.PARAMETER LocalSrc
@@ -17,11 +19,15 @@ function Get-Extension {
1719
[string] $ExtensionUrl = '',
1820
[Parameter(Mandatory = $false, Position=1, HelpMessage='Extension Reference')]
1921
[string] $ExtensionRef = '',
20-
[Parameter(Mandatory = $true, Position=2, HelpMessage='Build directory')]
22+
[Parameter(Mandatory = $true, Position=2, HelpMessage='PHP Version')]
23+
[ValidateNotNull()]
24+
[ValidateLength(1, [int]::MaxValue)]
25+
[string] $PhpVersion,
26+
[Parameter(Mandatory = $true, Position=3, HelpMessage='Build directory')]
2127
[ValidateNotNull()]
2228
[ValidateLength(1, [int]::MaxValue)]
2329
[string] $BuildDirectory,
24-
[Parameter(Mandatory = $true, Position=3, HelpMessage='Is source local')]
30+
[Parameter(Mandatory = $true, Position=4, HelpMessage='Is source local')]
2531
[ValidateNotNull()]
2632
[bool] $LocalSrc = $false
2733
)
@@ -67,9 +73,15 @@ function Get-Extension {
6773

6874
$patches = $False
6975
if($null -ne $extension) {
70-
if(Test-Path -PATH $PSScriptRoot\..\patches\$extension.ps1) {
71-
if((Get-Content $PSScriptRoot\..\patches\$extension.ps1).Contains('config.w32')) {
72-
Add-Patches $extension
76+
if(Test-Path -PATH "$PSScriptRoot\..\patches\${extension}.ps1") {
77+
if((Get-Content "$PSScriptRoot\..\patches\${extension}.ps1").Contains('config.w32')) {
78+
Add-Patches "${extension}.ps1"
79+
$patches = $True
80+
}
81+
}
82+
if(Test-Path -PATH "$PSScriptRoot\..\patches\php\${PhpVersion}.ps1") {
83+
if((Get-Content "$PSScriptRoot\..\patches\php\${PhpVersion}.ps1").Contains('config.w32')) {
84+
Add-Patches "php\${PhpVersion}.ps1"
7385
$patches = $True
7486
}
7587
}
@@ -103,7 +115,8 @@ function Get-Extension {
103115
}
104116

105117
if(!$patches) {
106-
Add-Patches $name
118+
Add-Patches "${name}.ps1"
119+
Add-Patches "php\${PhpVersion}.ps1"
107120
}
108121
if(-not($LocalSrc)) {
109122
Add-BuildLog tick $name "Fetched $name extension"

extension/BuildPhpExtension/public/Invoke-PhpBuildExtension.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Invoke-PhpBuildExtension {
6464

6565
$source = Get-ExtensionSource -ExtensionUrl $ExtensionUrl -ExtensionRef $ExtensionRef
6666

67-
$extension = Get-Extension -ExtensionUrl $source.url -ExtensionRef $source.ref -BuildDirectory $buildDirectory -LocalSrc $source.local
67+
$extension = Get-Extension -ExtensionUrl $source.url -ExtensionRef $source.ref -PhpVersion $PhpVersion -BuildDirectory $buildDirectory -LocalSrc $source.local
6868

6969
Set-Location "$buildDirectory"
7070

0 commit comments

Comments
 (0)