media-libs/mesa: Simplify driver selection code
authorMatt Turner <mattst88@gentoo.org>
Fri, 8 Jun 2018 00:16:25 +0000 (17:16 -0700)
committerMatt Turner <mattst88@gentoo.org>
Fri, 8 Jun 2018 04:16:32 +0000 (21:16 -0700)
media-libs/mesa/mesa-9999.ebuild

index e9bfa80a3194d32e71b3c0ec7a0e3304176f7f00..cb3e9ee26bbda9a46a85837bd34d089be13c6ed6 100644 (file)
@@ -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
 }