commit: 43b6be7423aaebee26e4659d580a9a17b4fde01e
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 7 23:14:40 2017 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue May 1 08:28:44 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=43b6be74
phase-helpers.sh: Implement -r|-d|-b options for best/has_version
The code for these functions is practically identical so refactor them
around a common function.
bin/eapi.sh | 6 ++-
bin/phase-helpers.sh | 146 ++++++++++++++++++++-------------------------------
2 files changed, 63 insertions(+), 89 deletions(-)
diff --git a/bin/eapi.sh b/bin/eapi.sh
index 3b6a5c1a9..455bc9b0d 100644
--- a/bin/eapi.sh
+++ b/bin/eapi.sh
@@ -155,7 +155,11 @@ ___eapi_has_package_manager_build_group() {
# HELPERS BEHAVIOR
___eapi_best_version_and_has_version_support_--host-root() {
- [[ ! ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi)$ ]]
+ [[ ${1-${EAPI-0}} =~ ^(5|5-progress|6)$ ]]
+}
+
+___eapi_best_version_and_has_version_support_-b_-d_-r() {
+ [[ ! ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-progress|6)$
]]
}
___eapi_unpack_supports_xz() {
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index f6c9ef6fc..59c19cf67 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -878,46 +878,55 @@ __eapi6_src_install() {
einstalldocs
}
-# @FUNCTION: has_version
-# @USAGE: [--host-root] <DEPEND ATOM>
-# @DESCRIPTION:
-# Return true if given package is installed. Otherwise return false.
-# Callers may override the ROOT variable in order to match packages from an
-# alternative ROOT.
-has_version() {
-
- local atom eroot host_root=false root=${ROOT}
- if [[ $1 == --host-root ]] ; then
- host_root=true
- shift
- fi
+___best_version_and_has_version_common() {
+ local atom root root_arg
+ case $1 in
+ --host-root|-r|-d|-b)
+ root_arg=$1
+ shift ;;
+ esac
atom=$1
shift
- [ $# -gt 0 ] && die "${FUNCNAME[0]}: unused argument(s): $*"
+ [ $# -gt 0 ] && die "${FUNCNAME[1]}: unused argument(s): $*"
- if ${host_root} ; then
- if ! ___eapi_best_version_and_has_version_support_--host-root;
then
- die "${FUNCNAME[0]}: option --host-root is not
supported with EAPI ${EAPI}"
- fi
- root=/
- fi
+ case ${root_arg} in
+ "") if ___eapi_has_prefix_variables; then
+ root=${EROOT}
+ else
+ root=${ROOT}
+ fi ;;
+ --host-root)
+ if !
___eapi_best_version_and_has_version_support_--host-root; then
+ die "${FUNCNAME[1]}: option ${root_arg} is not
supported with EAPI ${EAPI}"
+ fi
+ if ___eapi_has_prefix_variables; then
+ root=/${PORTAGE_OVERRIDE_EPREFIX#/}
+ else
+ root=/
+ fi ;;
+ -r|-d|-b)
+ if !
___eapi_best_version_and_has_version_support_-b_-d_-r; then
+ die "${FUNCNAME[1]}: option ${root_arg} is not
supported with EAPI ${EAPI}"
+ fi
+ if ___eapi_has_prefix_variables; then
+ case ${root_arg} in
+ -r) root=${EROOT} ;;
+ -d) root=${ESYSROOT} ;;
+ -b) root=${BROOT:-/} ;;
+ esac
+ else
+ case ${root_arg} in
+ -r) root=${ROOT} ;;
+ -d) root=${SYSROOT} ;;
+ -b) root=/ ;;
+ esac
+ fi ;;
+ esac
- if ___eapi_has_prefix_variables; then
- # [[ ${root} == / ]] would be ambiguous here,
- # since both prefixes can share root=/ while
- # having different EPREFIX offsets.
- if ${host_root} ; then
- eroot=${root%/}${PORTAGE_OVERRIDE_EPREFIX}/
- else
- eroot=${root%/}${EPREFIX}/
- fi
- else
- eroot=${root}
- fi
if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
- "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "${eroot}" "${atom}"
+ "${PORTAGE_BIN_PATH}"/ebuild-ipc "${FUNCNAME[1]}" "${root}"
"${atom}"
else
- "${PORTAGE_BIN_PATH}/ebuild-helpers/portageq" has_version
"${eroot}" "${atom}"
+ "${PORTAGE_BIN_PATH}"/ebuild-helpers/portageq "${FUNCNAME[1]}"
"${root}" "${atom}"
fi
local retval=$?
case "${retval}" in
@@ -925,75 +934,36 @@ has_version() {
return ${retval}
;;
2)
- die "${FUNCNAME[0]}: invalid atom: ${atom}"
+ die "${FUNCNAME[1]}: invalid atom: ${atom}"
;;
*)
if [[ -n ${PORTAGE_IPC_DAEMON} ]]; then
- die "${FUNCNAME[0]}: unexpected ebuild-ipc exit
code: ${retval}"
+ die "${FUNCNAME[1]}: unexpected ebuild-ipc exit
code: ${retval}"
else
- die "${FUNCNAME[0]}: unexpected portageq exit
code: ${retval}"
+ die "${FUNCNAME[1]}: unexpected portageq exit
code: ${retval}"
fi
;;
esac
}
+# @FUNCTION: has_version
+# @USAGE: [--host-root|-r|-d|-b] <DEPEND ATOM>
+# @DESCRIPTION:
+# Return true if given package is installed. Otherwise return false.
+# Callers may override the ROOT variable in order to match packages from an
+# alternative ROOT.
+has_version() {
+ ___best_version_and_has_version_common "$@"
+}
+
# @FUNCTION: best_version
-# @USAGE: [--host-root] <DEPEND ATOM>
+# @USAGE: [--host-root|-r|-d|-b] <DEPEND ATOM>
# @DESCRIPTION:
# Returns highest installed matching category/package-version (without
.ebuild).
# Callers may override the ROOT variable in order to match packages from an
# alternative ROOT.
best_version() {
-
- local atom eroot host_root=false root=${ROOT}
- if [[ $1 == --host-root ]] ; then
- host_root=true
- shift
- fi
- atom=$1
- shift
- [ $# -gt 0 ] && die "${FUNCNAME[0]}: unused argument(s): $*"
-
- if ${host_root} ; then
- if ! ___eapi_best_version_and_has_version_support_--host-root;
then
- die "${FUNCNAME[0]}: option --host-root is not
supported with EAPI ${EAPI}"
- fi
- root=/
- fi
-
- if ___eapi_has_prefix_variables; then
- # [[ ${root} == / ]] would be ambiguous here,
- # since both prefixes can share root=/ while
- # having different EPREFIX offsets.
- if ${host_root} ; then
- eroot=${root%/}${PORTAGE_OVERRIDE_EPREFIX}/
- else
- eroot=${root%/}${EPREFIX}/
- fi
- else
- eroot=${root}
- fi
- if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
- "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "${eroot}" "${atom}"
- else
- "${PORTAGE_BIN_PATH}/ebuild-helpers/portageq" best_version
"${eroot}" "${atom}"
- fi
- local retval=$?
- case "${retval}" in
- 0|1)
- return ${retval}
- ;;
- 2)
- die "${FUNCNAME[0]}: invalid atom: ${atom}"
- ;;
- *)
- if [[ -n ${PORTAGE_IPC_DAEMON} ]]; then
- die "${FUNCNAME[0]}: unexpected ebuild-ipc exit
code: ${retval}"
- else
- die "${FUNCNAME[0]}: unexpected portageq exit
code: ${retval}"
- fi
- ;;
- esac
+ ___best_version_and_has_version_common "$@"
}
if ___eapi_has_get_libdir; then