public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style
@ 2022-12-25 19:17 Sam James
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 2/3] linux-info.eclass: " Sam James
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sam James @ 2022-12-25 19:17 UTC (permalink / raw
  To: gentoo-dev; +Cc: kernel, Sam James

- Use Bash tests (i.e. [[ ]] instead of [ ])
- Use consistent newlines for if/while
- Drop unnecessary ; line terminators
- Add a handful of missing || dies

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/linux-mod.eclass | 149 +++++++++++++++++-----------------------
 1 file changed, 64 insertions(+), 85 deletions(-)

diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
index ff2294f1e4ef..b0a1264288a0 100644
--- a/eclass/linux-mod.eclass
+++ b/eclass/linux-mod.eclass
@@ -199,13 +199,13 @@ DEPEND="${RDEPEND}
 use_m() {
 	debug-print-function ${FUNCNAME} $*
 
-	# if we haven't determined the version yet, we need too.
-	get_version;
+	# If we haven't determined the version yet, we need to.
+	get_version
 
-	# if the kernel version is greater than 2.6.6 then we should use
+	# If the kernel version is greater than 2.6.6 then we should use
 	# M= instead of SUBDIRS=
-	[ ${KV_MAJOR} -ge 3 ] && return 0
-	[ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
+	[[ ${KV_MAJOR} -ge 3 ]] && return 0
+	[[ ${KV_MAJOR} -eq 2 && ${KV_MINOR} -gt 5 && ${KV_PATCH} -gt 5 ]] && \
 		return 0 || return 1
 }
 
@@ -216,10 +216,10 @@ use_m() {
 convert_to_m() {
 	debug-print-function ${FUNCNAME} $*
 
-	if use_m
-	then
-		[ ! -f "${1}" ] && \
+	if use_m; then
+		[[ ! -f "${1}" ]] && \
 			die "convert_to_m() requires a filename as an argument"
+
 		ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
 		sed -i 's:SUBDIRS=:M=:g' "${1}"
 		eend $?
@@ -233,12 +233,11 @@ convert_to_m() {
 update_depmod() {
 	debug-print-function ${FUNCNAME} $*
 
-	# if we haven't determined the version yet, we need too.
-	get_version;
+	# If we haven't determined the version yet, we need to.
+	get_version
 
 	ebegin "Updating module dependencies for ${KV_FULL}"
-	if [ -r "${KV_OUT_DIR}"/System.map ]
-	then
+	if [[ -r "${KV_OUT_DIR}"/System.map ]]; then
 		depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT:-/}" ${KV_FULL}
 		eend $?
 	else
@@ -310,15 +309,15 @@ remove_moduledb() {
 set_kvobj() {
 	debug-print-function ${FUNCNAME} $*
 
-	if kernel_is ge 2 6
-	then
+	if kernel_is ge 2 6; then
 		KV_OBJ="ko"
 	else
 		KV_OBJ="o"
 	fi
+
 	# Do we really need to know this?
-	# Lets silence it.
-	# einfo "Using KV_OBJ=${KV_OBJ}"
+	# Let's silence it.
+	#einfo "Using KV_OBJ=${KV_OBJ}"
 }
 
 # @FUNCTION: get-KERNEL_CC
@@ -334,7 +333,7 @@ get-KERNEL_CC() {
 	fi
 
 	local kernel_cc
-	if [ -n "${KERNEL_ABI}" ]; then
+	if [[ -n "${KERNEL_ABI}" ]]; then
 		# In future, an arch might want to define CC_$ABI
 		#kernel_cc="$(get_abi_CC)"
 		#[ -z "${kernel_cc}" ] &&
@@ -358,14 +357,13 @@ get-KERNEL_CC() {
 # At the end the documentation specified with MODULESD_<modulename>_DOCS is installed.
 generate_modulesd() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
 	local currm_path currm currm_t t myIFS myVAR
 	local module_docs module_enabled module_aliases \
 			module_additions module_examples module_modinfo module_opts
 
-	for currm_path in ${@}
-	do
+	for currm_path in ${@}; do
 		currm=${currm_path//*\/}
 		currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]')
 		currm_t=${currm}
@@ -388,8 +386,7 @@ generate_modulesd() {
 		[[ ${module_enabled} == no ]] && return 0
 
 		# unset any unwanted variables.
-		for t in ${!module_*}
-		do
+		for t in ${!module_*}; do
 			[[ -z ${!t} ]] && unset ${t}
 		done
 
@@ -427,19 +424,16 @@ generate_modulesd() {
 		fi
 
 		#-----------------------------------------------------------------------
-		if [[ -n ${module_modinfo} ]]
-		then
+		if [[ -n ${module_modinfo} ]]; then
 			echo >> "${module_config}"
 			echo  "# Configurable module parameters" >> "${module_config}"
 			echo  "# ------------------------------" >> "${module_config}"
 			myIFS="${IFS}"
 			IFS="$(echo -en "\n\b")"
 
-			for t in ${module_modinfo}
-			do
+			for t in ${module_modinfo}; do
 				myVAR="$(echo ${t#*:}  | grep -o "[^ ]*[0-9][ =][^ ]*" | tail -1  | grep -o "[0-9]")"
-				if [[ -n ${myVAR} ]]
-				then
+				if [[ -n ${myVAR} ]]; then
 					module_opts="${module_opts} ${t%%:*}:${myVAR}"
 				fi
 				echo -e "# ${t%%:*}:\t${t#*:}" >> "${module_config}"
@@ -449,11 +443,9 @@ generate_modulesd() {
 		fi
 
 		#-----------------------------------------------------------------------
-		if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]
-		then
-			# So lets do some guesswork eh?
-			if [[ -n ${module_opts} ]]
-			then
+		if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]; then
+			# So, let's do some guesswork, eh?
+			if [[ -n ${module_opts} ]]; then
 				echo "# For Example..." >> "${module_config}"
 				echo "# --------------" >> "${module_config}"
 				for t in ${module_opts}
@@ -462,12 +454,10 @@ generate_modulesd() {
 				done
 				echo '' >> "${module_config}"
 			fi
-		elif [[ ${module_examples} -gt 0 ]]
-		then
+		elif [[ ${module_examples} -gt 0 ]]; then
 			echo "# For Example..." >> "${module_config}"
 			echo "# --------------" >> "${module_config}"
-			for((t=0; t<${module_examples}; t++))
-			do
+			for ((t=0; t<${module_examples}; t++)); do
 				echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \
 					>> "${module_config}"
 			done
@@ -475,10 +465,8 @@ generate_modulesd() {
 		fi
 
 		#-----------------------------------------------------------------------
-		if [[ ${module_additions} -gt 0 ]]
-		then
-			for((t=0; t<${module_additions}; t++))
-			do
+		if [[ ${module_additions} -gt 0 ]]; then
+			for ((t=0; t<${module_additions}; t++)); do
 				echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \
 					>> "${module_config}"
 			done
@@ -510,8 +498,7 @@ find_module_params() {
 	local matched_offset=0 matched_opts=0 test="${@}" temp_var result
 	local i=0 y=0 z=0
 
-	for((i=0; i<=${#test}; i++))
-	do
+	for ((i=0; i<=${#test}; i++)); do
 		case ${test:${i}:1} in
 			\()		matched_offset[0]=${i};;
 			\:)		matched_opts=$((${matched_opts} + 1));
@@ -521,8 +508,7 @@ find_module_params() {
 		esac
 	done
 
-	for((i=0; i<=${matched_opts}; i++))
-	do
+	for ((i=0; i<=${matched_opts}; i++)); do
 		# i			= offset were working on
 		# y			= last offset
 		# z			= current offset - last offset
@@ -556,7 +542,7 @@ find_module_params() {
 # in the kernel and sets the object extension KV_OBJ.
 linux-mod_pkg_setup() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
 	local is_bin="${MERGE_TYPE}"
 
@@ -569,12 +555,12 @@ linux-mod_pkg_setup() {
 	# External modules use kernel symbols (bug #591832)
 	CONFIG_CHECK+=" !TRIM_UNUSED_KSYMS"
 
-	linux-info_pkg_setup;
+	linux-info_pkg_setup
 	require_configured_kernel
-	check_kernel_built;
-	strip_modulenames;
+	check_kernel_built
+	strip_modulenames
 	[[ -n ${MODULE_NAMES} ]] && check_modules_supported
-	set_kvobj;
+	set_kvobj
 }
 
 # @FUNCTION: linux-mod_pkg_setup_binary
@@ -586,13 +572,13 @@ linux-mod_pkg_setup_binary() {
 	debug-print-function ${FUNCNAME} $*
 	local new_CONFIG_CHECK
 	# ~ needs always to be quoted, else bash expands it.
-	for config in $CONFIG_CHECK ; do
+	for config in ${CONFIG_CHECK} ; do
 		optional='~'
 		[[ ${config:0:1} == "~" ]] && optional=''
 		new_CONFIG_CHECK="${new_CONFIG_CHECK} ${optional}${config}"
 	done
 	CONFIG_CHECK="${new_CONFIG_CHECK}"
-	linux-info_pkg_setup;
+	linux-info_pkg_setup
 }
 
 # @FUNCTION: strip_modulenames
@@ -617,7 +603,7 @@ strip_modulenames() {
 # Look at the description of these variables for more details.
 linux-mod_src_compile() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
 	local modulename libdir srcdir objdir i n myABI="${ABI}"
 	set_arch_to_kernel
@@ -631,30 +617,25 @@ linux-mod_src_compile() {
 	local -x CROSS_COMPILE=${CROSS_COMPILE-${CHOST}-}
 
 	BUILD_TARGETS=${BUILD_TARGETS:-clean module}
-	strip_modulenames;
-	cd "${S}"
-	touch Module.symvers
-	for i in ${MODULE_NAMES}
-	do
+	strip_modulenames
+	cd "${S}" || die
+	touch Module.symvers || die
+	for i in ${MODULE_NAMES}; do
 		unset libdir srcdir objdir
-		for n in $(find_module_params ${i})
-		do
+		for n in $(find_module_params ${i}); do
 			eval ${n/:*}=${n/*:/}
 		done
 		libdir=${libdir:-misc}
 		srcdir=${srcdir:-${S}}
 		objdir=${objdir:-${srcdir}}
 
-		if [ ! -f "${srcdir}/.built" ];
-		then
-			cd "${srcdir}"
-			ln -s "${S}"/Module.symvers Module.symvers
+		if [[ ! -f "${srcdir}/.built" ]]; then
+			cd "${srcdir}" || die
+			ln -s "${S}"/Module.symvers Module.symvers || die
 			einfo "Preparing ${modulename} module"
-			if [[ -n ${ECONF_PARAMS} ]]
-			then
+			if [[ -n ${ECONF_PARAMS} ]]; then
 				eqawarn "This package relies on the deprecated functionality of econf being called in linux-mod_src_compile (ECONF_PARAMS), which will go away in 30 days (20230107) (https://bugs.gentoo.org/340597)"
-				econf ${ECONF_PARAMS} || \
-				die "Unable to run econf ${ECONF_PARAMS}"
+				econf ${ECONF_PARAMS}
 			fi
 
 			# This looks messy, but it is needed to handle multiple variables
@@ -668,8 +649,8 @@ linux-mod_src_compile() {
 						${BUILD_PARAMS} \
 						${BUILD_TARGETS} " \
 				|| die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}"
-			cd "${OLDPWD}"
-			touch "${srcdir}"/.built
+			cd "${OLDPWD}" || die
+			touch "${srcdir}"/.built || die
 		fi
 	done
 
@@ -690,18 +671,16 @@ linux-mod_src_compile() {
 # Look at the description of these variables for more details.
 linux-mod_src_install() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
 	local modulename libdir srcdir objdir i n
 
 	[[ -n ${KERNEL_DIR} ]] && addpredict "${KERNEL_DIR}/null.dwo"
 
-	strip_modulenames;
-	for i in ${MODULE_NAMES}
-	do
+	strip_modulenames
+	for i in ${MODULE_NAMES}; do
 		unset libdir srcdir objdir
-		for n in $(find_module_params ${i})
-		do
+		for n in $(find_module_params ${i}); do
 			eval ${n/:*}=${n/*:/}
 		done
 		libdir=${libdir:-misc}
@@ -742,22 +721,22 @@ linux-mod_src_install() {
 # It checks what to do after having merged the package.
 linux-mod_pkg_preinst() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
-	[ -d "${D%/}/lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
-	[ -d "${D%/}/lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
+	[[ -d "${D%/}/lib/modules" ]] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
+	[[ -d "${D%/}/lib/modules" ]] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
 }
 
 # @FUNCTION: linux-mod_pkg_postinst
 # @DESCRIPTION:
 # It executes /sbin/depmod and adds the package to the /var/lib/module-rebuild/moduledb
-# database (if ${D}/lib/modules is created)"
+# database (if ${D}/lib/modules is created)
 linux-mod_pkg_postinst() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
 
-	${UPDATE_DEPMOD} && update_depmod;
-	${UPDATE_MODULEDB} && update_moduledb;
+	${UPDATE_DEPMOD} && update_depmod
+	${UPDATE_MODULEDB} && update_moduledb
 }
 
 # @FUNCTION: linux-mod_pkg_postrm
@@ -766,8 +745,8 @@ linux-mod_pkg_postinst() {
 # call /sbin/depmod because the modules are still installed.
 linux-mod_pkg_postrm() {
 	debug-print-function ${FUNCNAME} $*
-	[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
-	remove_moduledb;
+	[[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
+	remove_moduledb
 }
 
 fi
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 2/3] linux-info.eclass: use consistent style
  2022-12-25 19:17 [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Sam James
@ 2022-12-25 19:17 ` Sam James
  2022-12-25 21:28   ` Sam James
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes Sam James
  2022-12-25 22:19 ` [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Ulrich Mueller
  2 siblings, 1 reply; 6+ messages in thread
From: Sam James @ 2022-12-25 19:17 UTC (permalink / raw
  To: gentoo-dev; +Cc: kernel, Sam James

- Use Bash tests (i.e. [[ ]] instead of [ ])
- Use consistent newlines for if/while
- Drop unnecessary ; line terminators

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/linux-info.eclass | 142 ++++++++++++++++++---------------------
 1 file changed, 66 insertions(+), 76 deletions(-)

diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
index 3e64cb9457a9..308286e515c5 100644
--- a/eclass/linux-info.eclass
+++ b/eclass/linux-info.eclass
@@ -140,13 +140,12 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
 # A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless
 # KBUILD_OUTPUT is used. This should be used for referencing .config.
 
-
 # @ECLASS_VARIABLE: SKIP_KERNEL_CHECK
 # @USER_VARIABLE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
-# Do not check for kernel sources or a running kernel version 
-# Main use-case is for chroots
+# Do not check for kernel sources or a running kernel version.
+# Main use-case is for chroots.
 # This is a user flag and should under _no circumstances_ be set in the ebuild.
 : ${SKIP_KERNEL_CHECK:=""}
 
@@ -156,8 +155,7 @@ inherit toolchain-funcs
 
 EXPORT_FUNCTIONS pkg_setup
 
-# Bug fixes
-# fix to bug #75034
+# bug #75034
 case ${ARCH} in
 	ppc)	BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
 	ppc64)	BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
@@ -175,7 +173,7 @@ set_arch_to_pkgmgr() { export ARCH=$(tc-arch); }
 
 # @FUNCTION: qout
 # @DESCRIPTION:
-# qout <einfo | ewarn | eerror>  is a quiet call when EBUILD_PHASE should not have visible output.
+# qout <einfo | ewarn | eerror> is a quiet call when EBUILD_PHASE should not have visible output.
 qout() {
 	local outputmsg type
 	type=${1}
@@ -186,7 +184,7 @@ qout() {
 		clean)   unset outputmsg;;
 		preinst) unset outputmsg;;
 	esac
-	[ -n "${outputmsg}" ] && ${type} "${outputmsg}"
+	[[ -n "${outputmsg}" ]] && ${type} "${outputmsg}"
 }
 
 # @FUNCTION: qeinfo
@@ -196,14 +194,12 @@ qeinfo() { qout einfo "${@}" ; }
 
 # @FUNCTION: qewarn
 # @DESCRIPTION:
-# qewarn is a quiet ewarn call when EBUILD_PHASE
-# should not have visible output.
+# qewarn is a quiet ewarn call when EBUILD_PHASE should not have visible output.
 qewarn() { qout ewarn "${@}" ; }
 
 # @FUNCTION: qeerror
 # @DESCRIPTION:
-# qeerror is a quiet error call when EBUILD_PHASE
-# should not have visible output.
+# qeerror is a quiet error call when EBUILD_PHASE should not have visible output.
 qeerror() { qout eerror "${@}" ; }
 
 # File Functions
@@ -213,18 +209,17 @@ qeerror() { qout eerror "${@}" ; }
 # @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
-# It detects the value of the variable defined in the file configfile. This is
-# done by including the configfile, and printing the variable with Make.
+# It detects the value of the variable defined in the file 'configfile'. This is
+# done by including the 'configfile', and printing the variable with Make.
 # It WILL break if your makefile has missing dependencies!
 getfilevar() {
 	local ERROR basefname basedname myARCH="${ARCH}"
 	ERROR=0
 
-	[ -z "${1}" ] && ERROR=1
-	[ ! -f "${2}" ] && ERROR=1
+	[[ -z "${1}" ]] && ERROR=1
+	[[ ! -f "${2}" ]] && ERROR=1
 
-	if [ "${ERROR}" = 1 ]
-	then
+	if [[ "${ERROR}" = 1 ]]; then
 		echo -e "\n"
 		eerror "getfilevar requires 2 variables, with the second a valid file."
 		eerror "   getfilevar <VARIABLE> <CONFIGFILE>"
@@ -250,7 +245,7 @@ getfilevar() {
 # @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
-# It detects the value of the variable defined in the file configfile.
+# It detects the value of the variable defined in the file 'configfile'.
 # This is done with sed matching an expression only. If the variable is defined,
 # you will run into problems. See getfilevar for those cases.
 getfilevar_noexec() {
@@ -258,12 +253,11 @@ getfilevar_noexec() {
 	ERROR=0
 	mycat='cat'
 
-	[ -z "${1}" ] && ERROR=1
-	[ ! -f "${2}" ] && ERROR=1
-	[ "${2%.gz}" != "${2}" ] && mycat='zcat'
+	[[ -z "${1}" ]] && ERROR=1
+	[[ ! -f "${2}" ]] && ERROR=1
+	[[ "${2%.gz}" != "${2}" ]] && mycat='zcat'
 
-	if [ "${ERROR}" = 1 ]
-	then
+	if [[ "${ERROR}" = 1 ]]; then
 		echo -e "\n"
 		eerror "getfilevar_noexec requires 2 variables, with the second a valid file."
 		eerror "   getfilevar_noexec <VARIABLE> <CONFIGFILE>"
@@ -293,7 +287,8 @@ _LINUX_CONFIG_EXISTS_DONE=
 # Helper funciton which returns an error before the function argument is run if no config exists
 linux_config_qa_check() {
 	local f="$1"
-	if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then
+
+	if [[ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]]; then
 		ewarn "QA: You called $f before any linux_config_exists!"
 		ewarn "QA: The return value of $f will NOT guaranteed later!"
 	fi
@@ -351,7 +346,6 @@ linux_config_path() {
 # This function verifies that the current kernel is configured (it checks against the existence of .config)
 # otherwise it dies.
 require_configured_kernel() {
-
 	[[ -n ${SKIP_KERNEL_CHECK} ]] && return
 
 	if ! use kernel_linux; then
@@ -365,6 +359,7 @@ require_configured_kernel() {
 		qeerror "it points to the necessary object directory so that it might find .config."
 		die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
 	fi
+
 	get_version || die "Unable to determine configured kernel version"
 }
 
@@ -445,7 +440,7 @@ kernel_is() {
 		die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
 	fi
 
-	# if we haven't determined the version yet, we need to.
+	# If we haven't determined the version yet, we need to.
 	linux-info_get_any_version
 
 	# Now we can continue
@@ -459,7 +454,7 @@ kernel_is() {
 	  eq) operator="-eq"; shift;;
 	   *) operator="-eq";;
 	esac
-	[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
+	[[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters"
 
 	ver_test \
 		"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
@@ -488,7 +483,7 @@ get_makefile_extract_function() {
 
 # @ECLASS_VARIABLE: get_version_warning_done
 # @INTERNAL
-# @DESCRIPTION: 
+# @DESCRIPTION:
 # Internal variable, so we know to only print the warning once.
 get_version_warning_done=
 
@@ -511,26 +506,25 @@ get_version() {
 
 	[[ -n ${SKIP_KERNEL_CHECK} ]] && return
 
-	# no need to execute this twice assuming KV_FULL is populated.
-	# we can force by unsetting KV_FULL
-	[ -n "${KV_FULL}" ] && return 0
+	# No need to execute this twice assuming KV_FULL is populated.
+	# We can force by unsetting KV_FULL.
+	[[ -n "${KV_FULL}" ]] && return 0
 
-	# if we dont know KV_FULL, then we need too.
-	# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR
+	# If we don't know KV_FULL, then we need to.
+	# Make sure KV_DIR isn't set since we need to work it out via KERNEL_DIR.
 	unset KV_DIR
 
 	# KV_DIR will contain the full path to the sources directory we should use
-	[ -z "${get_version_warning_done}" ] && \
+	[[ -z "${get_version_warning_done}" ]] && \
 	qeinfo "Determining the location of the kernel source code"
-	[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}"
+	[[ -d "${KERNEL_DIR}" ]] && KV_DIR="${KERNEL_DIR}"
 
-	if [ -z "${KV_DIR}" ]
-	then
-		if [ -z "${get_version_warning_done}" ]; then
+	if [[ -z "${KV_DIR}" ]]; then
+		if [[ -z "${get_version_warning_done}" ]]; then
 			get_version_warning_done=1
 			qewarn "Unable to find kernel sources at ${KERNEL_DIR}"
 			#qeinfo "This package requires Linux sources."
-			if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then
+			if [[ "${KERNEL_DIR}" == "/usr/src/linux" ]] ; then
 				qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, "
 				qeinfo "(or the kernel you wish to build against)."
 				qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location"
@@ -542,22 +536,21 @@ get_version() {
 	fi
 
 	# See if the kernel dir is actually an output dir. #454294
-	if [ -z "${KBUILD_OUTPUT}" -a -L "${KERNEL_DIR}/source" ]; then
+	if [[ -z "${KBUILD_OUTPUT}" && -L "${KERNEL_DIR}/source" ]]; then
 		KBUILD_OUTPUT=${KERNEL_DIR}
 		KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source")
 		KV_DIR=${KERNEL_DIR}
 	fi
 
-	if [ -z "${get_version_warning_done}" ]; then
+	if [[ -z "${get_version_warning_done}" ]]; then
 		qeinfo "Found kernel source directory:"
 		qeinfo "    ${KV_DIR}"
 	fi
 
 	kernel_get_makefile
 
-	if [[ ! -s ${KERNEL_MAKEFILE} ]]
-	then
-		if [ -z "${get_version_warning_done}" ]; then
+	if [[ ! -s ${KERNEL_MAKEFILE} ]]; then
+		if [[ -z "${get_version_warning_done}" ]]; then
 			get_version_warning_done=1
 			qeerror "Could not find a Makefile in the kernel source directory."
 			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
@@ -567,8 +560,9 @@ get_version() {
 
 	# OK so now we know our sources directory, but they might be using
 	# KBUILD_OUTPUT, and we need this for .config and localversions-*
-	# so we better find it eh?
-	# do we pass KBUILD_OUTPUT on the CLI?
+	# so we better find it, eh?
+	#
+	# Do we pass KBUILD_OUTPUT on the CLI?
 	local OUTPUT_DIR=${KBUILD_OUTPUT}
 
 	if [[ -z ${OUTPUT_DIR} ]]; then
@@ -579,17 +573,16 @@ get_version() {
 		OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}")
 	fi
 
-	# And contrary to existing functions I feel we shouldn't trust the
+	# And contrary to existing functions, I feel we shouldn't trust the
 	# directory name to find version information as this seems insane.
-	# So we parse ${KERNEL_MAKEFILE}.  
+	# So we parse ${KERNEL_MAKEFILE}.
 	KV_MAJOR=$(getfilevar VERSION "${KERNEL_MAKEFILE}")
 	KV_MINOR=$(getfilevar PATCHLEVEL "${KERNEL_MAKEFILE}")
 	KV_PATCH=$(getfilevar SUBLEVEL "${KERNEL_MAKEFILE}")
 	KV_EXTRA=$(getfilevar EXTRAVERSION "${KERNEL_MAKEFILE}")
 
-	if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ]
-	then
-		if [ -z "${get_version_warning_done}" ]; then
+	if [[ -z "${KV_MAJOR}" || -z "${KV_MINOR}" || -z "${KV_PATCH}" ]; then
+		if [[ -z "${get_version_warning_done}" ]]; then
 			get_version_warning_done=1
 			qeerror "Could not detect kernel version."
 			qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
@@ -597,9 +590,8 @@ get_version() {
 		return 1
 	fi
 
-	[ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
-	if [ -n "${KV_OUT_DIR}" ];
-	then
+	[[ -d "${OUTPUT_DIR}" ]] && KV_OUT_DIR="${OUTPUT_DIR}"
+	if [[ -n "${KV_OUT_DIR}" ]]; then
 		qeinfo "Found kernel object directory:"
 		qeinfo "    ${KV_OUT_DIR}"
 	fi
@@ -609,9 +601,9 @@ get_version() {
 	# Grab the kernel release from the output directory.
 	# TODO: we MUST detect kernel.release being out of date, and 'return 1' from
 	# this function.
-	if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then
+	if [[ -s "${KV_OUT_DIR}"/include/config/kernel.release ]]; then
 		KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release)
-	elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then
+	elif [[ -s "${KV_OUT_DIR}"/.kernelrelease ]]; then
 		KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease)
 	else
 		KV_LOCAL=
@@ -624,13 +616,13 @@ get_version() {
 	# Clear out KV_LOCAL in that case.
 	# TODO: this does not detect a change in the localversion part between
 	# kernel.release and the value that would be generated.
-	if [ "$KV_LOCAL" = "$tmplocal" ]; then
+	if [[ "${KV_LOCAL}" = "${tmplocal}" ]]; then
 		KV_LOCAL=
 	else
-		KV_LOCAL=$tmplocal
+		KV_LOCAL=${tmplocal}
 	fi
 
-	# and in newer versions we can also pull LOCALVERSION if it is set.
+	# and in newer versions, we can also pull LOCALVERSION if it is set.
 	# but before we do this, we need to find if we use a different object directory.
 	# This *WILL* break if the user is using localversions, but we assume it was
 	# caught before this if they are.
@@ -718,7 +710,7 @@ check_kernel_built() {
 		die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
 	fi
 
-	# if we haven't determined the version yet, we need to
+	# If we haven't determined the version yet, we need to
 
 	[[ -n ${SKIP_KERNEL_CHECK} ]] && return
 
@@ -731,8 +723,7 @@ check_kernel_built() {
 		versionh_path="include/linux/version.h"
 	fi
 
-	if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ]
-	then
+	if [[ ! -f "${KV_OUT_DIR}/${versionh_path}" ]]; then
 		eerror "These sources have not yet been prepared."
 		eerror "We cannot build against an unprepared tree."
 		eerror "To resolve this, please type the following:"
@@ -754,7 +745,7 @@ check_modules_supported() {
 		die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
 	fi
 
-	# if we haven't determined the version yet, we need too.
+	# If we haven't determined the version yet, we need to.
 	require_configured_kernel
 
 	if ! linux_chkconfig_builtin "MODULES"; then
@@ -774,12 +765,12 @@ check_extra_config() {
 
 	local config negate die error reworkmodulenames
 	local soft_errors_count=0 hard_errors_count=0 config_required=0
-	# store the value of the QA check, because otherwise we won't catch usages
+	# Store the value of the QA check, because otherwise we won't catch usages
 	# after if check_extra_config is called AND other direct calls are done
 	# later.
 	local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}"
 
-	# if we haven't determined the version yet, we need to
+	# If we haven't determined the version yet, we need to.
 	linux-info_get_any_version
 
 	# Determine if we really need a .config. The only time when we don't need
@@ -820,9 +811,8 @@ check_extra_config() {
 
 	ebegin "Checking for suitable kernel configuration options"
 
-	for config in ${CONFIG_CHECK}
-	do
-		# if we specify any fatal, ensure we honor them
+	for config in ${CONFIG_CHECK}; do
+		# If we specify any fatal, ensure we honor them
 		die=1
 		error=0
 		negate=0
@@ -919,7 +909,7 @@ check_zlibinflate() {
 		die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
 	fi
 
-	# if we haven't determined the version yet, we need to
+	# If we haven't determined the version yet, we need to.
 	require_configured_kernel
 
 	# although I restructured this code - I really really really dont support it!
@@ -951,15 +941,15 @@ check_zlibinflate() {
 
 	LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
 	LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
-	(( LINENO_AMOUNT = $LINENO_END - $LINENO_START ))
-	(( LINENO_END = $LINENO_END - 1 ))
+	(( LINENO_AMOUNT = ${LINENO_END} - ${LINENO_START} ))
+	(( LINENO_END = ${LINENO_END} - 1 ))
 	SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
 
 	# okay, now we have a list of symbols
 	# we need to check each one in turn, to see whether it is set or not
-	for x in $SYMBOLS ; do
-		if [ "${!x}" = "y" ]; then
-			# we have a winner!
+	for x in ${SYMBOLS} ; do
+		if [[ "${!x}" = "y" ]]; then
+			# We have a winner!
 			einfo "${x} ensures zlib is linked into your kernel - excellent"
 			return 0
 		fi
@@ -974,7 +964,7 @@ check_zlibinflate() {
 	eerror "Please ensure that you enable at least one of these options:"
 	eerror
 
-	for x in $SYMBOLS ; do
+	for x in ${SYMBOLS} ; do
 		eerror "  * $x"
 	done
 
@@ -997,7 +987,7 @@ linux-info_pkg_setup() {
 
 	linux-info_get_any_version
 
-	[[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config;
+	[[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config
 }
 
 # @FUNCTION: kernel_get_makefile
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes
  2022-12-25 19:17 [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Sam James
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 2/3] linux-info.eclass: " Sam James
@ 2022-12-25 19:17 ` Sam James
  2022-12-25 22:14   ` Ulrich Mueller
  2022-12-25 22:19 ` [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Ulrich Mueller
  2 siblings, 1 reply; 6+ messages in thread
From: Sam James @ 2022-12-25 19:17 UTC (permalink / raw
  To: gentoo-dev; +Cc: kernel, Sam James

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/kernel-2.eclass | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/eclass/kernel-2.eclass b/eclass/kernel-2.eclass
index 2cf88f0ff238..e13ed1a4f5ba 100644
--- a/eclass/kernel-2.eclass
+++ b/eclass/kernel-2.eclass
@@ -22,7 +22,7 @@
 # @DESCRIPTION:
 # Utilized for 32-bit userland on ppc64.
 
-# @ECLASS_VARIABLE: CKV 
+# @ECLASS_VARIABLE: CKV
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Used as a comparison kernel version, which is used when
@@ -187,36 +187,36 @@
 # Apply genpatches to kernel source. Provide any
 # combination of "base", "extras" or "experimental".
 
-# @ECLASS_VARIABLE: KERNEL_URI 
+# @ECLASS_VARIABLE: KERNEL_URI
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Upstream kernel src URI
 
-# @ECLASS_VARIABLE: KV 
+# @ECLASS_VARIABLE: KV
 # @DEFAULT_UNSET
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
 # Kernel Version (2.6.0-gentoo/2.6.0-test11-gentoo-r1)
 
-# @ECLASS_VARIABLE: KV_FULL 
+# @ECLASS_VARIABLE: KV_FULL
 # @DEFAULT_UNSET
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
 # Kernel full version
 
-# @ECLASS_VARIABLE: KV_MAJOR 
+# @ECLASS_VARIABLE: KV_MAJOR
 # @DEFAULT_UNSET
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
 # Kernel major version from <KV_MAJOR>.<KV_MINOR>.<KV_PATCH
 
-# @ECLASS_VARIABLE: KV_MINOR 
+# @ECLASS_VARIABLE: KV_MINOR
 # @DEFAULT_UNSET
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
 # Kernel minor version from <KV_MAJOR>.<KV_MINOR>.<KV_PATCH
 
-# @ECLASS_VARIABLE: KV_PATCH 
+# @ECLASS_VARIABLE: KV_PATCH
 # @DEFAULT_UNSET
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
@@ -227,12 +227,12 @@
 # @DESCRIPTION:
 # Default cflags if not already set
 
-# @ECLASS_VARIABLE: OKV  
+# @ECLASS_VARIABLE: OKV
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Original Kernel Version (2.6.0/2.6.0-test11)
 
-# @ECLASS_VARIABLE: RELEASE 
+# @ECLASS_VARIABLE: RELEASE
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Representative of the kernel release tag (-rc3/-git3)
@@ -261,15 +261,15 @@
 # @DESCRIPTION:
 # space delimetered list of patches to be applied to the kernel
 
-# @ECLASS_VARIABLE: UNIPATCH_LIST_DEFAULT 
+# @ECLASS_VARIABLE: UNIPATCH_LIST_DEFAULT
 # @INTERNAL
 # @DESCRIPTION:
 # Upstream kernel patch archive
 
-# @ECLASS_VARIABLE: UNIPATCH_LIST_GENPATCHES 
+# @ECLASS_VARIABLE: UNIPATCH_LIST_GENPATCHES
 # @INTERNAL
 # @DESCRIPTION:
-# List of genpatches archives to apply to the kernel 
+# List of genpatches archives to apply to the kernel
 
 # @ECLASS_VARIABLE: UNIPATCH_STRICTORDER
 # @DEFAULT_UNSET
@@ -646,7 +646,7 @@ kernel_is() {
 	  eq) operator="-eq"; shift;;
 	   *) operator="-eq";;
 	esac
-	[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
+	[[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters"
 
 	ver_test \
 		"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
@@ -1190,14 +1190,14 @@ unipatch() {
 		fi
 	done
 
-	#populate KPATCH_DIRS so we know where to look to remove the excludes
+	# Populate KPATCH_DIRS so we know where to look to remove the excludes
 	x=${KPATCH_DIR}
 	KPATCH_DIR=""
 	for i in $(find ${x} -type d | sort -n); do
 		KPATCH_DIR="${KPATCH_DIR} ${i}"
 	done
 
-	#so now lets get rid of the patchno's we want to exclude
+	# So now lets get rid of the patch numbers we want to exclude
 	UNIPATCH_DROP="${UNIPATCH_EXCLUDE} ${UNIPATCH_DROP}"
 	for i in ${UNIPATCH_DROP}; do
 		ebegin "Excluding Patch #${i}"
@@ -1224,7 +1224,7 @@ unipatch() {
 			# addition of a file with the same name as the symlink in the      #
 			# same location; this causes the dry-run to fail, see bug #507656. #
 			#                                                                  #
-			# https://bugs.gentoo.org/show_bug.cgi?id=507656                   #
+			# https://bugs.gentoo.org/507656                                   #
 			####################################################################
 			if [[ -n ${K_NODRYRUN} ]]; then
 				ebegin "Applying ${i/*\//} (-p1)"
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] [PATCH 2/3] linux-info.eclass: use consistent style
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 2/3] linux-info.eclass: " Sam James
@ 2022-12-25 21:28   ` Sam James
  0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2022-12-25 21:28 UTC (permalink / raw
  To: gentoo-dev; +Cc: kernel

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]



> On 25 Dec 2022, at 19:17, Sam James <sam@gentoo.org> wrote:
> 
> - Use Bash tests (i.e. [[ ]] instead of [ ])
> - Use consistent newlines for if/while
> - Drop unnecessary ; line terminators

There's a missing ] on one line which I've fixed locally.

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 358 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes Sam James
@ 2022-12-25 22:14   ` Ulrich Mueller
  0 siblings, 0 replies; 6+ messages in thread
From: Ulrich Mueller @ 2022-12-25 22:14 UTC (permalink / raw
  To: Sam James; +Cc: gentoo-dev, kernel

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

>>>>> On Sun, 25 Dec 2022, Sam James wrote:

> -	[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters"
> +	[[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters"

This might be somewhat misleading. The name of the function is just
${FUNCNAME}, I suppose? (Also, "Error in" is redundant in a die
message.)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style
  2022-12-25 19:17 [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Sam James
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 2/3] linux-info.eclass: " Sam James
  2022-12-25 19:17 ` [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes Sam James
@ 2022-12-25 22:19 ` Ulrich Mueller
  2 siblings, 0 replies; 6+ messages in thread
From: Ulrich Mueller @ 2022-12-25 22:19 UTC (permalink / raw
  To: Sam James; +Cc: gentoo-dev, kernel

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

>>>>> On Sun, 25 Dec 2022, Sam James wrote:

> +	[[ ${KV_MAJOR} -eq 2 && ${KV_MINOR} -gt 5 && ${KV_PATCH} -gt 5 ]] && \
>  		return 0 || return 1

Ouch. :)

The "&& return 0 || return 1" can be omitted.

>  }

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-25 22:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-25 19:17 [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Sam James
2022-12-25 19:17 ` [gentoo-dev] [PATCH 2/3] linux-info.eclass: " Sam James
2022-12-25 21:28   ` Sam James
2022-12-25 19:17 ` [gentoo-dev] [PATCH 3/3] kernel-2.eclass: minor whitespace fixes Sam James
2022-12-25 22:14   ` Ulrich Mueller
2022-12-25 22:19 ` [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style Ulrich Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox