Skip to content

Commit c041441

Browse files
committed
kbuild: package: add -e and -u options to some shell scripts
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 <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent c520908 commit c041441

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

scripts/package/builddeb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# specified in KDEB_HOOKDIR) that will be called on package install and
1111
# removal.
1212

13-
set -e
13+
set -eu
1414

1515
is_enabled() {
1616
grep -q "^$1=y" include/config/auto.conf

scripts/package/buildtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Wichert Akkerman <[email protected]>.
1212
#
1313

14-
set -e
14+
set -eu
1515

1616
#
1717
# Some variables and settings used throughout the script

scripts/package/gen-diff-patch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0-only
33

4+
set -eu
5+
46
diff_patch=$1
57

68
mkdir -p "$(dirname "${diff_patch}")"

scripts/package/install-extmod-build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0-only
33

4-
set -e
4+
set -eu
55

66
destdir=${1}
77

8-
test -n "${srctree}"
9-
test -n "${SRCARCH}"
10-
118
is_enabled() {
129
grep -q "^$1=y" include/config/auto.conf
1310
}

scripts/package/mkdebian

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Simple script to generate a debian/ directory for a Linux kernel.
66

7-
set -e
7+
set -eu
88

99
is_enabled() {
1010
grep -q "^$1=y" include/config/auto.conf
@@ -19,7 +19,7 @@ if_enabled_echo() {
1919
}
2020

2121
set_debarch() {
22-
if [ -n "$KBUILD_DEBARCH" ] ; then
22+
if [ "${KBUILD_DEBARCH:+set}" ]; then
2323
debarch="$KBUILD_DEBARCH"
2424
return
2525
fi
@@ -135,13 +135,21 @@ else
135135
fi
136136
maintainer="${name} <${email}>"
137137

138-
if [ "$1" = --need-source ]; then
139-
gen_source
140-
fi
138+
while [ $# -gt 0 ]; do
139+
case "$1" in
140+
--need-source)
141+
gen_source
142+
shift
143+
;;
144+
*)
145+
break
146+
;;
147+
esac
148+
done
141149

142150
# Some variables and settings used throughout the script
143151
version=$KERNELRELEASE
144-
if [ -n "$KDEB_PKGVERSION" ]; then
152+
if [ "${KDEB_PKGVERSION:+set}" ]; then
145153
packageversion=$KDEB_PKGVERSION
146154
else
147155
packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/scripts/build-version)
@@ -158,7 +166,7 @@ debarch=
158166
set_debarch
159167

160168
# Try to determine distribution
161-
if [ -n "$KDEB_CHANGELOG_DIST" ]; then
169+
if [ "${KDEB_CHANGELOG_DIST:+set}" ]; then
162170
distribution=$KDEB_CHANGELOG_DIST
163171
# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
164172
elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then

scripts/package/mkspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# Patched for non-x86 by Opencon (L) 2002 <[email protected]>
1010
#
1111

12+
set -eu
13+
1214
output=$1
1315

1416
mkdir -p "$(dirname "${output}")"

0 commit comments

Comments
 (0)