Skip to contentSkip to conversation

kheaders: use `command -v` to test for existence of `cpio`

PATCH In review Miguel Ojeda 2 participants 2 messages May 28, 2024 – May 29, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kheaders: use `command -v` to test for existence of `cpio`

Commit 13e1df09284d ("kheaders: explicitly validate existence of cpio command") added an explicit check for cpio using type.

However, type in dash (which is used in some popular distributions and base images as the shell script runner) prints the missing message to standard output, and thus no error is printed:

    $ bash -c 'type missing >/dev/null'
    bash: line 1: type: missing: not found
    $ dash -c 'type missing >/dev/null'
    $

For instance, this issue may be seen by loongarch builders, given its defconfig enables CONFIG_IKHEADERS since commit 9cc1df421f00 ("LoongArch:
Update Loongson-3 default config file").

Therefore, use command -v instead to have consistent behavior, and take the chance to provide a more explicit error.

---
 kernel/gen_kheaders.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/gen_kheaders.sh +6 -1
index 6d443ea22bb7..4ba5fd3d73ae 100755
@@ -14,7 +14,12 @@ include/
 arch/$SRCARCH/include/
 "
 
-type cpio > /dev/null
+if ! command -v cpio >/dev/null; then
+	echo >&2 "***"
+	echo >&2 "*** 'cpio' could not be found."
+	echo >&2 "***"
+	exit 1
+fi
 
 # Support incremental builds by skipping archive generation
 # if timestamps of files being archived are not changed.

base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0

Signature · 1 line
2.45.1
#1 lore raw
Quoted 44 lines · Miguel Ojeda

Commit 13e1df09284d ("kheaders: explicitly validate existence of cpio command") added an explicit check for cpio using type.

However, type in dash (which is used in some popular distributions and base images as the shell script runner) prints the missing message to standard output, and thus no error is printed:

    $ bash -c 'type missing >/dev/null'
    bash: line 1: type: missing: not found
    $ dash -c 'type missing >/dev/null'
    $

For instance, this issue may be seen by loongarch builders, given its defconfig enables CONFIG_IKHEADERS since commit 9cc1df421f00 ("LoongArch:
Update Loongson-3 default config file").

Therefore, use command -v instead to have consistent behavior, and take the chance to provide a more explicit error.

---
 kernel/gen_kheaders.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/gen_kheaders.sh +6 -1
index 6d443ea22bb7..4ba5fd3d73ae 100755
@@ -14,7 +14,12 @@ include/
 arch/$SRCARCH/include/
 "
 
-type cpio > /dev/null
+if ! command -v cpio >/dev/null; then
+       echo >&2 "***"
+       echo >&2 "*** 'cpio' could not be found."
+       echo >&2 "***"
+       exit 1
+fi
 
 # Support incremental builds by skipping archive generation
 # if timestamps of files being archived are not changed.
Quoted 4 lines

base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0 --
2.45.1

Ah, right.
'command -v' is more portable.

Applied to linux-kbuild.
Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada