Add patch for old random headers on PHP 8.4

This commit is contained in:
Shivam Mathur 2024-01-15 11:14:26 +05:30
parent 2ee6851e7b
commit 6d7209f44a
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 35 additions and 12 deletions

View File

@ -176,21 +176,30 @@ pecl_install() {
local extension=$1 local extension=$1
local prefix=${2:-extension} local prefix=${2:-extension}
add_pecl >/dev/null 2>&1 add_pecl >/dev/null 2>&1
cpu_count="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo '1')"
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS) MAKEFLAGS='-j $cpu_count'"
suffix_opts="$(parse_args "$extension" CONFIGURE_OPTS) $(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
IFS=' ' read -r -a libraries <<<"$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
(( ${#libraries[@]} )) && add_libs "${libraries[@]}" >/dev/null 2>&1
disable_extension_helper "${extension%-*}" >/dev/null 2>&1 disable_extension_helper "${extension%-*}" >/dev/null 2>&1
if [ "$version" = "5.3" ]; then # Compare version with 8.3 so it runs only on 8.4 and above
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f "$extension" >/dev/null 2>&1 # Install using the source interface as it allows for patching.
if [[ $(printf "%s\n%s" "${version:?}" "8.3" | sort -V | head -n1) != "$version" ]]; then
extension_version=${extension##*-};
[ "$extension_version" = "${extension%-*}" ] && extension_version=$(get_pecl_version "$extension" "stable")
add_extension_from_source "${extension%-*}" https://pecl.php.net "${extension%-*}" "${extension%-*}" "$extension_version" "$prefix" pecl
check_extension "${extension%-*}" && return 0 || return 1;
else else
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f -D "$(parse_pecl_configure_options "$suffix_opts")" "$extension" >/dev/null 2>&1 cpu_count="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo '1')"
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS) MAKEFLAGS='-j $cpu_count'"
suffix_opts="$(parse_args "$extension" CONFIGURE_OPTS) $(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
IFS=' ' read -r -a libraries <<<"$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
(( ${#libraries[@]} )) && add_libs "${libraries[@]}" >/dev/null 2>&1
if [ "$version" = "5.3" ]; then
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f "$extension" >/dev/null 2>&1
else
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f -D "$(parse_pecl_configure_options "$suffix_opts")" "$extension" >/dev/null 2>&1
fi
local exit_code=$?
sudo pecl info "$extension" | grep -iq 'zend extension' && prefix=zend_extension
enable_extension "${extension%-*}" "$prefix"
return "$exit_code"
fi fi
local exit_code=$?
sudo pecl info "$extension" | grep -iq 'zend extension' && prefix=zend_extension
enable_extension "${extension%-*}" "$prefix"
return "$exit_code"
} }
# Function to install a specific version of PECL extension. # Function to install a specific version of PECL extension.

View File

@ -0,0 +1,12 @@
process_file() {
local file=$1
sed -i '0,/#include.*\(php_lcg.h\|php_mt_rand.h\|php_rand.h\|standard\/php_random\.h\).*/s//\#include <ext\/random\/php_random.h>/' "$file"
sed -i '/#include.*\(php_lcg.h\|php_mt_rand.h\|php_rand.h\|standard\/php_random\.h\)/d' "$file"
}
export -f process_file
# Compare with 8.3 so it runs only on 8.4 and above
if [[ $(printf "%s\n%s" "${version:?}" "8.3" | sort -V | head -n1) != "$version" ]]; then
find . -type f \( -name "*.c" -o -name "*.h" \) -exec bash -c 'process_file "$0"' {} \;
fi

View File

@ -89,6 +89,8 @@ run_group() {
patch_extension() { patch_extension() {
local extension=$1 local extension=$1
# shellcheck source=.
. "${scripts:?}"/extensions/patches/common.sh
if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then
# shellcheck source=. # shellcheck source=.
. "${scripts:?}"/extensions/patches/"$extension".sh . "${scripts:?}"/extensions/patches/"$extension".sh