commit:     f7854dec88e0126fbe6a29b7a53d67e0917cc610
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Jun  8 00:16:25 2018 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Jun  8 04:16:32 2018 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f7854dec

media-libs/mesa: Simplify driver selection code

 media-libs/mesa/mesa-9999.ebuild | 70 +++++++++++++---------------------------
 1 file changed, 22 insertions(+), 48 deletions(-)

diff --git a/media-libs/mesa/mesa-9999.ebuild b/media-libs/mesa/mesa-9999.ebuild
index e9bfa80a319..cb3e9ee26bb 100644
--- a/media-libs/mesa/mesa-9999.ebuild
+++ b/media-libs/mesa/mesa-9999.ebuild
@@ -351,13 +351,18 @@ multilib_src_configure() {
        fi
 
        if use gallium; then
-               gallium_enable swrast
+               GALLIUM_DRIVERS+="swrast "
                emesonargs+=( -Dosmesa=$(usex osmesa gallium none) )
        else
-               dri_driver_enable swrast
+               DRI_DRIVERS+="swrast "
                emesonargs+=( -Dosmesa=$(usex osmesa classic none) )
        fi
 
+       driver_list() {
+               arr=($(printf "%s\n" "$@" | sort -u | tr '\n' ','))
+               echo "${arr: : -1}"
+       }
+
        emesonargs+=(
                -Dbuild-tests=$(usex test true false)
                -Dglx=dri
@@ -372,9 +377,9 @@ multilib_src_configure() {
                -Dlibunwind=$(usex unwind true false)
                -Dlmsensors=$(usex lm_sensors true false)
                -Dvalgrind=$(usex valgrind auto false)
-               -Ddri-drivers=${DRI_DRIVERS}
-               -Dgallium-drivers=${GALLIUM_DRIVERS}
-               -Dvulkan-drivers=${VULKAN_DRIVERS}
+               -Ddri-drivers=$(driver_list ${DRI_DRIVERS})
+               -Dgallium-drivers=$(driver_list ${GALLIUM_DRIVERS})
+               -Dvulkan-drivers=$(driver_list ${VULKAN_DRIVERS})
        )
        meson_src_configure
 }
@@ -455,54 +460,23 @@ pkg_prerm() {
 
 # $1 - VIDEO_CARDS flag
 # other args - names of DRI drivers to enable
-# TODO: avoid code duplication for a more elegant implementation
 dri_driver_enable() {
-       case $# in
-               # for enabling unconditionally
-               1)
-                       DRI_DRIVERS+=",$1"
-                       ;;
-               *)
-                       if use $1; then
-                               shift
-                               for i in $@; do
-                                       DRI_DRIVERS+=",${i}"
-                               done
-                       fi
-                       ;;
-       esac
+       if use $1; then
+               shift
+               DRI_DRIVERS+="$@ "
+       fi
 }
 
 gallium_enable() {
-       case $# in
-               # for enabling unconditionally
-               1)
-                       GALLIUM_DRIVERS+=",$1"
-                       ;;
-               *)
-                       if use $1; then
-                               shift
-                               for i in $@; do
-                                       GALLIUM_DRIVERS+=",${i}"
-                               done
-                       fi
-                       ;;
-       esac
+       if use $1; then
+               shift
+               GALLIUM_DRIVERS+="$@ "
+       fi
 }
 
 vulkan_enable() {
-       case $# in
-               # for enabling unconditionally
-               1)
-                       VULKAN_DRIVERS+=",$1"
-                       ;;
-               *)
-                       if use $1; then
-                               shift
-                               for i in $@; do
-                                       VULKAN_DRIVERS+=",${i}"
-                               done
-                       fi
-                       ;;
-       esac
+       if use $1; then
+               shift
+               VULKAN_DRIVERS+="$@ "
+       fi
 }

Reply via email to