implement --missing flag for user-control over IUSE-missing behavior
authorMike Frysinger <vapier@gentoo.org>
Fri, 19 Jan 2007 05:29:18 +0000 (05:29 +0000)
committerMike Frysinger <vapier@gentoo.org>
Fri, 19 Jan 2007 05:29:18 +0000 (05:29 +0000)
eclass/eutils.eclass

index 57bcfb9b25ccc7ade6a32af60f13d21c89b9416d..2d413f1852344b07b03d7b20835a234e49199490 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2006 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.268 2007/01/13 19:36:14 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.269 2007/01/19 05:29:18 vapier Exp $
 #
 # This eclass is for general purpose functions that most ebuilds
 # have to implement themselves.
@@ -1592,13 +1592,24 @@ preserve_old_lib_notify() {
 # Hack for people to figure out if a package was built with
 # certain USE flags
 #
-# Usage: built_with_use [-a|-o] <DEPEND ATOM> <List of USE flags>
+# Usage: built_with_use [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
 #       ex: built_with_use xchat gtk2
 #
-# Flags: -a      all USE flags should be utilized
-#               -o       at least one USE flag should be utilized
+# Flags: -a            all USE flags should be utilized
+#               -o             at least one USE flag should be utilized
+#        --missing  peform the specified action if the flag is not in IUSE (true/false/die)
 # Note: the default flag is '-a'
 built_with_use() {
+       local missing_action="die"
+       if [[ $1 == "--missing" ]] ; then
+               missing_action=$2
+               shift ; shift
+               case ${missing_action} in
+                       true|false|die) ;;
+                       *) die "unknown action '${missing_action}'";;
+               esac
+       fi
+
        local opt=$1
        [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
 
@@ -1623,7 +1634,13 @@ built_with_use() {
                fi
        done
        if [[ -n ${expand} ]] ; then
-               has $1 ${IUSE_BUILT} || die "$PKG does not actually support the $1 USE flag!"
+               if ! has $1 ${IUSE_BUILT} ; then
+                       case ${missing_action} in
+                               true)  return 0;;
+                               false) return 1;;
+                               die)   die "$PKG does not actually support the $1 USE flag!";;
+                       esac
+               fi
        fi
 
        local USE_BUILT=$(<${USEFILE})