[arch-commits] Commit in dkms/trunk (PKGBUILD hook.sh)

Sébastien Luttringer seblu at archlinux.org
Fri Oct 26 13:05:23 UTC 2018


    Date: Friday, October 26, 2018 @ 13:05:21
  Author: seblu
Revision: 337320

hook.sh: Improve check_dependency and check_buildexclusive

>From 9069728e4ba60df6ada86610818baff11fdabf8f Mon Sep 17 00:00:00 2001
From: Eli Schwartz <eschwartz93 at gmail.com>
Date: Wed, 6 Jun 2018 12:35:42 -0400
Subject: [PATCH 1/2] simplify the hook script

Instead of copying the BUILD_DEPENDS array from a subshell that sources
the dkms.conf and uses a herestring to pass that to readarray, run the
whole function in a subshell. It needs one subshell either way, and
heredocs use a temporary file which is just totally unnecessary albeit
minimal overhead in this case.

Heredocs also invoke command substitution which strips newlines, and do
not support \0 which means readarray needs to re-split the content based
on newlines instead. Neither of these are likely to matter in this
case... but why not just avoid it, if it is free to do so?
Both of these could be solved by using < <(commands) which communicates
via a file instead of command substitution. But that still results in an
unnecessary temporary file.

Instead of copying the BUILD_EXCLUSIVE_KERNEL variable from a subshell
that sources the dkms.conf and uses a herestring to pass that to
readarray, simply use command substitution to assign the value to the
variable. The herestring is once again inefficiently opening a temporary
file, except this time it is totally unnecessary as the value in the
dkms.conf is not an array and does not need to be split into one

Modified:
  dkms/trunk/PKGBUILD
  dkms/trunk/hook.sh

----------+
 PKGBUILD |    2 +-
 hook.sh  |   20 ++++++++------------
 2 files changed, 9 insertions(+), 13 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2018-10-26 12:06:56 UTC (rev 337319)
+++ PKGBUILD	2018-10-26 13:05:21 UTC (rev 337320)
@@ -24,7 +24,7 @@
 md5sums=('SKIP'
          '90f1486e0af9aab85e8c60d456802c63'
          '2e8ffd0c2ddec02872d0234befd129fd'
-         'a71fcf1bfb037047c4d9321e189e06a2'
+         '0dd4819d19fcafc817a96dd5b0a60fd8'
          'd3b91ef709f567a375f4bbdbd3291d2b')
 
 prepare() {

Modified: hook.sh
===================================================================
--- hook.sh	2018-10-26 12:06:56 UTC (rev 337319)
+++ hook.sh	2018-10-26 13:05:21 UTC (rev 337320)
@@ -26,25 +26,21 @@
 # check whether the dependencies of a module are installed
 # $1: module name/module version
 # $2: kernel version
-check_dependency() {
-	local -a BUILD_DEPENDS
-	readarray -t BUILD_DEPENDS <<<$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "${BUILD_DEPENDS[@]}")
-	[[ -z ${BUILD_DEPENDS[@]} ]] && unset BUILD_DEPENDS
-	local mod
-	for mod in "${BUILD_DEPENDS[@]}"; do
-		if ! [[ "$(dkms status -m "$mod" -k "$2")" =~ :[[:space:]]installed$ ]]; then
-			return 1
+check_dependency() { (
+	source "$source_tree/${1/\//-}/dkms.conf"
+	for dep in "${BUILD_DEPENDS[@]}"; do
+		if ! [[ "$(dkms status -m "$dep" -k "$2")" =~ :[[:space:]]installed$ ]]; then
+			exit 1
 		fi
 	done
-	return 0
-}
+	exit 0
+) }
 
 # check whether the modules should be built with this kernel version
 # $1: module name/module version
 # $2: kernel version
 check_buildexclusive() {
-	local BUILD_EXCLUSIVE_KERNEL
-	readarray -t BUILD_EXCLUSIVE_KERNEL <<<$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL")
+	local BUILD_EXCLUSIVE_KERNEL=$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL")
 	[[ "$2" =~ $BUILD_EXCLUSIVE_KERNEL ]]
 }
 



More information about the arch-commits mailing list