]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kbuild: package: add -e and -u options to some shell scripts
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 2 Jul 2024 18:02:42 +0000 (03:02 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Tue, 16 Jul 2024 07:06:18 +0000 (16:06 +0900)
Set -e to make these scripts fail on the first error.

Set -u because these scripts are invoked by Makefile, and do not work
properly without necessary variables defined.

I tweaked mkdebian to cope with optional environment variables.

Remove the explicit "test -n ..." from install-extmod-build.

Both options are described in POSIX. [1]

[1]: https://pubs.opengroup.org/onlinepubs/009604499/utilities/set.html

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
scripts/package/builddeb
scripts/package/buildtar
scripts/package/gen-diff-patch
scripts/package/install-extmod-build
scripts/package/mkdebian
scripts/package/mkspec

index e797ad360f7a5b0493892630b330c8084a7770b0..c1757db6aa8a8030f07c53ebf22b4b43fe4d3c80 100755 (executable)
@@ -10,7 +10,7 @@
 # specified in KDEB_HOOKDIR) that will be called on package install and
 # removal.
 
-set -e
+set -eu
 
 is_enabled() {
        grep -q "^$1=y" include/config/auto.conf
index eb67787f8673305ed104e1aac51d10909bfed651..cc87a473c01f4548335597e46b62f49fe232fa0d 100755 (executable)
@@ -11,7 +11,7 @@
 # Wichert Akkerman <wichert@wiggy.net>.
 #
 
-set -e
+set -eu
 
 #
 # Some variables and settings used throughout the script
index 8a98b7bb78a0c39d71d60cdb760d1d31b6ba9bab..f272f7770ea35ea360ac632cd8846d888cdc30fe 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-only
 
+set -eu
+
 diff_patch=$1
 
 mkdir -p "$(dirname "${diff_patch}")"
index 76e0765dfcd6ea23294be4d54329c1317dbddb37..8cc9e13403ae0a73f27d0754cedb7f80e3583108 100755 (executable)
@@ -1,13 +1,10 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-only
 
-set -e
+set -eu
 
 destdir=${1}
 
-test -n "${srctree}"
-test -n "${SRCARCH}"
-
 is_enabled() {
        grep -q "^$1=y" include/config/auto.conf
 }
index 83c6636fadb84b31f771c2116ae86c07a8a83613..f962d303502b7a596233205caaf016ea87c27019 100755 (executable)
@@ -4,7 +4,7 @@
 #
 # Simple script to generate a debian/ directory for a Linux kernel.
 
-set -e
+set -eu
 
 is_enabled() {
        grep -q "^$1=y" include/config/auto.conf
@@ -19,7 +19,7 @@ if_enabled_echo() {
 }
 
 set_debarch() {
-       if [ -n "$KBUILD_DEBARCH" ] ; then
+       if [ "${KBUILD_DEBARCH:+set}" ]; then
                debarch="$KBUILD_DEBARCH"
                return
        fi
@@ -135,13 +135,21 @@ else
 fi
 maintainer="${name} <${email}>"
 
-if [ "$1" = --need-source ]; then
-       gen_source
-fi
+while [ $# -gt 0 ]; do
+       case "$1" in
+       --need-source)
+               gen_source
+               shift
+               ;;
+       *)
+               break
+               ;;
+       esac
+done
 
 # Some variables and settings used throughout the script
 version=$KERNELRELEASE
-if [ -n "$KDEB_PKGVERSION" ]; then
+if [ "${KDEB_PKGVERSION:+set}" ]; then
        packageversion=$KDEB_PKGVERSION
 else
        packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/scripts/build-version)
@@ -158,7 +166,7 @@ debarch=
 set_debarch
 
 # Try to determine distribution
-if [ -n "$KDEB_CHANGELOG_DIST" ]; then
+if [ "${KDEB_CHANGELOG_DIST:+set}" ]; then
         distribution=$KDEB_CHANGELOG_DIST
 # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
 elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
index cffc2567bef2a1616762ba897836aa5b0b3c98a5..77d25dda37e35f575b780bb1002238b699fb4803 100755 (executable)
@@ -9,6 +9,8 @@
 #      Patched for non-x86 by Opencon (L) 2002 <opencon@rio.skydome.net>
 #
 
+set -eu
+
 output=$1
 
 mkdir -p "$(dirname "${output}")"