From 6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 15 Jan 2024 11:14:26 +0530 Subject: [PATCH] Add patch for old random headers on PHP 8.4 --- src/scripts/extensions/add_extensions.sh | 33 +++++++++++++++--------- src/scripts/extensions/patches/common.sh | 12 +++++++++ src/scripts/extensions/source.sh | 2 ++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/scripts/extensions/patches/common.sh diff --git a/src/scripts/extensions/add_extensions.sh b/src/scripts/extensions/add_extensions.sh index 6ad98709..d07b959f 100644 --- a/src/scripts/extensions/add_extensions.sh +++ b/src/scripts/extensions/add_extensions.sh @@ -176,21 +176,30 @@ pecl_install() { local extension=$1 local prefix=${2:-extension} 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 - if [ "$version" = "5.3" ]; then - yes '' 2>/dev/null | sudo "$prefix_opts" pecl install -f "$extension" >/dev/null 2>&1 + # Compare version with 8.3 so it runs only on 8.4 and above + # 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 - 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 - 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. diff --git a/src/scripts/extensions/patches/common.sh b/src/scripts/extensions/patches/common.sh new file mode 100644 index 00000000..3aab5e01 --- /dev/null +++ b/src/scripts/extensions/patches/common.sh @@ -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 /' "$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 diff --git a/src/scripts/extensions/source.sh b/src/scripts/extensions/source.sh index 36d15fb2..d5c57a2c 100644 --- a/src/scripts/extensions/source.sh +++ b/src/scripts/extensions/source.sh @@ -89,6 +89,8 @@ run_group() { patch_extension() { local extension=$1 + # shellcheck source=. + . "${scripts:?}"/extensions/patches/common.sh if [ -e "${scripts:?}"/extensions/patches/"$extension".sh ]; then # shellcheck source=. . "${scripts:?}"/extensions/patches/"$extension".sh