Skip to content

Commit 6d7209f

Browse files
committed
Add patch for old random headers on PHP 8.4
1 parent 2ee6851 commit 6d7209f

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/scripts/extensions/add_extensions.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,30 @@ pecl_install() {
176176
local extension=$1
177177
local prefix=${2:-extension}
178178
add_pecl >/dev/null 2>&1
179-
cpu_count="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo '1')"
180-
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS) MAKEFLAGS='-j $cpu_count'"
181-
suffix_opts="$(parse_args "$extension" CONFIGURE_OPTS) $(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
182-
IFS=' ' read -r -a libraries <<<"$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
183-
(( ${#libraries[@]} )) && add_libs "${libraries[@]}" >/dev/null 2>&1
184179
disable_extension_helper "${extension%-*}" >/dev/null 2>&1
185-
if [ "$version" = "5.3" ]; then
186-
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f "$extension" >/dev/null 2>&1
180+
# Compare version with 8.3 so it runs only on 8.4 and above
181+
# Install using the source interface as it allows for patching.
182+
if [[ $(printf "%s\n%s" "${version:?}" "8.3" | sort -V | head -n1) != "$version" ]]; then
183+
extension_version=${extension##*-};
184+
[ "$extension_version" = "${extension%-*}" ] && extension_version=$(get_pecl_version "$extension" "stable")
185+
add_extension_from_source "${extension%-*}" https://pecl.php.net "${extension%-*}" "${extension%-*}" "$extension_version" "$prefix" pecl
186+
check_extension "${extension%-*}" && return 0 || return 1;
187187
else
188-
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f -D "$(parse_pecl_configure_options "$suffix_opts")" "$extension" >/dev/null 2>&1
188+
cpu_count="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo '1')"
189+
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS) MAKEFLAGS='-j $cpu_count'"
190+
suffix_opts="$(parse_args "$extension" CONFIGURE_OPTS) $(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
191+
IFS=' ' read -r -a libraries <<<"$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
192+
(( ${#libraries[@]} )) && add_libs "${libraries[@]}" >/dev/null 2>&1
193+
if [ "$version" = "5.3" ]; then
194+
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f "$extension" >/dev/null 2>&1
195+
else
196+
yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f -D "$(parse_pecl_configure_options "$suffix_opts")" "$extension" >/dev/null 2>&1
197+
fi
198+
local exit_code=$?
199+
sudo pecl info "$extension" | grep -iq 'zend extension' && prefix=zend_extension
200+
enable_extension "${extension%-*}" "$prefix"
201+
return "$exit_code"
189202
fi
190-
local exit_code=$?
191-
sudo pecl info "$extension" | grep -iq 'zend extension' && prefix=zend_extension
192-
enable_extension "${extension%-*}" "$prefix"
193-
return "$exit_code"
194203
}
195204

196205
# Function to install a specific version of PECL extension.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
process_file() {
2+
local file=$1
3+
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"
4+
sed -i '/#include.*\(php_lcg.h\|php_mt_rand.h\|php_rand.h\|standard\/php_random\.h\)/d' "$file"
5+
}
6+
7+
export -f process_file
8+
9+
# Compare with 8.3 so it runs only on 8.4 and above
10+
if [[ $(printf "%s\n%s" "${version:?}" "8.3" | sort -V | head -n1) != "$version" ]]; then
11+
find . -type f \( -name "*.c" -o -name "*.h" \) -exec bash -c 'process_file "$0"' {} \;
12+
fi

src/scripts/extensions/source.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ run_group() {
8989

9090
patch_extension() {
9191
local extension=$1
92+
# shellcheck source=.
93+
. "${scripts:?}"/extensions/patches/common.sh
9294
if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then
9395
# shellcheck source=.
9496
. "${scripts:?}"/extensions/patches/"$extension".sh

0 commit comments

Comments
 (0)