Skip to content

Commit 670e80e

Browse files
committed
Add support in Add-Extension for in-tree extensions
1 parent 5d406fb commit 670e80e

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

extension/BuildPhpExtension/private/Add-Extension.ps1

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,55 @@ Function Add-Extension {
2222
}
2323
process {
2424
Set-GAGroup start
25-
Get-File -Url "https://pecl.php.net/get/$Extension" -OutFile "$Extension.tgz"
2625
$currentDirectory = (Get-Location).Path
27-
& tar -xzf "$Extension.tgz" -C $currentDirectory
28-
Set-Location "$Extension-*"
29-
$extensionBuildDirectory = Join-Path -Path (Get-Location).Path -ChildPath $config.build_directory
30-
# Apply patches only for php/php-windows-builder and shivammathur/php-windows-builder
31-
if($null -ne $env:GITHUB_REPOSITORY) {
32-
if($env:GITHUB_REPOSITORY -eq 'php/php-windows-builder' -or $env:GITHUB_REPOSITORY -eq 'shivammathur/php-windows-builder') {
33-
if(Test-Path -PATH $PSScriptRoot\..\patches\$Extension.ps1) {
34-
. $PSScriptRoot\..\patches\$Extension.ps1
26+
$extensionList = & "$currentDirectory\php-bin\php.exe" -m
27+
if(-not($extensionList -contains $Extension)) {
28+
if(-not(Test-Path $currentDirectory\php-bin\ext\$php_$Extension.dll)) {
29+
Get-File -Url "https://pecl.php.net/get/$Extension" -OutFile "$Extension.tgz"
30+
& tar -xzf "$Extension.tgz" -C $currentDirectory
31+
Set-Location "$Extension-*"
32+
$extensionBuildDirectory = Join-Path -Path (Get-Location).Path -ChildPath $config.build_directory
33+
# Apply patches only for php/php-windows-builder and shivammathur/php-windows-builder
34+
if ($null -ne $env:GITHUB_REPOSITORY)
35+
{
36+
if ($env:GITHUB_REPOSITORY -eq 'php/php-windows-builder' -or $env:GITHUB_REPOSITORY -eq 'shivammathur/php-windows-builder')
37+
{
38+
if (Test-Path -PATH $PSScriptRoot\..\patches\$Extension.ps1)
39+
{
40+
. $PSScriptRoot\..\patches\$Extension.ps1
41+
}
42+
}
3543
}
44+
$configW32Content = [string](Get-Content -Path "config.w32")
45+
$argument = Get-ArgumentFromConfig $Extension $configW32Content
46+
$bat_content = @()
47+
$bat_content += ""
48+
$bat_content += "call phpize 2>&1"
49+
$bat_content += "call configure --with-php-build=`"..\deps`" $argument --with-mp=`"disable`" --with-prefix=$Prefix 2>&1"
50+
$bat_content += "nmake /nologo 2>&1"
51+
$bat_content += "exit %errorlevel%"
52+
Set-Content -Encoding "ASCII" -Path $Extension-task.bat -Value $bat_content
53+
$builder = "$currentDirectory\php-sdk\phpsdk-starter.bat"
54+
$task = (Get-Item -Path "." -Verbose).FullName + "\$Extension-task.bat"
55+
$suffix = "php_" + (@(
56+
$Config.name,
57+
$Config.ref,
58+
$Config.php_version,
59+
$Config.ts,
60+
$Config.vs_version,
61+
$Config.arch
62+
) -join "-")
63+
& $builder -c $Config.vs_version -a $Config.Arch -s $Config.vs_toolset -t $task | Tee-Object -FilePath "build-$suffix.txt"
64+
Write-Host (Get-Content "build-$suffix.txt" -Raw)
65+
$includePath = "$currentDirectory\php-dev\include"
66+
New-Item -Path $includePath\ext -Name $Extension -ItemType "directory" | Out-Null
67+
Get-ChildItem -Path (Get-Location).Path -Recurse -Include '*.h', '*.c' | Copy-Item -Destination "$includePath\ext\$Extension"
68+
Copy-Item -Path "$extensionBuildDirectory\*.dll" -Destination "$currentDirectory\php-bin\ext" -Force
69+
Copy-Item -Path "$extensionBuildDirectory\*.lib" -Destination "$currentDirectory\php-dev\lib" -Force
3670
}
71+
Add-Content -Path "$currentDirectory\php-bin\php.ini" -Value "extension=$Extension"
72+
Set-Location $currentDirectory
3773
}
38-
$configW32Content = [string](Get-Content -Path "config.w32")
39-
$argument = Get-ArgumentFromConfig $Extension $configW32Content
40-
$bat_content = @()
41-
$bat_content += ""
42-
$bat_content += "call phpize 2>&1"
43-
$bat_content += "call configure --with-php-build=`"..\deps`" $argument --with-mp=`"disable`" --with-prefix=$Prefix 2>&1"
44-
$bat_content += "nmake /nologo 2>&1"
45-
$bat_content += "exit %errorlevel%"
46-
Set-Content -Encoding "ASCII" -Path $Extension-task.bat -Value $bat_content
47-
$builder = "$currentDirectory\php-sdk\phpsdk-starter.bat"
48-
$task = (Get-Item -Path "." -Verbose).FullName + "\$Extension-task.bat"
49-
$suffix = "php_" + (@(
50-
$Config.name,
51-
$Config.ref,
52-
$Config.php_version,
53-
$Config.ts,
54-
$Config.vs_version,
55-
$Config.arch
56-
) -join "-")
57-
& $builder -c $Config.vs_version -a $Config.Arch -s $Config.vs_toolset -t $task | Tee-Object -FilePath "build-$suffix.txt"
58-
Write-Host (Get-Content "build-$suffix.txt" -Raw)
59-
$includePath = "$currentDirectory\php-dev\include"
60-
New-Item -Path $includePath\ext -Name $Extension -ItemType "directory" | Out-Null
61-
Get-ChildItem -Path (Get-Location).Path -Recurse -Include '*.h', '*.c' | Copy-Item -Destination "$includePath\ext\$Extension"
62-
Copy-Item -Path "$extensionBuildDirectory\*.dll" -Destination "$currentDirectory\php-bin\ext" -Force
63-
Copy-Item -Path "$extensionBuildDirectory\*.lib" -Destination "$currentDirectory\php-dev\lib" -Force
64-
Add-Content -Path "$currentDirectory\php-bin\php.ini" -Value "extension=$Extension"
65-
Set-Location $currentDirectory
6674
Set-GAGroup end
6775
}
6876
end {

0 commit comments

Comments
 (0)