Add a new src_prepare phase function which is called in-between src_unpack
[portage.git] / bin / ebuild.sh
index 2a434ef7583b36446e63b9ad393fe1c3c683a402..e45747d02a1583054319e1f709ff584ee512c74d 100755 (executable)
@@ -726,7 +726,7 @@ dyn_clean() {
        fi
 
        if ! hasq keepwork $FEATURES; then
-               rm -f "$PORTAGE_BUILDDIR"/.{exit_status,logid,unpacked} \
+               rm -f "$PORTAGE_BUILDDIR"/.{exit_status,logid,unpacked,prepared} \
                        "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged}
 
                rm -rf "${PORTAGE_BUILDDIR}/build-info"
@@ -832,6 +832,12 @@ abort_handler() {
        trap SIGINT SIGQUIT
 }
 
+abort_prepare() {
+       abort_handler src_prepare $1
+       rm -f "$PORTAGE_BUILDDIR/.prepared"
+       exit 1
+}
+
 abort_configure() {
        abort_handler src_configure $1
        rm -f "$PORTAGE_BUILDDIR/.configured"
@@ -856,6 +862,32 @@ abort_install() {
        exit 1
 }
 
+dyn_prepare() {
+
+       if [[ $PORTAGE_BUILDDIR/.prepared -nt $WORKDIR ]] ; then
+               vecho ">>> It appears that '$PF' is already prepared; skipping."
+               vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
+               return 0
+       fi
+
+       local srcdir
+       if [[ -d $S ]] ; then
+               srcdir=$S
+       else
+               srcdir=$WORKDIR
+       fi
+       cd "$srcdir"
+
+       trap abort_prepare SIGINT SIGQUIT
+
+       ebuild_phase pre_src_prepare
+       ebuild_phase src_prepare
+       touch "$PORTAGE_BUILDDIR"/.prepared
+       ebuild_phase post_src_prepare
+
+       trap SIGINT SIGQUIT
+}
+
 dyn_configure() {
 
        if [[ $PORTAGE_BUILDDIR/.configured -nt $WORKDIR ]] ; then
@@ -1038,7 +1070,8 @@ dyn_help() {
        echo "  fetch       : download source archive(s) and patches"
        echo "  digest      : create a manifest file for the package"
        echo "  manifest    : create a manifest file for the package"
-       echo "  unpack      : unpack/patch sources (auto-fetch if needed)"
+       echo "  unpack      : unpack sources (auto-dependencies if needed)"
+       echo "  prepare     : prepare sources (auto-dependencies if needed)"
        echo "  configure   : configure sources (auto-fetch/unpack if needed)"
        echo "  compile     : compile sources (auto-fetch/unpack/configure if needed)"
        echo "  test        : test package (auto-fetch/unpack/configure/compile if needed)"
@@ -1387,7 +1420,7 @@ _ebuild_phase_funcs() {
        [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
        local eapi=$1
        local phase_func=$2
-       local default_phases="pkg_nofetch src_unpack src_configure
+       local default_phases="pkg_nofetch src_unpack src_prepare src_configure
                src_compile src_install src_test"
        local x y default_func=""
 
@@ -1440,6 +1473,7 @@ _ebuild_phase_funcs() {
 
                                eapi0_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
                                eapi0_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi0_src_prepare   () { die "$FUNCNAME is not supported" ; }
                                eapi0_src_configure () { die "$FUNCNAME is not supported" ; }
                                eapi0_src_compile   () { _eapi0_src_compile   "$@" ; }
                                eapi0_src_test      () { _eapi0_src_test      "$@" ; }
@@ -1447,6 +1481,7 @@ _ebuild_phase_funcs() {
 
                                eapi1_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
                                eapi1_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi1_src_prepare   () { die "$FUNCNAME is not supported" ; }
                                eapi1_src_configure () { die "$FUNCNAME is not supported" ; }
                                eapi1_src_compile   () { _eapi1_src_compile   "$@" ; }
                                eapi1_src_test      () { _eapi0_src_test      "$@" ; }
@@ -1454,6 +1489,7 @@ _ebuild_phase_funcs() {
 
                                eapi2_pkg_nofetch   () { _eapi0_pkg_nofetch   "$@" ; }
                                eapi2_src_unpack    () { _eapi0_src_unpack    "$@" ; }
+                               eapi2_src_prepare   () { true ; }
                                eapi2_src_configure () { _eapi2_src_configure "$@" ; }
                                eapi2_src_compile   () { _eapi2_src_compile   "$@" ; }
                                eapi2_src_test      () { _eapi0_src_test      "$@" ; }
@@ -1945,7 +1981,7 @@ ebuild_main() {
                                | bzip2 -c -f9 > "$PORTAGE_UPDATE_ENV"
                fi
                ;;
-       unpack|configure|compile|test|clean|install)
+       unpack|prepare|configure|compile|test|clean|install)
                if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
                        export SANDBOX_ON="1"
                else