From: Zac Medico Date: Sun, 11 Sep 2011 22:50:07 +0000 (-0700) Subject: build.sh: has/best_version to phase-helpers.sh X-Git-Tag: v2.2.0_alpha56~26 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e40e2bce40464dace057d91f0a24ba682928814a;p=portage.git build.sh: has/best_version to phase-helpers.sh --- diff --git a/bin/ebuild.sh b/bin/ebuild.sh index 6bcc6b314..4dd29216a 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -127,30 +127,6 @@ esyslog() { return 0 } -# Return true if given package is installed. Otherwise return false. -# Takes single depend-type atoms. -has_version() { - if [ "${EBUILD_PHASE}" == "depend" ]; then - die "portageq calls (has_version calls portageq) are not allowed in the global scope" - fi - - if [[ -n $PORTAGE_IPC_DAEMON ]] ; then - "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1" - else - PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1" - fi - local retval=$? - case "${retval}" in - 0|1) - return ${retval} - ;; - *) - die "unexpected portageq exit code: ${retval}" - ;; - esac -} - portageq() { if [ "${EBUILD_PHASE}" == "depend" ]; then die "portageq calls are not allowed in the global scope" @@ -160,36 +136,6 @@ portageq() { "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@" } - -# ---------------------------------------------------------------------------- -# ---------------------------------------------------------------------------- -# ---------------------------------------------------------------------------- - - -# Returns the best/most-current match. -# Takes single depend-type atoms. -best_version() { - if [ "${EBUILD_PHASE}" == "depend" ]; then - die "portageq calls (best_version calls portageq) are not allowed in the global scope" - fi - - if [[ -n $PORTAGE_IPC_DAEMON ]] ; then - "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1" - else - PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ - "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" - fi - local retval=$? - case "${retval}" in - 0|1) - return ${retval} - ;; - *) - die "unexpected portageq exit code: ${retval}" - ;; - esac -} - register_die_hook() { local x for x in $* ; do @@ -793,6 +739,11 @@ else keepdir libopts use useq usev use_with use_enable ; do eval "${x}() { : ; }" done + # These functions die because calls to them during the "depend" phase + # are considered to be severe QA violations. + for x in best_version has_version ; do + eval "${x}() { die \"\${FUNCNAME} calls are not allowed in global scope\"; }" + done unset x fi diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh index 6064346be..1f39c7556 100644 --- a/bin/phase-helpers.sh +++ b/bin/phase-helpers.sh @@ -571,3 +571,45 @@ _eapi4_src_install() { dodoc ${DOCS} fi } + +# Return true if given package is installed. Otherwise return false. +# Takes single depend-type atoms. +has_version() { + + if [[ -n $PORTAGE_IPC_DAEMON ]] ; then + "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1" + else + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1" + fi + local retval=$? + case "${retval}" in + 0|1) + return ${retval} + ;; + *) + die "unexpected portageq exit code: ${retval}" + ;; + esac +} + +# Returns the best/most-current match. +# Takes single depend-type atoms. +best_version() { + + if [[ -n $PORTAGE_IPC_DAEMON ]] ; then + "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1" + else + PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \ + "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" best_version "${ROOT}" "$1" + fi + local retval=$? + case "${retval}" in + 0|1) + return ${retval} + ;; + *) + die "unexpected portageq exit code: ${retval}" + ;; + esac +}