diff options
author | 2015-07-09 19:16:45 -0400 | |
---|---|---|
committer | 2015-07-09 19:16:45 -0400 | |
commit | 263acdb438bb35003c3a9c2639e2a7ac7598aea0 (patch) | |
tree | ebee26da91da0694c20d517d1c41d1fe90adcf0c | |
parent | setup: minor cleanups (diff) | |
download | pkgcore-263acdb438bb35003c3a9c2639e2a7ac7598aea0.tar.gz pkgcore-263acdb438bb35003c3a9c2639e2a7ac7598aea0.tar.bz2 pkgcore-263acdb438bb35003c3a9c2639e2a7ac7598aea0.zip |
bash: simplify EAPI phase injection
Now all EAPI specific phase functions should be defined in their related
libs using the naming format __phase_$func (e.g. __phase_src_install).
This allows later EAPI definitions to override previous ones and
decreases the complexity for injecting default functions for later
EAPIs.
Also, all __phase_common and __phase_default internal function prefixes
were dropped to just __phase.
-rw-r--r-- | bash/eapi/0.lib | 42 | ||||
-rw-r--r--[l---------] | bash/eapi/1.lib | 14 | ||||
-rw-r--r-- | bash/eapi/2.lib | 12 | ||||
-rw-r--r-- | bash/eapi/4.lib | 4 | ||||
-rw-r--r-- | bash/eapi/common.lib | 81 | ||||
-rw-r--r-- | bash/ebuild-default-functions.lib | 4 | ||||
-rw-r--r-- | bash/ebuild.lib | 9 |
7 files changed, 87 insertions, 79 deletions
diff --git a/bash/eapi/0.lib b/bash/eapi/0.lib index 0525fab23..5d36379d6 100644 --- a/bash/eapi/0.lib +++ b/bash/eapi/0.lib @@ -1,4 +1,44 @@ # Copyright: 2012 Brian Harring <ferringb@gmail.com> # license GPL2/BSD 3 -__inject_phase_funcs __phase_common pkg_nofetch src_{unpack,compile,test} +__phase_pkg_nofetch() { + [[ -z ${SRC_URI} ]] && return + + echo "!!! The following are listed in SRC_URI for ${PN}:" + local fp + __shopt_push -f + for fp in ${SRC_URI}; do + echo "!!! ${fp}" + done + __shopt_pop +} + +__phase_src_unpack() { + if [[ -n ${A} ]]; then + unpack ${A} + fi +} + +__phase_src_compile() { + if [[ -x ./configure ]]; then + econf + fi + if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + emake || die "emake failed" + fi +} + +__phase_src_test() { + addpredict / + local extra_args=( ${EXTRA_EMAKE} ) + ${PKGCORE_ALLOW_PARALLEL_SRC_TEST} || extra_args+=( -j1 ) + if make check -n &> /dev/null; then + echo ">>> Test phase [check]: ${CATEGORY}/${PF}" + emake "${extra_args[@]}" check || die "Make check failed. See above for details." + elif make test -n &> /dev/null; then + emake "${extra_args[@]}" test || die "Make test failed. See above for details." + else + echo ">>> Test phase [none]: ${CATEGORY}/${PF}" + fi + SANDBOX_PREDICT=${SANDBOX_PREDICT%:/} +} diff --git a/bash/eapi/1.lib b/bash/eapi/1.lib index 4f66e73b6..0757f1e48 120000..100644 --- a/bash/eapi/1.lib +++ b/bash/eapi/1.lib @@ -1 +1,13 @@ -0.lib
\ No newline at end of file +# Copyright: 2015 Tim Harder <radhermit@gmail.com> +# license GPL2/BSD 3 + +source "${PKGCORE_BIN_PATH}"/eapi/0.lib + +__phase_src_compile() { + if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then + econf + fi + if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + emake || die "emake failed" + fi +} diff --git a/bash/eapi/2.lib b/bash/eapi/2.lib index d62d6d068..5dd125ada 100644 --- a/bash/eapi/2.lib +++ b/bash/eapi/2.lib @@ -3,13 +3,19 @@ source "${PKGCORE_BIN_PATH}"/eapi/1.lib -__phase_eapi2_src_configure() { +__phase_src_configure() { if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then econf fi } -__phase_eapi2_src_prepare() { +__phase_src_compile() { + if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + emake || die "emake failed" + fi +} + +__phase_src_prepare() { : } @@ -23,6 +29,4 @@ default() { fi } -__inject_phase_funcs __phase_eapi2 src_{configure,prepare} - : diff --git a/bash/eapi/4.lib b/bash/eapi/4.lib index 82e344fef..1837b19d3 100644 --- a/bash/eapi/4.lib +++ b/bash/eapi/4.lib @@ -7,7 +7,7 @@ nonfatal() { PKGCORE_NONFATAL_HELPER=true "$@" } -__phase_eapi4_src_install() { +__phase_src_install() { if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then emake DESTDIR="${D}" install fi @@ -33,6 +33,4 @@ __phase_eapi4_src_install() { fi } -__inject_phase_funcs __phase_eapi4 src_install - : diff --git a/bash/eapi/common.lib b/bash/eapi/common.lib index 5d6526eeb..e20446873 100644 --- a/bash/eapi/common.lib +++ b/bash/eapi/common.lib @@ -253,53 +253,6 @@ __get_libdir() { echo "${libdir}" } -__phase_common_pkg_nofetch() { - [[ -z ${SRC_URI} ]] && return - - echo "!!! The following are listed in SRC_URI for ${PN}:" - local fp - __shopt_push -f - for fp in ${SRC_URI}; do - echo "!!! ${fp}" - done - __shopt_pop -} - -__phase_common_src_unpack() { - if [[ -n ${A} ]]; then - unpack ${A} - fi -} - -__phase_common_src_compile() { - # only eapi 0/1 invoke configure... - if __safe_has "${EAPI}" 0 1; then - if [[ ${EAPI} == 0 ]]; then - [[ -x ./configure ]] && econf - elif [[ -x ${ECONF_SOURCE:-.}/configure ]]; then - econf - fi - fi - if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then - emake || die "emake failed" - fi -} - -__phase_common_src_test() { - addpredict / - local extra_args=( ${EXTRA_EMAKE} ) - ${PKGCORE_ALLOW_PARALLEL_SRC_TEST} || extra_args+=( -j1 ) - if make check -n &> /dev/null; then - echo ">>> Test phase [check]: ${CATEGORY}/${PF}" - emake "${extra_args[@]}" check || die "Make check failed. See above for details." - elif make test -n &> /dev/null; then - emake "${extra_args[@]}" test || die "Make test failed. See above for details." - else - echo ">>> Test phase [none]: ${CATEGORY}/${PF}" - fi - SANDBOX_PREDICT=${SANDBOX_PREDICT%:/} -} - into() { ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} if [[ $1 == "/" ]]; then @@ -348,7 +301,7 @@ docinto() { fi } -__phase_common_pre_phase() { +__phase_pre_phase() { if [[ -d ${S} ]]; then cd "${S}" elif __safe_has "${EAPI}" 0 1 2 3; then @@ -371,7 +324,7 @@ __phase_common_pre_phase() { fi } -__phase_default_pre_src_unpack() { +__phase_pre_src_unpack() { export PORTAGE_GZIP_COMMAND=${PORTAGE_GZIP_COMMAND:-gzip} export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} export PORTAGE_XZ_COMMAND=${PORTAGE_XZ_COMMAND:-xz} @@ -379,21 +332,21 @@ __phase_default_pre_src_unpack() { cd "${WORKDIR}" } -__phase_default_pre_src_prepare() { __phase_common_pre_phase; } -__phase_default_pre_src_test() { __phase_common_pre_phase; } +__phase_pre_src_prepare() { __phase_pre_phase; } +__phase_pre_src_test() { __phase_pre_phase; } -__phase_default_pre_src_configure() { +__phase_pre_src_configure() { local var for var in C{BUILD,HOST,TARGET,C,XX} {AS,LD,{,LIB}C{,XX}}FLAGS; do [[ -n ${!var+set} ]] && export ${var}="${!var}" done - __phase_common_pre_phase + __phase_pre_phase } -__phase_default_pre_src_compile() { +__phase_pre_src_compile() { # just reuse the default_pre_src_configure; this means we don't have to care # if the eapi has configure or not. - __phase_default_pre_src_configure + __phase_pre_src_configure if __feature_is_enabled distcc; then [[ -n ${DISTCC_DIR} ]] && addwrite "${DISTCC_DIR}" @@ -404,14 +357,14 @@ __phase_default_pre_src_compile() { fi } -__phase_default_post_src_compile() { +__phase_post_src_compile() { if __feature_is_enabled distcc && __feature_is_enabled distcc-pump; then pump --shutdown trap - EXIT fi } -__phase_default_pre_src_install() { +__phase_pre_src_install() { export DESTTREE=/usr INSDESTTREE='' PKGCORE_EXEDESTTREE='' PKGCORE_DOCDESTTREE='' export INSOPTIONS="-m0644" EXEOPTIONS="-m0755" export LIBOPTIONS="-m0644" DIROPTIONS="-m0755" @@ -428,21 +381,19 @@ __phase_default_pre_src_install() { else mkdir "${D}" fi - __phase_common_pre_phase + __phase_pre_phase } -__inject_phase_funcs() { - local prefix=$1 func - shift +__inject_default_phase_funcs() { + local prefix="__phase_" func for func in "$@"; do - if ! __is_function "${func}"; then - eval "__phase_default_${func}() { ${prefix}_${func}; }"; - fi + # skip non-phase functions + [[ ${func} == ${prefix}* ]] || continue # define default_${phase} funcs for EAPI 2 and up if ! __safe_has "${EAPI}" 0 1 ; then - eval "default_${func}() { ${prefix}_${func}; }"; + eval "default_${func#${prefix}}() { ${func}; }"; fi done } diff --git a/bash/ebuild-default-functions.lib b/bash/ebuild-default-functions.lib index 284b480e2..e04c92b52 100644 --- a/bash/ebuild-default-functions.lib +++ b/bash/ebuild-default-functions.lib @@ -31,7 +31,7 @@ __dyn_src_install() { if __is_function src_install; then __qa_invoke src_install else - __qa_run_function_if_exists __phase_default_src_install + __qa_run_function_if_exists __phase_src_install fi "${PKGCORE_BIN_PATH}"/helpers/internals/prepall @@ -123,7 +123,7 @@ __dyn_pkg_preinst() { if __is_function pkg_preinst; then __qa_invoke pkg_preinst else - __qa_run_function_if_exists __phase_default_pkg_preinst + __qa_run_function_if_exists __phase_pkg_preinst fi ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} diff --git a/bash/ebuild.lib b/bash/ebuild.lib index b69231242..bd99b7665 100644 --- a/bash/ebuild.lib +++ b/bash/ebuild.lib @@ -166,6 +166,9 @@ __load_eapi_libs() { source "${PKGCORE_BIN_PATH}"/eapi/common.lib || die "failed sourcing eapi/common.lib" source "${PKGCORE_BIN_PATH}/eapi/${PKGCORE_EAPI-${EAPI}}.lib" || \ die "failed loading eapi/${PKGCORE_EAPI-${EAPI}}.lib" + + # create default_* functions + __inject_default_phase_funcs ${PKGCORE_EAPI_FUNCS} } # do all profile, bashrc's, and ebuild sourcing. Should only be called in setup phase, unless the @@ -278,7 +281,7 @@ source "${PKGCORE_BIN_PATH}"/ebuild-env-utils.lib >&2 || die "failed sourcing eb __run_ebuild_phase() { [[ -n ${PKGCORE_DEBUG} ]] && set -x - __qa_run_function_if_exists __phase_default_pre_$1 + __qa_run_function_if_exists __phase_pre_$1 __qa_run_function_if_exists pre_$1 local EBUILD_PHASE_FUNC @@ -289,11 +292,11 @@ __run_ebuild_phase() { elif __is_function $1; then __qa_invoke $1 else - __qa_run_function_if_exists __phase_default_$1 + __qa_run_function_if_exists __phase_$1 fi __qa_run_function_if_exists post_$1 - __qa_run_function_if_exists __phase_default_post_$1 + __qa_run_function_if_exists __phase_post_$1 [[ ${PKGCORE_DEBUG} -lt 2 ]] && set +x } |