mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Fix enabling cached extensions with custom support
This commit is contained in:
parent
52d2b3b70b
commit
cb5db3f888
@ -107,22 +107,18 @@ shared_extension() {
|
|||||||
[ -e "${ext_dir:?}/$1.so" ]
|
[ -e "${ext_dir:?}/$1.so" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable cached extensions.
|
# Function to enable cached extension's dependencies.
|
||||||
enable_cache_extension() {
|
enable_cache_extension_dependencies() {
|
||||||
deps=()
|
if [ -d /tmp/extcache ] && shared_extension "$1"; then
|
||||||
for ext in /tmp/extcache/"$1"/*; do
|
cache_dir=$(find /tmp/extcache -maxdepth 1 -type d -regex ".*$1[0-9]*")
|
||||||
deps+=("$(basename "$ext")")
|
if [[ -n "$cache_dir" ]]; then
|
||||||
done
|
IFS=" " read -r -a deps <<<"$(find "$cache_dir" -maxdepth 1 -type f -name "*" -exec basename {} \; | tr '\n' ' ')"
|
||||||
if [ "x${deps[*]}" = "x" ]; then
|
if [[ -n "${deps[*]}" ]] && php "${deps[@]/#/-d ${2}=}" -d "${2}=$1" -m 2>/dev/null | grep -i -q "$1"; then
|
||||||
sudo rm -rf /tmp/extcache/"$1"
|
for ext in "${deps[@]}"; do
|
||||||
enable_extension "$1" "$2"
|
sudo rm -rf /tmp/extcache/"$ext"
|
||||||
else
|
enable_extension "$ext" "$2"
|
||||||
deps+=("$1")
|
done
|
||||||
if php "${deps[@]/#/-d ${2}=}" -m 2>/dev/null | grep -i -q "$1"; then
|
fi
|
||||||
for ext in "${deps[@]}"; do
|
|
||||||
sudo rm -rf /tmp/extcache/"$ext"
|
|
||||||
enable_extension "$ext" "$2"
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -132,9 +128,8 @@ enable_extension() {
|
|||||||
modules_dir="/var/lib/php/modules/$version"
|
modules_dir="/var/lib/php/modules/$version"
|
||||||
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
|
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
|
||||||
enable_extension_dependencies "$1" "$2"
|
enable_extension_dependencies "$1" "$2"
|
||||||
if [ -d /tmp/extcache/"$1" ]; then
|
enable_cache_extension_dependencies "$1" "$2"
|
||||||
enable_cache_extension "$1" "$2"
|
if ! check_extension "$1" && shared_extension "$1"; then
|
||||||
elif ! check_extension "$1" && shared_extension "$1"; then
|
|
||||||
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
|
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,18 @@ self_hosted_helper() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Disable dependency extensions
|
||||||
|
disable_dependency_extensions() {
|
||||||
|
local extension=$1
|
||||||
|
formula_file="$tap_dir/$ext_tap/Formula/$extension@${version:?}.rb"
|
||||||
|
if [ -e "$formula_file" ]; then
|
||||||
|
IFS=" " read -r -a dependency_extensions <<< "$(grep -Eo "shivammathur.*@" "$formula_file" | xargs -I {} -n 1 basename '{}' | cut -d '@' -f 1 | tr '\n' ' ')"
|
||||||
|
for dependency_extension in "${dependency_extensions[@]}"; do
|
||||||
|
sudo sed -Ei '' "/=(.*\/)?\"?$dependency_extension(.so)?$/d" "${ini_file:?}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Helper function to disable an extension.
|
# Helper function to disable an extension.
|
||||||
disable_extension_helper() {
|
disable_extension_helper() {
|
||||||
local extension=$1
|
local extension=$1
|
||||||
@ -49,15 +61,16 @@ add_brew_tap() {
|
|||||||
add_brew_extension() {
|
add_brew_extension() {
|
||||||
formula=$1
|
formula=$1
|
||||||
prefix=$2
|
prefix=$2
|
||||||
extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")"
|
shared_extension "$formula" && extension="$formula" || extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")"
|
||||||
enable_extension "$extension" "$prefix"
|
enable_extension "$extension" "$prefix"
|
||||||
if check_extension "$extension"; then
|
if check_extension "$extension"; then
|
||||||
add_log "${tick:?}" "$extension" "Enabled"
|
add_log "${tick:?}" "$extension" "Enabled"
|
||||||
else
|
else
|
||||||
add_brew_tap shivammathur/homebrew-php
|
add_brew_tap "$php_tap"
|
||||||
add_brew_tap shivammathur/homebrew-extensions
|
add_brew_tap "$ext_tap"
|
||||||
sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$formula"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
|
sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
|
||||||
update_dependencies >/dev/null 2>&1
|
update_dependencies >/dev/null 2>&1
|
||||||
|
disable_dependency_extensions "$extension" >/dev/null 2>&1
|
||||||
brew install -f "$formula@$version" >/dev/null 2>&1
|
brew install -f "$formula@$version" >/dev/null 2>&1
|
||||||
sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir"
|
sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir"
|
||||||
add_extension_log "$extension" "Installed and enabled"
|
add_extension_log "$extension" "Installed and enabled"
|
||||||
@ -129,7 +142,7 @@ update_dependencies() {
|
|||||||
while read -r dependency; do
|
while read -r dependency; do
|
||||||
update_dependencies_helper "$dependency" &
|
update_dependencies_helper "$dependency" &
|
||||||
to_wait+=($!)
|
to_wait+=($!)
|
||||||
done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}"
|
done <"$tap_dir/$php_tap/.github/deps/${ImageOS:?}_${ImageVersion:?}"
|
||||||
wait "${to_wait[@]}"
|
wait "${to_wait[@]}"
|
||||||
echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1
|
echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
@ -160,7 +173,7 @@ get_brewed_php() {
|
|||||||
add_php() {
|
add_php() {
|
||||||
action=$1
|
action=$1
|
||||||
existing_version=$2
|
existing_version=$2
|
||||||
add_brew_tap shivammathur/homebrew-php
|
add_brew_tap "$php_tap"
|
||||||
update_dependencies
|
update_dependencies
|
||||||
if [ "$existing_version" != "false" ]; then
|
if [ "$existing_version" != "false" ]; then
|
||||||
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula"
|
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula"
|
||||||
@ -172,8 +185,8 @@ add_php() {
|
|||||||
|
|
||||||
# Function to get extra version.
|
# Function to get extra version.
|
||||||
php_extra_version() {
|
php_extra_version() {
|
||||||
php_formula_file="$tap_dir"/shivammathur/homebrew-php/Formula/php@"$version".rb
|
php_formula_file="$tap_dir"/"$php_tap"/Formula/php@"$version".rb
|
||||||
if [ -e "$php_formula_file" ] && ! grep -q "deprecate!" $php_formula_file && grep -Eq "archive/[0-9a-zA-Z]+" "$php_formula_file"; then
|
if [ -e "$php_formula_file" ] && ! grep -q "deprecate!" "$php_formula_file" && grep -Eq "archive/[0-9a-zA-Z]+" "$php_formula_file"; then
|
||||||
echo " ($(grep -Eo "archive/[0-9a-zA-Z]+" "$php_formula_file" | cut -d'/' -f 2))"
|
echo " ($(grep -Eo "archive/[0-9a-zA-Z]+" "$php_formula_file" | cut -d'/' -f 2))"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -221,6 +234,8 @@ brew_prefix="$(brew --prefix)"
|
|||||||
brew_repo="$(brew --repository)"
|
brew_repo="$(brew --repository)"
|
||||||
tap_dir="$brew_repo"/Library/Taps
|
tap_dir="$brew_repo"/Library/Taps
|
||||||
scripts="${dist}"/../src/scripts
|
scripts="${dist}"/../src/scripts
|
||||||
|
ext_tap=shivammathur/homebrew-extensions
|
||||||
|
php_tap=shivammathur/homebrew-php
|
||||||
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
||||||
export HOMEBREW_DEVELOPER=1
|
export HOMEBREW_DEVELOPER=1
|
||||||
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
||||||
|
Loading…
Reference in New Issue
Block a user