Since axxo is being a slacker (:-P) and hasn't posted this, did a 
quicky implentation for stable ebuild.sh of pre/post phase hooks.

The intention of these hooks are for users to define funcs in their 
/etc/portage/bashrc; the phase to be hooked, say pkg_setup , is hooked 
via

echo $'
pre_pkg_setup() { echo "I am called prior to pkg_setup"; }
post_pkg_setup() { echo "I am called after pkg_setup"; }
' >> /etc/portage/bashrc

for example.
setup, unpack, compile, test, install, preinst, postinst, prerm, 
postrm, and config via this patch have pre/post hooks.

This hooking approach is preferred to just sticking stuff in bashrc 
and having it detect the phase- reasoning is that the bashrc will be 
sourced once, and only once when ebd is default.

So... it's in users interests to convert over to this setup sooner 
rather then later.

Note also, that these hooks aren't phase additions- ebuilds/eclasses 
are not to touch them (this will be enforced under ebd also).

That said, their will be an exemption for java ebuilds due to the fact 
that they're blocked by ebuild.sh env handling- they need ebd for 
things to work properly, and in the meantime this gives them a method 
to have things work properly.  Downside is that the pre/post hooks are 
not available for users for java ebuilds.

Either way, play with it, feedback would be appreciated.
~harring
Index: ebuild.sh
===================================================================
--- ebuild.sh   (revision 2122)
+++ ebuild.sh   (working copy)
@@ -631,11 +631,14 @@
 
 dyn_setup()
 {
+       [ "$(type -t pre_pkg_setup)" != "file" ] && pre_pkg_setup
        pkg_setup
+       [ "$(type -t post_pkg_setup)" != "file" ] && post_pkg_setup
 }
 
 dyn_unpack() {
        trap "abort_unpack" SIGINT SIGQUIT
+       [ "$(type -t pre_src_unpack)" != "file" ] && pre_src_unpack
        local newstuff="no"
        if [ -e "${WORKDIR}" ]; then
                local x
@@ -662,6 +665,7 @@
        if [ -e "${WORKDIR}" ]; then
                if [ "$newstuff" == "no" ]; then
                        echo ">>> WORKDIR is up-to-date, keeping..."
+                       [ "$(type -t post_src_unpack)" != "file" ] && 
post_src_unpack
                        return 0
                fi
        fi
@@ -673,6 +677,9 @@
        touch "${BUILDDIR}/.unpacked" || die "IO Failure -- Failed 'touch 
.unpacked' in BUILDIR"
        echo ">>> Source unpacked."
        cd "$BUILDDIR"
+
+       [ "$(type -t post_src_unpack)" != "file" ] && post_src_unpack
+
        trap SIGINT SIGQUIT
 }
 
@@ -854,6 +861,9 @@
 
 dyn_compile() {
        trap "abort_compile" SIGINT SIGQUIT
+
+       [ "$(type -t pre_src_compile)" != "file" ] && pre_src_compile
+
        [ "${CFLAGS-unset}"      != "unset" ] && export CFLAGS
        [ "${CXXFLAGS-unset}"    != "unset" ] && export CXXFLAGS
        [ "${LIBCFLAGS-unset}"   != "unset" ] && export LIBCFLAGS
@@ -892,6 +902,7 @@
                echo ">>> It appears that ${PN} is already compiled; skipping."
                echo ">>> (clean to force compilation)"
                trap SIGINT SIGQUIT
+               [ "$(type -t post_src_compile)" != "file" ] && post_src_compile
                return
        fi
        if [ -d "${S}" ]; then
@@ -948,6 +959,9 @@
        if hasq nostrip $FEATURES $RESTRICT; then
                touch DEBUGBUILD
        fi
+
+       [ "$(type -t post_src_compile)" != "file" ] && post_src_compile
+
        trap SIGINT SIGQUIT
 }
 
@@ -972,8 +986,10 @@
 
 
 dyn_test() {
+       [ "$(type -t pre_src_test)" != "file" ] && pre_src_test
        if [ ${BUILDDIR}/.tested -nt "${WORKDIR}" ]; then
                echo ">>> It appears that ${PN} has already been tested; 
skipping."
+               [ "$(type -t post_src_test)" != "file" ] && post_src_test
                return
        fi
        trap "abort_test" SIGINT SIGQUIT
@@ -992,6 +1008,7 @@
 
        cd "${BUILDDIR}"
        touch .tested || die "Failed to 'touch .tested' in ${BUILDDIR}"
+       [ "$(type -t post_src_test)" != "file" ] && post_src_test
        trap SIGINT SIGQUIT
 }
        
@@ -1001,6 +1018,7 @@
 
 dyn_install() {
        trap "abort_install" SIGINT SIGQUIT
+       [ "$(type -t pre_src_install)" != "file" ] && pre_src_install
        rm -rf "${BUILDDIR}/image"
        mkdir "${BUILDDIR}/image"
        if [ -d "${S}" ]; then
@@ -1204,6 +1222,7 @@
        echo ">>> Completed installing ${PF} into ${D}"
        echo
        cd ${BUILDDIR}
+       [ "$(type -t post_src_install)" != "file" ] && post_src_install
        trap SIGINT SIGQUIT
 }
 
@@ -1211,6 +1230,8 @@
        # set IMAGE depending if this is a binary or compile merge
        [ "${EMERGE_FROM}" == "binary" ] && IMAGE=${PKG_TMPDIR}/${PF}/bin \
                                        || IMAGE=${D}
+       
+       [ "$(type -t pre_pkg_preinst)" != "file" ] && pre_pkg_preinst
 
        pkg_preinst
 
@@ -1319,6 +1340,9 @@
                        echo "!!! Unable to set SELinux security labels"
                fi
        fi
+
+       [ "$(type -t post_pkg_preinst)" != "file" ] && post_pkg_preinst
+
        trap SIGINT SIGQUIT
 }
 
@@ -1845,11 +1869,15 @@
        prerm|postrm|postinst|config)
                export SANDBOX_ON="0"
                if [ "$PORTAGE_DEBUG" != "1" ]; then
+                       [ "$(type -t pre_pkg_${myarg})" != "file" ] && 
pre_pkg_${myarg}
                        pkg_${myarg}
+                       [ "$(type -t post_pkg_${myarg})" != "file" ] && 
post_pkg_${myarg}
                        #Allow non-zero return codes since they can be caused 
by &&
                else
                        set -x
+                       [ "$(type -t pre_pkg_${myarg})" != "file" ] && 
pre_pkg_${myarg}
                        pkg_${myarg}
+                       [ "$(type -t post_pkg_${myarg})" != "file" ] && 
post_pkg_${myarg}
                        #Allow non-zero return codes since they can be caused 
by &&
                        set +x
                fi

Attachment: pgpbwGshAR3PH.pgp
Description: PGP signature

Reply via email to