Use AdditionalFilesPath parameter in Install-PhpExtension

AdditionalFilesPath allows to specify a directory inside extension directory (which can be cached) for installing dependencies which are in the same archive as the extension

Fix dependency directory name to correctly use VCVersion in win32.ps1

Fix exception in phalcon4 setup on Windows.
This commit is contained in:
Shivam Mathur 2021-08-20 14:38:22 +05:30
parent 4d3cfaa653
commit ca319bd10e
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
2 changed files with 41 additions and 19 deletions

View File

@ -1,7 +1,7 @@
# Function to install phalcon
Function Add-PhalconHelper() {
if ($extension_version -eq '4') {
Install-Phpextension phalcon -MinimumStability stable -Path $php_dir
Install-Phpextension -Extension phalcon -MinimumStability stable -Path $php_dir
} else {
$domain = 'https://github.com'
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
@ -30,7 +30,7 @@ Function Add-Phalcon() {
if (Test-Path $ext_dir\php_psr.dll) {
Enable-PhpExtension -Extension psr -Path $php_dir
} else {
Install-Phpextension psr -MinimumStability stable -Path $php_dir
Install-Phpextension -Extension psr -MinimumStability stable -Path $php_dir
}
}
@ -49,7 +49,6 @@ Function Add-Phalcon() {
}
Add-Log $tick $extension $status
} catch [Exception] {
Write-Output $_.Exception|format-list -force
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}

View File

@ -3,7 +3,7 @@ param (
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$version = '7.4',
$version = '8.0',
[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
@ -119,7 +119,32 @@ Function Install-PSPackage() {
}
}
Function Add-ExtensionPrerequisites{
# Function to link dependencies to PHP directory.
Function Set-ExtensionPrerequisites
{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$deps_dir
)
$deps = Get-ChildItem -Recurse -Path $deps_dir
if ($deps.Count -ne 0) {
# Symlink dependencies instead of adding the directory to PATH ...
# as other actions change the PATH thus breaking extensions.
$deps | ForEach-Object {
New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force > $null 2>&1
}
} else {
Remove-Item $deps_dir -Recurse -Force
}
}
# Function to get extension pre-requisites.
# https://windows.php.net/downloads/pecl/deps
# Currently only imagick is supported using this Cmdlet.
Function Get-ExtensionPrerequisites{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
@ -127,17 +152,13 @@ Function Add-ExtensionPrerequisites{
[string]
$extension
)
$deps_dir = "$ext_dir\$extension-vc$installed.VCVersion-$arch"
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
$extensions_with_dependencies = ('imagick')
New-Item $deps_dir -Type Directory 2>&1 | Out-Null
if($extensions_with_dependencies.Contains($extension)) {
if(-not(Test-Path $deps_dir)) {
New-Item $deps_dir -Type Directory 2>&1 | Out-Null
Install-PhpExtensionPrerequisite -Extension $extension -InstallPath $deps_dir -PhpPath $php_dir
}
Get-ChildItem -Recurse -Path $deps_dir | ForEach-Object {
New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force >$null 2>&1
}
Install-PhpExtensionPrerequisite -Extension $extension -InstallPath $deps_dir -PhpPath $php_dir
}
return $deps_dir
}
# Function to add PHP extensions.
@ -170,20 +191,21 @@ Function Add-Extension {
Add-Log $tick $extension "Enabled"
}
default {
Add-ExtensionPrerequisites $extension
$deps_dir = Get-ExtensionPrerequisites $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled"
}
}
}
else {
Add-ExtensionPrerequisites $extension
$deps_dir = Get-ExtensionPrerequisites $extension
$params = @{ Extension = $extension; MinimumStability = $stability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') {
Install-PhpExtension -Extension $extension -Version $extension_version -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
} else {
Install-PhpExtension -Extension $extension -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
$params["Version"] = $extension_version
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled"
}
}
@ -216,6 +238,7 @@ Function Remove-Extension() {
}
}
# Function to configure composer.
Function Edit-ComposerConfig() {
Param(
[Parameter(Position = 0, Mandatory = $true)]