From b793b2bd9a5dc3ba3477fbfcbb00fe27fcb577f2 Mon Sep 17 00:00:00 2001 From: "Gregory M. Tuner" Date: Sun, 29 Dec 2013 23:14:00 -0800 Subject: eclass/multibuild: multibuild_is_best_variant -> multibuild_get_best_variant It is trivial to deduce whether the current variant is the best one from an API that returns the name of the best one. However it is nontrivial to determine the name of the best variant from an API that returns whether or not the current variant is the best one. Therefore, it's better to have this API than the old one. This patch also ports multilib-build.eclass to use the new API instead of the old one. Finally, it re-implements multibuild_for_best_variant using the new API in lieu of its duplicate procedural logic, to compute precisely the same value. Signed-off-by: Gregory M. Tuner --- eclass/multibuild.eclass | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'eclass/multibuild.eclass') diff --git a/eclass/multibuild.eclass b/eclass/multibuild.eclass index 382d51d..249814a 100644 --- a/eclass/multibuild.eclass +++ b/eclass/multibuild.eclass @@ -194,32 +194,30 @@ multibuild_for_best_variant() { || die "MULTIBUILD_VARIANTS need to be set" # bash-4.1 can't handle negative subscripts - local MULTIBUILD_VARIANTS=( - "${MULTIBUILD_VARIANTS[$(( ${#MULTIBUILD_VARIANTS[@]} - 1 ))]}" - ) + local MULTIBUILD_VARIANTS=("$(multibuild_get_best_variant)") multibuild_foreach_variant "${@}" } -# @FUNCTION: multibuild_is_best_variant +# @FUNCTION: multibuild_get_best_variant # @DESCRIPTION: -# Sometimes, while iterating through multibuild variants, we might -# want to conditionalize some code on whether or not the current -# variant is the "best" variant, without explicitly needing to -# invoke multibuild_for_best_variant. +# Sometimes, we want to know what the best variant is according to +# multibuild (answer: it's always the last one on the list). # -# Returns zero if and only if the current variant is the same as -# would be activated by multibuild_for_best_variant. -multibuild_is_best_variant() { +# This performs some sanity checking and returns it on the standard +# output -- otherwise, folks would have to know the ordering +# implementation detail or use multibuild_for_best_variant which is +# a rather wasteful, and even potentially incorrect way to get the +# information. +# +# This may only be used if ${MULTIBUILD_VARIANTS} has been set. +# otherwise we die(), lest someone miss an error in a subshell. +multibuild_get_best_variant() { debug-print-function ${FUNCNAME} "${@}" [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments" [[ ${MULTIBUILD_VARIANTS} ]] \ || die "MULTIBUILD_VARIANTS must be set" - [[ ${MULTIBUILD_VARIANT} ]] \ - || die "MULTIBUILD_VARIANT must be set" - - local best_variant="${MULTIBUILD_VARIANTS[$(( ${#MULTIBUILD_VARIANTS[@]} - 1 ))]}" - [[ ${MULTIBUILD_VARIANT} == ${best_variant} ]] + echo "${MULTIBUILD_VARIANTS[$(( ${#MULTIBUILD_VARIANTS[@]} - 1 ))]}" } # @FUNCTION: multibuild_copy_sources -- cgit v1.2.3-18-g5258