Introduce in_iuse() for IUSE checks.
authorMichał Górny <mgorny@gentoo.org>
Wed, 21 Sep 2011 21:46:49 +0000 (21:46 +0000)
committerMichał Górny <mgorny@gentoo.org>
Wed, 21 Sep 2011 21:46:49 +0000 (21:46 +0000)
Such checks are used at least in autotools-utils & kde* eclasses, and
are done wrong there. Thus, I've created a little reusable snippet
suitable for eutils.

eclass/eutils.eclass

index cd1f9ff17cec3a2577f722c88f4fc7bb8626c4fa..d202031b8f982dadcd216b05103cdaeb17bdcbe3 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.363 2011/09/12 20:44:01 mgorny Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.364 2011/09/21 21:46:49 mgorny Exp $
 
 # @ECLASS: eutils.eclass
 # @MAINTAINER:
@@ -2028,3 +2028,20 @@ path_exists() {
                -o) return $(( r == $# )) ;;
        esac
 }
+
+# @FUNCTION: in_iuse
+# @USAGE: <flag>
+# @DESCRIPTION:
+# Determines whether the given flag is in IUSE. Strips IUSE default prefixes
+# as necessary.
+#
+# Note that this function should not be used in the global scope.
+in_iuse() {
+       debug-print-function ${FUNCNAME} "${@}"
+       [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()"
+
+       local flag=${1}
+       local liuse=( ${IUSE} )
+
+       has "${flag}" "${liuse[@]#[+-]}"
+}