dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / php-ext-source-r3.eclass
index 3372a4b8347084c7a246cedfa670a585e9fc362e..12e4a24facd61ce9d23fa0553dff6324a72800ab 100644 (file)
@@ -1,10 +1,10 @@
-# Copyright 1999-2016 Gentoo Foundation
+# Copyright 1999-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
-# $Id$
 
 # @ECLASS: php-ext-source-r3.eclass
 # @MAINTAINER:
 # Gentoo PHP team <php-bugs@gentoo.org>
+# @SUPPORTED_EAPIS: 6 7
 # @BLURB: Compile and install standalone PHP extensions.
 # @DESCRIPTION:
 # A unified interface for compiling and installing standalone PHP
 
 inherit autotools
 
-EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
+EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
 
-case ${EAPI} in
-       6) ;;
+case ${EAPI:-0} in
+       6) inherit eapi7-ver ;;
+       7) ;;
        *)
                die "${ECLASS} is not compatible with EAPI=${EAPI}"
 esac
@@ -74,11 +75,39 @@ esac
 # the tree.
 [[ -z "${PHP_EXT_SAPIS}" ]] && PHP_EXT_SAPIS="apache2 cli cgi fpm embed phpdbg"
 
+# @ECLASS-VARIABLE: PHP_INI_NAME
+# @DESCRIPTION:
+# An optional file name of the saved ini file minis the ini extension
+# This allows ordering of extensions such that one is loaded before
+# or after another.  Defaults to the PHP_EXT_NAME.
+# Example (produces 40-foo.ini file):
+# @CODE@
+# PHP_INI_NAME="40-foo"
+# @CODE@
+: ${PHP_INI_NAME:=${PHP_EXT_NAME}}
+
+# @ECLASS-VARIABLE: PHP_EXT_NEEDED_USE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# A list of USE flags to append to each PHP target selected
+# as a valid USE-dependency string.  The value should be valid
+# for all targets so USE defaults may be necessary.
+# Example:
+# @CODE
+# PHP_EXT_NEEDED_USE="mysql?,pdo,pcre(+)"
+# @CODE
+#
+# The PHP dependencies will result in:
+# @CODE
+# php_targets_php7-0? ( dev-lang/php:7.0[mysql?,pdo,pcre(+)] )
+# @CODE
+
 
 # Make sure at least one target is installed. First, start a USE
 # conditional like "php?", but only when PHP_EXT_OPTIONAL_USE is
 # non-null. The option group "|| (..." is always started here.
 REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
+PHPDEPEND="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( } "
 for _php_target in ${USE_PHP}; do
        # Now loop through each USE_PHP target and add the corresponding
        # dev-lang/php slot to PHPDEPEND.
@@ -86,6 +115,9 @@ for _php_target in ${USE_PHP}; do
        REQUIRED_USE+="php_targets_${_php_target} "
        _php_slot=${_php_target/php}
        _php_slot=${_php_slot/-/.}
+       if [[ ${PHP_EXT_NEEDED_USE} ]] ; then
+               _php_slot+=[${PHP_EXT_NEEDED_USE}]
+       fi
        PHPDEPEND+=" php_targets_${_php_target}? ( dev-lang/php:${_php_slot} )"
 done
 
@@ -95,50 +127,48 @@ unset _php_slot _php_target
 # Finally, end the optional group that we started before the loop. Close
 # the USE-conditional if PHP_EXT_OPTIONAL_USE is non-null.
 REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
+PHPDEPEND+=" ${PHP_EXT_OPTIONAL_USE:+ )}"
+TOOLDEPS="sys-devel/m4 sys-devel/libtool"
 
-RDEPEND="${RDEPEND}
-       ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
-       ${PHPDEPEND}
-       ${PHP_EXT_OPTIONAL_USE:+ )}"
+RDEPEND="${PHPDEPEND}"
 
-DEPEND="${DEPEND}
-       sys-devel/m4
-       sys-devel/libtool
-       ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
-       ${PHPDEPEND}
-       ${PHP_EXT_OPTIONAL_USE:+ )}
-"
+case ${EAPI:-0} in
+       6) DEPEND="${TOOLDEPS} ${PHPDEPEND}" ;;
+       7) DEPEND="${PHPDEPEND}" ; BDEPEND="${TOOLDEPS} ${PHPDEPEND}" ;;
+esac
+
+unset PHPDEPEND TOOLDEPS
 
 # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
-# By default, we run "phpize" in php-ext-source-r3_src_unpack(). Set
+# By default, we run "phpize" in php-ext-source-r3_src_prepare(). Set
 # PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run
 # phpize (and the autoreconf that becomes necessary afterwards).
 
-# @FUNCTION: php-ext-source-r3_src_unpack
+# @ECLASS-VARIABLE: PHP_EXT_SKIP_PATCHES
+# @DEFAULT_UNSET
 # @DESCRIPTION:
-# Runs the default src_unpack and then makes a copy for each PHP slot.
-php-ext-source-r3_src_unpack() {
-       default
-
-       local slot orig_s="${PHP_EXT_S}"
-       for slot in $(php_get_slots); do
-               cp --recursive --preserve "${orig_s}" "${WORKDIR}/${slot}" || \
-                       die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}"
-       done
-}
-
+# By default, we run default_src_prepare to PHP_EXT_S.
+# Set PHP_EXT_SKIP_PATCHES="yes" in your ebuild if you
+# want to apply patches yourself.
 
 # @FUNCTION: php-ext-source-r3_src_prepare
 # @DESCRIPTION:
-# For each PHP slot, we initialize the environment, run the default
-# src_prepare() for PATCHES/eapply_user support, and then call
-# php-ext-source-r3_phpize.
+# Runs the default src_prepare() for PATCHES/eapply_user() support (optional),
+# and for each PHP slot, makes a copy of sources, initializes the environment,
+# and calls php-ext-source-r3_phpize().
 php-ext-source-r3_src_prepare() {
+       local slot orig_s="${PHP_EXT_S}"
+       if [[ "${PHP_EXT_SKIP_PATCHES}" != 'yes' ]] ; then
+               pushd "${orig_s}" > /dev/null || die
+               default
+               popd > /dev/null || die
+       fi
        for slot in $(php_get_slots); do
+               cp --recursive --preserve "${orig_s}" "${WORKDIR}/${slot}" || \
+                       die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}"
                php_init_slot_env "${slot}"
-               default
                php-ext-source-r3_phpize
        done
 }
@@ -154,10 +184,18 @@ php-ext-source-r3_phpize() {
                # WANT_AUTOMAKE (see bugs #329071 and #549268).
                autotools_run_tool "${PHPIZE}"
 
-               # Force libtoolize to run and regenerate autotools files (bug
-               # #220519).
-               rm aclocal.m4 || die "failed to remove aclocal.m4"
-               eautoreconf
+               # PHP >=7.4 no longer works with eautoreconf
+               if ver_test $PHP_CURRENTSLOT -ge 7.4 ; then
+                       rm -fr aclocal.m4 autom4te.cache config.cache \
+                               configure main/php_config.h.in || die
+                       eautoconf --force
+                       eautoheader
+               else
+                       # Force libtoolize to run and regenerate autotools files (bug
+                       # #220519).
+                       rm aclocal.m4 || die "failed to remove aclocal.m4"
+                       eautoreconf
+               fi
        fi
 }
 
@@ -179,7 +217,7 @@ php-ext-source-r3_src_configure() {
 
        # Support either a string or an array for PHP_EXT_ECONF_ARGS.
        local econf_args
-       if [[ $(declare -p PHP_EXT_ECONF_ARGS) == "declare -a"* ]]; then
+       if [[ -n "${PHP_EXT_ECONF_ARGS}" && $(declare -p PHP_EXT_ECONF_ARGS) == "declare -a"* ]]; then
                econf_args=( "${PHP_EXT_ECONF_ARGS[@]}" )
        else
                econf_args=( ${PHP_EXT_ECONF_ARGS} )
@@ -230,6 +268,19 @@ php-ext-source-r3_src_install() {
        php-ext-source-r3_createinifiles
 }
 
+# @FUNCTION: php-ext-source-r3_src_test
+# @DESCRIPTION:
+# Run tests delivered with the standalone PHP extension. Phpize will have generated
+# a run-tests.php file to be executed by `make test`. We only need to
+# force the test suite to run in non-interactive mode.
+php-ext-source-r3_src_test() {
+       local slot
+       for slot in $(php_get_slots); do
+               php_init_slot_env "${slot}"
+               NO_INTERACTION="yes" emake test
+       done
+}
+
 # @FUNCTION: php_get_slots
 # @DESCRIPTION:
 # Get a list of PHP slots contained in both the ebuild's USE_PHP and the
@@ -283,7 +334,7 @@ php_slot_ini_files() {
        local x
        for x in ${PHP_EXT_SAPIS} ; do
                if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
-                       slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
+                       slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_INI_NAME}.ini"
                fi
        done
 
@@ -312,10 +363,10 @@ php-ext-source-r3_createinifiles() {
                                einfo "Added contents of ${FILESDIR}/${PHP_EXT_INIFILE}" \
                                          "to ${file}"
                        fi
-                       inidir="${file/${PHP_EXT_NAME}.ini/}"
+                       inidir="${file/${PHP_INI_NAME}.ini/}"
                        inidir="${inidir/ext/ext-active}"
                        dodir "/${inidir}"
-                       dosym "/${file}" "/${file/ext/ext-active}"
+                       dosym "../ext/${PHP_INI_NAME}.ini" "/${file/ext/ext-active}"
                done
        done