Refactor extension functions to add_extensions scripts

This commit is contained in:
Shivam Mathur 2022-01-02 17:21:14 +05:30
parent d189609ea9
commit 2fd8046c9d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
34 changed files with 359 additions and 358 deletions

View File

@ -110,7 +110,7 @@ describe('Extension tests', () => {
const [formula, extension]: string[] = line.split('=');
const prefix: string =
extension == 'xdebug' ? 'zend_extension' : 'extension';
const output: string = fs.existsSync(`src/scripts/ext/${extension}.sh`)
const output: string = fs.existsSync(`src/scripts/extensions/${extension}.sh`)
? `add_${extension}`
: `add_brew_extension ${formula} ${prefix}`;
return [formula, '7.3', output];

6
dist/index.js vendored
View File

@ -238,7 +238,7 @@ async function addExtensionDarwin(extension_csv, version) {
case /^couchbase$|^geos$|^pdo_oci$|^oci8$|^(pecl_)?http|^pdo_firebird$/.test(extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension):
add_script += await utils.customPackage(ext_name, 'ext', extension, 'darwin');
add_script += await utils.customPackage(ext_name, 'extensions', extension, 'darwin');
return;
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix);
@ -286,7 +286,7 @@ async function addExtensionWindows(extension_csv, version) {
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
case /^(7\.[1-4]|8\.0)(pecl_)?http/.test(version_extension):
add_script += await utils.customPackage(ext_name, 'ext', extension, 'win32');
add_script += await utils.customPackage(ext_name, 'extensions', extension, 'win32');
return;
case /.+-(stable|beta|alpha|devel|snapshot)/.test(extension):
add_script += await utils.joins('\nAdd-Extension', ext_name, ext_version.replace('stable', ''));
@ -352,7 +352,7 @@ async function addExtensionLinux(extension_csv, version) {
case /(?<!5\.[3-5])intl-[\d]+\.[\d]+$/.test(version_extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
add_script += await utils.customPackage(ext_name, 'ext', extension, 'linux');
add_script += await utils.customPackage(ext_name, 'extensions', extension, 'linux');
return;
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix);

View File

@ -46,7 +46,7 @@ export async function addExtensionDarwin(
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
'extensions',
extension,
'darwin'
);
@ -142,7 +142,7 @@ export async function addExtensionWindows(
case /^(7\.[1-4]|8\.0)(pecl_)?http/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
'extensions',
extension,
'win32'
);
@ -269,7 +269,7 @@ export async function addExtensionLinux(
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
'extensions',
extension,
'linux'
);

View File

@ -30,13 +30,6 @@ add_log() {
fi
}
# Function to log result of installing extension.
add_extension_log() {
(
check_extension "$(echo "$1" | cut -d '-' -f 1)" && add_log "$tick" "$1" "$2"
) || add_log "$cross" "$1" "Could not install $1 on PHP ${semver:?}"
}
# Function to read env inputs.
read_env() {
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
@ -88,99 +81,6 @@ self_hosted_setup() {
fi
}
# Function to test if extension is loaded.
check_extension() {
local extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
php -m | grep -i -q "$extension"
fi
}
# Function to check if extension is shared
shared_extension() {
[ -e "${ext_dir:?}/$1.so" ]
}
# Function to enable cached extension's dependencies.
enable_cache_extension_dependencies() {
if [ -d /tmp/extcache ] && shared_extension "$1"; then
cache_dir=$(find /tmp/extcache -maxdepth 1 -type d -regex ".*$1[0-9]*")
if [[ -n "$cache_dir" ]]; then
IFS=" " read -r -a deps <<<"$(find "$cache_dir" -maxdepth 1 -type f -name "*" -exec basename {} \; | tr '\n' ' ')"
if [[ -n "${deps[*]}" ]] && php "${deps[@]/#/-d ${2}=}" -d "${2}=$1" -m 2>/dev/null | grep -i -q "$1"; then
for ext in "${deps[@]}"; do
sudo rm -rf /tmp/extcache/"$ext"
enable_extension "$ext" "$2"
done
fi
fi
fi
}
# Function to enable existing extensions.
enable_extension() {
modules_dir="/var/lib/php/modules/$version"
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
enable_extension_dependencies "$1" "$2"
enable_cache_extension_dependencies "$1" "$2"
if ! check_extension "$1" && shared_extension "$1"; then
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
fi
}
# Function to get a map of extensions and their dependent shared extensions.
get_extension_map() {
php -d'error_reporting=0' "${dist:?}"/../src/scripts/ext/extension_map.php
}
# Function to enable extension dependencies which are also extensions.
enable_extension_dependencies() {
local extension=$1
prefix=$2
if ! [ -e /tmp/map.orig ]; then
get_extension_map | sudo tee /tmp/map.orig >/dev/null
fi
for dependency in $(grep "$extension:" /tmp/map.orig | cut -d ':' -f 2 | tr '\n' ' '); do
enable_extension "$dependency" "$prefix"
done
}
# Function to disable dependent extensions.
disable_extension_dependents() {
local extension=$1
for dependent in $(get_extension_map | grep -E ".*:.*\s$extension(\s|$)" | cut -d ':' -f 1 | tr '\n' ' '); do
disable_extension_helper "$dependent" true
add_log "${tick:?}" ":$extension" "Disabled $dependent as it depends on $extension"
done
}
# Function to disable an extension.
disable_extension() {
local extension=$1
if check_extension "$extension"; then
if shared_extension "$extension"; then
disable_extension_helper "$extension" true
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Disabled") ||
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP ${semver:?}"
else
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP $semver as it not a shared extension"
fi
elif shared_extension "$extension"; then
add_log "${tick:?}" ":$extension" "Disabled"
else
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
fi
}
# Function to disable shared extensions.
disable_all_shared() {
sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true
sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
add_log "${tick:?}" "none" "Disabled all shared extensions"
}
# Function to configure PHP
configure_php() {
(
@ -190,65 +90,6 @@ configure_php() {
) | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
}
# Function to configure PECL.
configure_pecl() {
if ! [ -e /tmp/pecl_config ]; then
for script in pear pecl; do
sudo "$script" config-set php_ini "${pecl_file:-${ini_file[@]}}"
sudo "$script" channel-update "$script".php.net
done
echo '' | sudo tee /tmp/pecl_config >/dev/null 2>&1
fi
}
# Function to get the PECL version of an extension.
get_pecl_version() {
local extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "([0-9]+\.[0-9]+\.[0-9]+${stability}[0-9]+)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
fi
echo "$pecl_version"
}
# Function to install PECL extensions and accept default options
pecl_install() {
local extension=$1
add_pecl >/dev/null 2>&1
yes '' 2>/dev/null | sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to install a specific version of PECL extension.
add_pecl_extension() {
local extension=$1
pecl_version=$2
prefix=$3
enable_extension "$extension" "$prefix"
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
ext_version=$(php -r "echo phpversion('$extension');")
if [ "${ext_version/-/}" = "$pecl_version" ]; then
add_log "${tick:?}" "$extension" "Enabled"
else
disable_extension_helper "$extension" >/dev/null 2>&1
pecl_install "$extension-$pecl_version"
add_extension_log "$extension-$pecl_version" "Installed and enabled"
fi
}
# Function to setup pre-release extensions using PECL.
add_unstable_extension() {
local extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
add_pecl_extension "$extension" "$pecl_version" "$prefix"
}
# Function to get PHP version in semver format.
php_semver() {
php -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+((-?[a-zA-Z]+([0-9]+)?)?){2}" | head -n 1
@ -260,6 +101,6 @@ php_src_tag() {
if [[ -n "${commit}" ]]; then
echo "$commit"
else
echo "php-$semver"
echo "php-${semver:?}"
fi
}

View File

@ -250,8 +250,9 @@ export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
# shellcheck source=.
. "${scripts:?}"/common.sh
. "${scripts:?}"/ext/source.sh
. "${scripts:?}"/tools/add_tools.sh
. "${scripts:?}"/extensions/source.sh
. "${scripts:?}"/extensions/add_extensions.sh
read_env
self_hosted_setup
setup_php

View File

@ -0,0 +1,184 @@
# 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 add PHP extensions.
Function Add-Extension {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string]
$stability = 'stable',
[Parameter(Position = 2, Mandatory = $false)]
[ValidateNotNull()]
[ValidatePattern('^\d+(\.\d+){0,2}$')]
[string]
$extension_version = ''
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
New-Item $deps_dir -Type Directory -Force > $null 2>&1
if ($null -ne $extension_info) {
switch ($extension_info.State) {
'Builtin' {
Add-Log $tick $extension "Enabled"
}
'Enabled' {
Add-Log $tick $extension "Enabled"
}
default {
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled"
}
}
}
else {
# Patch till PHP 8.1 DLLs are released as stable.
$minimumStability = 'stable'
if($version -eq '8.1' -and $stability -eq 'stable') {
$minimumStability = 'snapshot'
}
$params = @{ Extension = $extension; MinimumStability = $minimumStability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') {
$params["Version"] = $extension_version
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled"
}
}
catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}
# Function to get a map of extensions and their dependent shared extensions.
Function Get-ExtensionMap {
php -d'error_reporting=0' $dist\..\src\scripts\ext\extension_map.php
}
# Function to enable extension dependencies which are also extensions.
Function Enable-ExtensionDependencies {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
if (-not(Test-Path $env:TEMP\map.orig)) {
Get-ExtensionMap | Set-Content -Path $env:TEMP\map.orig
}
$entry = findstr /r "$extension`:.*" $env:TEMP\map.orig
if($entry) {
$entry.split(':')[1].trim().split(' ') | ForEach-Object {
if (-not(php -m | findstr -i $_)) {
Enable-PhpExtension -Extension $_ -Path $php_dir
}
}
}
}
# Function to disable dependent extensions.
Function Disable-DependentExtensions() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
Get-ExtensionMap | Select-String -Pattern ".*:.*\s$extension(\s|$)" | ForEach-Object {
$dependent = $_.Matches[0].Value.split(':')[0];
Disable-ExtensionHelper -Extension $dependent -DisableDependents
Add-Log $tick ":$extension" "Disabled $dependent as it depends on $extension"
}
}
# Helper function to disable an extension.
Function Disable-ExtensionHelper() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[switch] $DisableDependents
)
if($DisableDependents) {
Disable-DependentExtensions $extension
}
Disable-PhpExtension -Extension $extension -Path $php_dir
}
# Function to disable an extension.
Function Disable-Extension() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$DisableDependents
)
if(php -m | findstr -i $extension) {
if(Test-Path $ext_dir\php_$extension.dll) {
try {
$params = @{ Extension = $extension; DisableDependents = ($DisableDependents -ne 'false') }
Disable-ExtensionHelper @params
Add-Log $tick ":$extension" "Disabled"
} catch {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion)"
}
} else {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion) as it not a shared extension"
}
} elseif(Test-Path $ext_dir\php_$extension.dll) {
Add-Log $tick ":$extension" "Disabled"
} else {
Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
}
}
# Function to disable shared extensions.
Function Disable-AllShared() {
(Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini
Add-Log $tick "none" "Disabled all shared extensions"
}
# Function to handle request to add PECL.
Function Add-Pecl() {
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
}

View File

@ -0,0 +1,158 @@
# Function to log result of installing extension.
add_extension_log() {
(
check_extension "$(echo "$1" | cut -d '-' -f 1)" && add_log "${tick:?}" "$1" "$2"
) || add_log "${cross:?}" "$1" "Could not install $1 on PHP ${semver:?}"
}
# Function to test if extension is loaded.
check_extension() {
local extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
php -m | grep -i -q "$extension"
fi
}
# Function to check if extension is shared
shared_extension() {
[ -e "${ext_dir:?}/$1.so" ]
}
# Function to enable cached extension's dependencies.
enable_cache_extension_dependencies() {
if [ -d /tmp/extcache ] && shared_extension "$1"; then
cache_dir=$(find /tmp/extcache -maxdepth 1 -type d -regex ".*$1[0-9]*")
if [[ -n "$cache_dir" ]]; then
IFS=" " read -r -a deps <<<"$(find "$cache_dir" -maxdepth 1 -type f -name "*" -exec basename {} \; | tr '\n' ' ')"
if [[ -n "${deps[*]}" ]] && php "${deps[@]/#/-d ${2}=}" -d "${2}=$1" -m 2>/dev/null | grep -i -q "$1"; then
for ext in "${deps[@]}"; do
sudo rm -rf /tmp/extcache/"$ext"
enable_extension "$ext" "$2"
done
fi
fi
fi
}
# Function to enable existing extensions.
enable_extension() {
modules_dir="/var/lib/php/modules/${version:?}"
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
enable_extension_dependencies "$1" "$2"
enable_cache_extension_dependencies "$1" "$2"
if ! check_extension "$1" && shared_extension "$1"; then
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
fi
}
# Function to get a map of extensions and their dependent shared extensions.
get_extension_map() {
php -d'error_reporting=0' "${dist:?}"/../src/scripts/extensions/extension_map.php
}
# Function to enable extension dependencies which are also extensions.
enable_extension_dependencies() {
local extension=$1
prefix=$2
if ! [ -e /tmp/map.orig ]; then
get_extension_map | sudo tee /tmp/map.orig >/dev/null
fi
for dependency in $(grep "$extension:" /tmp/map.orig | cut -d ':' -f 2 | tr '\n' ' '); do
enable_extension "$dependency" "$prefix"
done
}
# Function to disable dependent extensions.
disable_extension_dependents() {
local extension=$1
for dependent in $(get_extension_map | grep -E ".*:.*\s$extension(\s|$)" | cut -d ':' -f 1 | tr '\n' ' '); do
disable_extension_helper "$dependent" true
add_log "${tick:?}" ":$extension" "Disabled $dependent as it depends on $extension"
done
}
# Function to disable an extension.
disable_extension() {
local extension=$1
if check_extension "$extension"; then
if shared_extension "$extension"; then
disable_extension_helper "$extension" true
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Disabled") ||
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP ${semver:?}"
else
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP $semver as it not a shared extension"
fi
elif shared_extension "$extension"; then
add_log "${tick:?}" ":$extension" "Disabled"
else
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
fi
}
# Function to disable shared extensions.
disable_all_shared() {
sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true
sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
add_log "${tick:?}" "none" "Disabled all shared extensions"
}
# Function to configure PECL.
configure_pecl() {
if ! [ -e /tmp/pecl_config ]; then
for script in pear pecl; do
sudo "$script" config-set php_ini "${pecl_file:-${ini_file[@]}}"
sudo "$script" channel-update "$script".php.net
done
echo '' | sudo tee /tmp/pecl_config >/dev/null 2>&1
fi
}
# Function to get the PECL version of an extension.
get_pecl_version() {
local extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "([0-9]+\.[0-9]+\.[0-9]+${stability}[0-9]+)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
fi
echo "$pecl_version"
}
# Function to install PECL extensions and accept default options
pecl_install() {
local extension=$1
add_pecl >/dev/null 2>&1
yes '' 2>/dev/null | sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to install a specific version of PECL extension.
add_pecl_extension() {
local extension=$1
pecl_version=$2
prefix=$3
enable_extension "$extension" "$prefix"
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
ext_version=$(php -r "echo phpversion('$extension');")
if [ "${ext_version/-/}" = "$pecl_version" ]; then
add_log "${tick:?}" "$extension" "Enabled"
else
disable_extension_helper "$extension" >/dev/null 2>&1
pecl_install "$extension-$pecl_version"
add_extension_log "$extension-$pecl_version" "Installed and enabled"
fi
}
# Function to setup pre-release extensions using PECL.
add_unstable_extension() {
local extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
add_pecl_extension "$extension" "$pecl_version" "$prefix"
}

View File

@ -57,4 +57,4 @@ add_cubrid() {
}
# shellcheck source=.
. "${scripts:?}"/ext/patches/phpize.sh
. "${scripts:?}"/extensions/patches/phpize.sh

View File

@ -62,4 +62,4 @@ add_oci() {
}
# shellcheck source=.
. "${scripts:?}"/ext/patches/phpize.sh
. "${scripts:?}"/extensions/patches/phpize.sh

View File

@ -76,9 +76,9 @@ run_group() {
patch_extension() {
extension=$1
if [ -e "${scripts:?}"/ext/patches/"$extension".sh ]; then
if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then
# shellcheck source=.
. "${scripts:?}"/ext/patches/"$extension".sh
. "${scripts:?}"/extensions/patches/"$extension".sh
patch_"${extension}"
fi
}

View File

@ -231,9 +231,10 @@ scripts="${dist}"/../src/scripts
. /etc/os-release
# shellcheck source=.
. "${scripts:?}"/common.sh
. "${scripts:?}"/ext/source.sh
. "${scripts:?}"/tools/ppa.sh
. "${scripts:?}"/tools/add_tools.sh
. "${scripts:?}"/extensions/source.sh
. "${scripts:?}"/extensions/add_extensions.sh
read_env
self_hosted_setup
setup_php

View File

@ -119,28 +119,6 @@ Function Install-PSPackage() {
}
}
# 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 add CA certificates to PHP.
Function Add-PhpCAInfo {
try {
@ -151,169 +129,6 @@ Function Add-PhpCAInfo {
}
}
# Function to add PHP extensions.
Function Add-Extension {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string]
$stability = 'stable',
[Parameter(Position = 2, Mandatory = $false)]
[ValidateNotNull()]
[ValidatePattern('^\d+(\.\d+){0,2}$')]
[string]
$extension_version = ''
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
New-Item $deps_dir -Type Directory -Force > $null 2>&1
if ($null -ne $extension_info) {
switch ($extension_info.State) {
'Builtin' {
Add-Log $tick $extension "Enabled"
}
'Enabled' {
Add-Log $tick $extension "Enabled"
}
default {
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled"
}
}
}
else {
# Patch till PHP 8.1 DLLs are released as stable.
$minimumStability = 'stable'
if($version -eq '8.1' -and $stability -eq 'stable') {
$minimumStability = 'snapshot'
}
$params = @{ Extension = $extension; MinimumStability = $minimumStability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') {
$params["Version"] = $extension_version
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled"
}
}
catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}
# Function to get a map of extensions and their dependent shared extensions.
Function Get-ExtensionMap {
php -d'error_reporting=0' $dist\..\src\scripts\ext\extension_map.php
}
# Function to enable extension dependencies which are also extensions.
Function Enable-ExtensionDependencies {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
if (-not(Test-Path $env:TEMP\map.orig)) {
Get-ExtensionMap | Set-Content -Path $env:TEMP\map.orig
}
$entry = findstr /r "$extension`:.*" $env:TEMP\map.orig
if($entry) {
$entry.split(':')[1].trim().split(' ') | ForEach-Object {
if (-not(php -m | findstr -i $_)) {
Enable-PhpExtension -Extension $_ -Path $php_dir
}
}
}
}
# Function to disable dependent extensions.
Function Disable-DependentExtensions() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
Get-ExtensionMap | Select-String -Pattern ".*:.*\s$extension(\s|$)" | ForEach-Object {
$dependent = $_.Matches[0].Value.split(':')[0];
Disable-ExtensionHelper -Extension $dependent -DisableDependents
Add-Log $tick ":$extension" "Disabled $dependent as it depends on $extension"
}
}
# Helper function to disable an extension.
Function Disable-ExtensionHelper() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[switch] $DisableDependents
)
if($DisableDependents) {
Disable-DependentExtensions $extension
}
Disable-PhpExtension -Extension $extension -Path $php_dir
}
# Function to disable an extension.
Function Disable-Extension() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$DisableDependents
)
if(php -m | findstr -i $extension) {
if(Test-Path $ext_dir\php_$extension.dll) {
try {
$params = @{ Extension = $extension; DisableDependents = ($DisableDependents -ne 'false') }
Disable-ExtensionHelper @params
Add-Log $tick ":$extension" "Disabled"
} catch {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion)"
}
} else {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion) as it not a shared extension"
}
} elseif(Test-Path $ext_dir\php_$extension.dll) {
Add-Log $tick ":$extension" "Disabled"
} else {
Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
}
}
# Function to disable shared extensions.
Function Disable-AllShared() {
(Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini
Add-Log $tick "none" "Disabled all shared extensions"
}
# Function to handle request to add PECL.
Function Add-Pecl() {
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
}
# Variables
$tick = ([char]8730)
$cross = ([char]10007)
@ -363,6 +178,7 @@ if($env:RUNNER -eq 'self-hosted') {
}
. $dist\..\src\scripts\tools\add_tools.ps1
. $dist\..\src\scripts\extensions\add_extensions.ps1
Add-Printf >$null 2>&1
Step-Log "Setup PhpManager"