Revised to use a separate variable for the name of the flag instead of
reading IUSE, as suggested by Ciaran McCreesh. As a result of this
change, vala.eclass now defaults to assuming that vala support is
optional (which is the case in an overwhelming majority of ebuilds that
would want to use this eclass).

--- a/vala.eclass
+++ b/vala.eclass
@@ -39,6 +39,19 @@
 # @DESCRIPTION:
 # USE dependencies that vala must be built with (e.g. vapigen).
 
+# @ECLASS-VARIABLE: VALA_OPTIONAL
+# @DESCRIPTION:
+# Set to "no" if vala support is not optional.
+VALA_OPTIONAL=${VALA_OPTIONAL:-yes}
+
+# @ECLASS-VARIABLE: VALA_IUSE
+# @DESCRIPTION:
+# USE flag that enables vala support in the ebuild; will be added to IUSE 
unless
+# VALA_OPTIONAL is "no"; can be prefixed with '+'.
+VALA_IUSE=${VALA_IUSE:-vala}
+
+[[ ${VALA_OPTIONAL} = no ]] || IUSE=${VALA_IUSE}
+
 # @FUNCTION: vala_api_versions
 # @DESCRIPTION:
 # Outputs a list of vala API versions from VALA_MAX_API_VERSION down to
@@ -49,17 +62,20 @@
 
 # @FUNCTION: vala_depend
 # @DESCRIPTION:
-# Outputs a ||-dependency string on vala from VALA_MAX_API_VERSION down to
-# VALA_MIN_API_VERSION
+# Outputs a ||-dependency string on vala satisfying VALA_MAX_API_VERSION,
+# VALA_MIN_API_VERSION, and VALA_USE_DEPEND. The dependency will be conditional
+# on VALA_IUSE unless vala is non-optional.
 vala_depend() {
        local u v versions=$(vala_api_versions)
        [[ ${VALA_USE_DEPEND} ]] && u="[${VALA_USE_DEPEND}]"
 
+       [[ ${VALA_OPTIONAL} = no ]] || echo -n "${VALA_IUSE#[+-]}? ( "
        echo -n "|| ("
        for v in ${versions}; do
                echo -n " dev-lang/vala:${v}${u}"
        done
-       echo " )"
+       echo -n " )"
+       [[ ${VALA_OPTIONAL} = no ]] || echo -n " )"
 }
 
 # @FUNCTION: vala_best_api_version
@@ -81,17 +97,24 @@
 # specified API version, or, if no version is specified, for the
 # highest installed vala API version satisfying
 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
-# Dies if called without --vala-api-version and no suitable vala
-# version is found.
+# Is a no-op if vala support is optional and disabled via USE.
+# Dies if the USE check is passed and a suitable vala version is not
+# available.
 vala_src_prepare() {
        local p d valafoo version
 
        if [[ $1 = "--vala-api-version" ]]; then
                version=$2
                [[ ${version} ]] || die "'--vala-api-version' option requires 
API version parameter."
+       fi
+
+       [[ ${VALA_OPTIONAL} = no ]] || use "${VALA_IUSE#[+-]}" || return
+
+       if [[ ${version} ]]; then
+               has_version "dev-lang/vala:${version}" || die "No installed 
vala:${version}"
        else
                version=$(vala_best_api_version)
-               [[ ${version} ]] || die "No installed vala in $(vala_depend)"
+               [[ ${version} ]] || die "No installed vala in 
$(VALA_OPTIONAL=no vala_depend)"
        fi
 
        export VALAC=$(type -P valac-${version})


Reply via email to