Skip to content

Commit

Permalink
Add support for zts and debug extensions on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 25, 2023
1 parent 201dd6c commit 8123608
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/scripts/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,41 @@ add_brew_extension() {
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
brew_opts=(-f)
add_brew_tap "$php_tap"
add_brew_tap "$ext_tap"
if [ "${ts:?}" = "zts" ]; then
brew_opts=(-sf)
suffix="$(get_php_formula_suffix)"
abstract_path="$tap_dir"/"$ext_tap"/Abstract/abstract-php-extension.rb
if [ -f "$abstract_path" ]; then
grep -q zts "$abstract_path" || sed -i '' "s/php@${version}/php@${version}$suffix/" "$abstract_path"
fi
fi
sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "${core_repo:?}/Formula/" 2>/dev/null || true
update_dependencies >/dev/null 2>&1
disable_dependency_extensions "$extension" >/dev/null 2>&1
handle_dependency_extensions_for_suffix >/dev/null 2>&1
(brew install "${brew_opts[@]}" "$ext_tap/$formula@$version" >/dev/null 2>&1 && copy_brew_extensions "$formula") || pecl_install "$extension" >/dev/null 2>&1
add_extension_log "$extension" "Installed and enabled"
fi
}

# Install dependency extensions if the PHP version is ZTS or Debug.
handle_dependency_extensions_for_suffix() {
suffix="$(get_php_formula_suffix)"
if [[ -n "$suffix" ]]; then
brew_opts=(-sf)
patch_abstract_file >/dev/null 2>&1
dependency_extensions=()
while IFS= read -r dependency_extension; do
dependency_extensions+=("$dependency_extension")
done < <(grep -E "depends_on.*shivammathur/extensions" "$formula_file" | sed -E 's/.*\/([^@]+)@.*/\1/')
for dependency_extension in "${dependency_extensions[@]}"; do
brew install "${brew_opts[@]}" "$ext_tap/$dependency_extension@$version" >/dev/null 2>&1 && copy_brew_extensions "$dependency_extension"
done
fi
}

# Function to patch the abstract file in the extensions tap.
patch_abstract_file() {
abstract_path="$tap_dir"/"$ext_tap"/Abstract/abstract-php-extension.rb
if [ -e "$abstract_path" ] && ! grep -q "$suffix" "$abstract_path"; then
sudo sed -i '' -e "s|php@#{\(.*\)}|php@#{\1}$suffix|g" -e "s|php_version /|\"#{php_version}$suffix\" /|g" "$abstract_path"
fi
}

# Helper function to add an extension.
add_extension_helper() {
local extension=$1
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/tools/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ configure_brew() {
add_brew
brew_path="$(command -v brew)"
fi
brew_opts=(-f)
brew_path_dir="$(dirname "$brew_path")"
brew_prefix="$brew_path_dir"/..
brew_repo="$brew_path_dir/$(dirname "$(readlink "$brew_path")")"/..
Expand All @@ -74,6 +75,7 @@ configure_brew() {
export HOMEBREW_NO_ENV_HINTS=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
export brew_opts
export brew_path
export brew_path_dir
export brew_prefix
Expand Down

0 comments on commit 8123608

Please sign in to comment.