Implement eapi$EAPI_* default phase functions that are equivalent to the
authorZac Medico <zmedico@gentoo.org>
Fri, 8 Aug 2008 11:24:31 +0000 (11:24 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 8 Aug 2008 11:24:31 +0000 (11:24 -0000)
default_* functions for the given EAPI. For example, a function named
eapi0_src_compile provides access to the default src_compile implementation
that EAPI 0 provides. This feature is supported only when EAPI=2_pre2 is set.
Thanks to Brian Harring for suggesting this idea.

svn path=/main/trunk/; revision=11350

bin/ebuild.sh
bin/isolated-functions.sh

index 6cd69b7e208e872fbe36b9e4b84b9950a92147d8..734dd0ad637b6956b6c6e5e3c3d0e1cb172e0441 100755 (executable)
@@ -583,7 +583,7 @@ einstall() {
        fi
 }
 
-_default_pkg_nofetch() {
+_eapi0_pkg_nofetch() {
        [ -z "${SRC_URI}" ] && return
 
        echo "!!! The following are listed in SRC_URI for ${PN}:"
@@ -593,25 +593,18 @@ _default_pkg_nofetch() {
        done
 }
 
-_default_src_unpack() {
+_eapi0_src_unpack() {
        [[ -n ${A} ]] && unpack ${A}
 }
 
-_default_src_configure() {
-       if [ "${EAPI:-0}" == 0 ] ; then
-               [ -x ./configure ] && econf
-       elif [ -x "${ECONF_SOURCE:-.}/configure" ] ; then
+_eapi0_src_compile() {
+       if [ -x ./configure ] ; then
                econf
        fi
+       _eapi2_src_compile
 }
 
-_default_src_compile() {
-       if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
-               emake || die "emake failed"
-       fi
-}
-
-_default_src_test() {
+_eapi0_src_test() {
        if emake -j1 check -n &> /dev/null; then
                vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
                if ! emake -j1 check; then
@@ -629,23 +622,35 @@ _default_src_test() {
        fi
 }
 
-pkg_nofetch() {
-       _default_pkg_nofetch
+_eapi1_src_compile() {
+       if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
+               econf
+       fi
+       _eapi2_src_compile
 }
 
-src_unpack() {
-       _default_src_unpack
+_eapi2_src_configure() {
+       if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
+               econf
+       fi
 }
 
-src_compile() {
-       hasq "$EAPI" 0 1 2_pre1 && \
-               _default_src_configure
+_eapi2_src_compile() {
+       if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
+               emake || die "emake failed"
+       fi
+}
+
+pkg_nofetch() {
+       _eapi0_pkg_nofetch
+}
 
-       _default_src_compile
+src_unpack() {
+       _eapi0_src_unpack
 }
 
 src_test() {
-       _default_src_test
+       _eapi0_src_test
 }
 
 ebuild_phase() {
@@ -1402,57 +1407,105 @@ _ebuild_phase_funcs() {
        [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
        local eapi=$1
        local phase_func=$2
-       local eapi_has_default_fns=$(hasq $eapi 0 1 2_pre1 && echo 0 || echo 1)
        local default_phases="pkg_nofetch src_unpack src_configure
-               src_compile src_test"
-       local x default_func=""
+               src_compile src_install src_test"
+       local x default_func=""
 
-       [[ $eapi_has_default_fns = 1 ]] && \
-       hasq $phase_func $default_phases && \
-               default_func=$phase_func
-
-       if [[ $eapi_has_default_fns = 1 ]] ; then
-
-               if [[ -n $default_func ]] ; then
-
-                       for x in $default_phases ; do
-                               eval "default_$x() { _default_$x \"\$@\" ; }"
-                       done
+       for x in pkg_nofetch src_unpack src_test ; do
+               [[ $(type -t $x) = function ]] || \
+                       eval "$x() { _eapi0_$x "$@" ; }"
+       done
 
-                       [[ $(type -t src_configure) = function ]] || \
-                               src_configure() { _default_src_configure "$@" ; }
+       case $eapi in
 
-                       eval "default() {
-                               _default_$default_func "$@"
-                       }"
+               0|1|2_pre1)
 
-               else
+                       if [[ $(type -t src_compile) != function ]] ; then
+                               case $eapi in
+                                       0)
+                                               src_compile() { _eapi0_src_compile "$@" ; }
+                                               ;;
+                                       *)
+                                               src_compile() { _eapi1_src_compile "$@" ; }
+                                               ;;
+                               esac
+                       fi
 
                        for x in $default_phases ; do
                                eval "default_$x() {
-                                       die \"default_$x() is not supported in phase $default_func\"
+                                       die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
                                }"
+                               for y in 0 1 2_pre1 ; do
+                                       eval "eapi${y}_$x() {
+                                               die \"eapi${y}_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
+                                       }"
+                               done
                        done
 
                        eval "default() {
                                die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
                        }"
 
-               fi
+                       ;;
 
-       else
+               *)
 
-               for x in $default_phases ; do
-                       eval "default_$x() {
-                               die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
-                       }"
-               done
+                       [[ $(type -t src_configure) = function ]] || \
+                               src_configure() { _eapi2_src_configure "$@" ; }
+
+                       [[ $(type -t src_compile) = function ]] || \
+                               src_compile() { _eapi2_src_compile "$@" ; }
+
+                       if hasq $phase_func $default_phases ; then
+
+                               eapi0_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
+                               eapi0_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi0_src_configure () { die "$FUNCNAME is not supported" ; }
+                               eapi0_src_compile   () { _eapi0_src_compile   "$@" ; }
+                               eapi0_src_test      () { _eapi0_src_test      "$@" ; }
+                               eapi0_src_install   () { _eapi0_src_install   "$@" ; }
+
+                               eapi1_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
+                               eapi1_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi1_src_configure () { die "$FUNCNAME is not supported" ; }
+                               eapi1_src_compile   () { _eapi1_src_compile   "$@" ; }
+                               eapi1_src_test      () { _eapi0_src_test      "$@" ; }
+                               eapi1_src_install   () { _eapi0_src_install   "$@" ; }
+
+                               eapi2_pre2_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
+                               eapi2_pre2_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi2_pre2_src_configure () { _eapi2_src_configure "$@" ; }
+                               eapi2_pre2_src_compile   () { _eapi2_src_compile   "$@" ; }
+                               eapi2_pre2_src_test      () { _eapi0_src_test      "$@" ; }
+                               eapi2_pre2_src_install   () { _eapi0_src_install   "$@" ; }
+
+                               for x in $default_phases ; do
+                                       eval "default_$x() { eapi${eapi}_$x \"\$@\" ; }"
+                               done
 
-               default() {
-                       die "default() is not supported with EAPI='$eapi' during phase $phase_func"
-               }
+                               eval "default() { eapi${eapi}_$phase_func \"\$@\" ; }"
 
-       fi
+                       else
+
+                               for x in $default_phases ; do
+                                       eval "default_$x() {
+                                               die \"default_$x() is not supported in phase $default_func\"
+                                       }"
+                                       for y in 0 1 2_pre2 ; do
+                                               eval "eapi${y}_$x() {
+                                                       die \"eapi${y}_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
+                                               }"
+                                       done
+                               done
+
+                               eval "default() {
+                                       die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
+                               }"
+
+                       fi
+
+                       ;;
+       esac
 }
 
 # @FUNCTION: source_all_bashrcs
index 378e03f91dbff250bf0dcaec92b6d9384e81eaf2..85a478e6b0bee88c9e5843d0ee8e0e66728b0f2e 100755 (executable)
@@ -546,7 +546,7 @@ save_ebuild_env() {
                for x in pkg_setup pkg_nofetch src_unpack src_configure \
                        src_compile src_test src_install pkg_preinst pkg_postinst \
                        pkg_prerm pkg_postrm ; do
-                       unset -f {,_}default_$x
+                       unset -f {,_}default_$x {,_}eapi{0,1,2,2_pre1,2_pre2}_$x
                done
                unset x