Refactor and improve extension support

Add support for APCu on macOS from shivammathur/homebrew-extensions
Improve support for geos to compile on PHP 8.0 and 8.1
Fix pecl setup to avoid unnecessary callbacks
Use GitHub releases for all couchbase versions
Use add_extension_from_source for all custom supported extensions
Remove bintray and use shivammathur/intl-icu releases
Add patch for protobuf for installing from source
Move patches from custom extension scripts to patches directory
Add support to build extension from GitHub and pecl tar archives (Internal API)
Refactor regex in extension.ts
Move add_pecl_extension to common.sh
Refactor remove_extension in darwin.sh
Fix shellcheck warning in darwin.sh
Improve switch_version in linux.sh to accept parameters
This commit is contained in:
Shivam Mathur
2021-04-15 16:54:35 +05:30
parent 7c13389546
commit ada1ce86b7
19 changed files with 301 additions and 349 deletions
+84 -25
View File
@@ -1,11 +1,12 @@
# Function to parse extension environment variables
parse_args() {
extension=$1
suffix=$2
up_extension=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
suffix=$(echo "$2" | tr '[:lower:]' '[:upper:]')
up_ext_name=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
var="${extension}_${suffix}"
up_var="${up_extension}_${suffix}"
output=$(echo "${!var} ${!up_var}" | sed "s/, */ /g")
up_var="${up_ext_name}_${suffix}"
! [[ "$suffix" =~ .*PREFIX|LIBS.* ]] && hyp='-'
output=$(echo "${!var} ${!up_var}" | sed "s/, *$hyp/ $hyp/g" | sed -E "s/^,|,$//g")
echo "$output" | xargs -n 1 | sort | uniq | xargs
}
@@ -20,16 +21,45 @@ add_lib_log() {
fi
}
# Function to check if a library is installed
check_lib() {
lib=$1
if [ "$(uname -s)" = "Linux" ]; then
[ "x$(dpkg -s "$lib" 2>/dev/null | grep Status)" != "x" ]
else
[ "x$(find "${brew_prefix:?}"/Cellar -maxdepth 1 -name "$lib")" != "x" ]
fi
}
# Function to add a library on linux
add_linux_libs() {
lib=$1
if ! check_lib "$lib"; then
install_packages "$lib" >/dev/null 2>&1 || true
fi
add_lib_log "$lib"
}
# Function to add a library on macOS
add_darwin_libs() {
lib=$1
if ! check_lib "$lib"; then
brew install "$lib" >/dev/null 2>&1 || true
if [[ "$lib" = *@* ]]; then
brew link --overwrite --force "$lib" >/dev/null 2>&1 || true
fi
fi
add_lib_log "$lib"
}
# Function to add required libraries
add_libs() {
libs=("$@")
for lib in "${libs[@]}"; do
all_libs=("$@")
for lib in "${all_libs[@]}"; do
if [ "$(uname -s)" = "Linux" ]; then
install_packages "$lib" >/dev/null 2>&1
add_lib_log "$lib" "$(dpkg -s "$lib" 2>/dev/null | grep Status)"
add_linux_libs "$lib"
else
brew install "$lib" >/dev/null 2>&1
add_lib_log "$lib" "$(find "${brew_cellar:?}" -maxdepth 1 -name "$lib")"
add_darwin_libs "$lib"
fi
done
}
@@ -45,36 +75,65 @@ run_group() {
echo "::endgroup::"
}
patch_extension() {
extension=$1
if [ -e "${scripts:?}"/ext/patches/"$extension".sh ]; then
# shellcheck source=.
. "${scripts:?}"/ext/patches/"$extension".sh
patch_"${extension}"
fi
}
fetch_extension() {
fetch=$1
if [ "$fetch" = "clone" ]; then
run_group "git clone -nv $url/$org/$repo /tmp/$repo-$release" "git clone"
cd /tmp/"$repo-$release" || exit 1
git checkout -q "$release"
cd "$sub_dir" || exit 1
if [ -e .gitmodules ]; then
jobs="$(grep -c "\[submodule" .gitmodules)"
run_group "git submodule update --jobs $jobs --init --recursive" "git submodule"
fi
elif [ "$fetch" = "get" ]; then
get -q -n /tmp/"$extension".tar.gz "$url/$org/$repo/archive/$release.tar.gz"
tar -xzf /tmp/"$extension".tar.gz -C /tmp
cd /tmp/"$repo"-"$release"/"$sub_dir" || exit
elif [ "$fetch" = "pecl" ]; then
source="pecl"
pecl_name=${extension/http/pecl_http}
get -q -n /tmp/"$pecl_name".tgz https://pecl.php.net/get/"$pecl_name"-"$release".tgz
tar -xzf /tmp/"$pecl_name".tgz -C /tmp
cd /tmp/"$pecl_name"-"$release" || exit
fi
}
# Function to install extension from a git repository
add_extension_from_source() {
extension=$1
domain=$2
extension="${1/pecl_/}"
url=$2
org=$3
repo=$4
sub_dir=$5
release=$6
prefix=$7
fetch=${8:-clone}
slug="$extension-$release"
libraries="$(parse_args "$extension" LIBS)"
source="$url/$org/$repo"
libraries="$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
opts="$(parse_args "$extension" CONFIGURE_OPTS)"
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
suffix_opts="$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
step_log "Setup $slug"
(
add_devtools phpize >/dev/null
add_devtools phpize >/dev/null 2>&1
delete_extension "$extension"
run_group "git clone -nv $domain/$org/$repo /tmp/$repo-$release" "git clone"
cd /tmp/"$repo-$release" || exit 1
git checkout -q "$release"
cd $sub_dir || exit 1
fetch_extension "$fetch"
if ! [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \; | wc -l)" != "0" ]; then
add_log "${cross:?}" "$domain/$org/$repo" "$domain/$org/$repo does not have a PHP extension"
add_log "${cross:?}" "$source" "$source does not have a PHP extension"
else
if [ -e .gitmodules ]; then
jobs="$(grep -c "\[submodule" .gitmodules)"
run_group "git submodule update --jobs $jobs --init --recursive" "git submodule"
fi
[ "x$libraries" != "x" ] && run_group "add_libs $libraries" "add libraries"
[[ -n "${libraries// }" ]] && run_group "add_libs $libraries" "add libraries"
patch_extension "$extension" >/dev/null 2>&1
run_group "phpize" "phpize"
run_group "sudo $prefix_opts ./configure $suffix_opts $opts" "configure"
run_group "sudo make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)" "make"
@@ -82,5 +141,5 @@ add_extension_from_source() {
enable_extension "$extension" "$prefix"
fi
)
add_extension_log "$slug" "Installed from $domain/$org/$repo and enabled"
add_extension_log "$slug" "Installed from $source and enabled"
}