kbuild: pahole-version: improve overall checking and error messages
PATCH v2 1/1 kbuild: pahole-version: improve overall checking and error messages
Like patch "rust: suppress error messages from CONFIG_{RUSTC,BINDGEN}_VERSION_TEXT" [1], do not assume the file existing and being executable implies executing it will succeed.
Instead, bail out if executing it fails for any reason, as well as if the program does not print to standard output what we are expecting from pahole --version. The script needs to ensure that it always returns an integer, since its output will go into a Kconfig int-type symbol.
In addition, check whether the program exists first, and provide error messages for each error condition, similar to how it is done in e.g. scripts/rust_is_available.sh.
For instance, currently pahole may be built for another architecture or may be a program we do not expect that fails:
$ echo 'bad' > bad-pahole
$ chmod u+x bad-pahole
$ make PAHOLE=./bad-pahole defconfig
...
./bad-pahole: 1: bad: not found
init/Kconfig:112: syntax error
init/Kconfig:112: invalid statementWith this applied, we get instead:
***
*** Running './bad-pahole' to check the pahole version failed with *** code 127. pahole will not be used.
***
...
$ grep CONFIG_PAHOLE_VERSION .config CONFIG_PAHOLE_VERSION=0
Similarly, pahole currently may be a program that returns successfully, but that does not print the version that we would expect:
$ echo 'echo' > bad-pahole
$ chmod u+x bad-pahole
$ make PAHOLE=./bad-pahole defconfig
...
init/Kconfig:114: syntax error
init/Kconfig:114: invalid statementWith this applied, we get instead:
***
*** pahole './bad-pahole' returned an unexpected version output. *** pahole will not be used.
***
...
$ grep CONFIG_PAHOLE_VERSION .config CONFIG_PAHOLE_VERSION=0
Finally, with this applied, if the program does not exist, we get:
$ make PAHOLE=./bad-pahole defconfig
...
***
*** pahole './bad-pahole' could not be found. pahole will not be used.
***
...
$ grep CONFIG_PAHOLE_VERSION .config
CONFIG_PAHOLE_VERSION=0---
v1: https://lore.kernel.org/all/[email protected]/
v2:
Reworked to catch successful programs that may not output what we expect from pahole as well as to do the checking step-by-step (for better error messages).
I didn't change the regular expression to reduce the changes (except adding p) -- it can be improved separately.
Also, please note that I added Nicolas as co-author since he proposed part of the solution, but he has not formally signed off yet.
scripts/pahole-version.sh | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
scripts/pahole-version.sh +27 -3
@@ -5,9 +5,33 @@ # # Prints pahole's version in a 3-digit form, such as 119 for v1.19. -if [ ! -x "$(command -v "$@")" ]; then - echo 0 +set -e +trap "echo 0; exit 1" EXIT + +if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used." + echo >&2 "***" + exit 1 +fi + +output=$("$@" --version 2>/dev/null) || code=$? +if [ -n "$code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$@' to check the pahole version failed with" + echo >&2 "*** code $code. pahole will not be used." + echo >&2 "***" + exit 1 +fi + +output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9]+)/\1\2/p') +if [ -z "${output}" ]; then + echo >&2 "***" + echo >&2 "*** pahole '$@' returned an unexpected version output." + echo >&2 "*** pahole will not be used." + echo >&2 "***" exit 1 fi -"$@" --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/' +echo "${output}" +trap EXIT
base-commit: 431c1646e1f86b949fa3685efc50b660a364c2b6 --
2.46.0
scripts/pahole-version.sh line 16
Quoted 7 lines · Miguel Ojeda
scripts/pahole-version.sh +6
-0+if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used." + echo >&2 "***" + exit 1 +fi
We may not want to print a warning in this case if this case/setup is too common, though.
Cheers,
Miguel
Quoted 11 lines · Miguel Ojeda
scripts/pahole-version.sh line 16
Quoted 7 lines · Miguel Ojeda
scripts/pahole-version.sh +6
-0+if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used." + echo >&2 "***" + exit 1 +fiWe may not want to print a warning in this case if this case/setup is too common, though.
yes, I think it's a good idea to skip to remove this one.
Kind regards,
Nicolas
Quoted 12 lines · Miguel Ojeda
scripts/pahole-version.sh line 16
Quoted 7 lines · Miguel Ojeda
scripts/pahole-version.sh +6
-0+if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used." + echo >&2 "***" + exit 1 +fiWe may not want to print a warning in this case if this case/setup is too common, though.
I am fine with your color (in case someone wants to run it manually?) as long as stderr is suppressed in Kconfig.
default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE) 2>/dev/null)
scripts/rust_is_available.sh is very verbose, but we are not annoyed while running Kconfig because the $(success ) macro suppressed stderr.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 73 lines · Miguel Ojeda
Like patch "rust: suppress error messages from CONFIG_{RUSTC,BINDGEN}_VERSION_TEXT" [1], do not assume the file existing and being executable implies executing it will succeed.
Instead, bail out if executing it fails for any reason, as well as if the program does not print to standard output what we are expecting from
pahole --version. The script needs to ensure that it always returns an integer, since its output will go into aKconfigint-type symbol.In addition, check whether the program exists first, and provide error messages for each error condition, similar to how it is done in e.g.
scripts/rust_is_available.sh.For instance, currently
paholemay be built for another architecture or may be a program we do not expect that fails:$ echo 'bad' > bad-pahole $ chmod u+x bad-pahole $ make PAHOLE=./bad-pahole defconfig ... ./bad-pahole: 1: bad: not found init/Kconfig:112: syntax error init/Kconfig:112: invalid statementWith this applied, we get instead:
***
*** Running './bad-pahole' to check the pahole version failed with *** code 127. pahole will not be used.
***
...
$ grepCONFIG_PAHOLE_VERSION.configCONFIG_PAHOLE_VERSION=0Similarly,
paholecurrently may be a program that returns successfully, but that does not print the version that we would expect:$ echo 'echo' > bad-pahole $ chmod u+x bad-pahole $ make PAHOLE=./bad-pahole defconfig ... init/Kconfig:114: syntax error init/Kconfig:114: invalid statementWith this applied, we get instead:
***
*** pahole './bad-pahole' returned an unexpected version output. *** pahole will not be used.
***
...
$ grepCONFIG_PAHOLE_VERSION.configCONFIG_PAHOLE_VERSION=0Finally, with this applied, if the program does not exist, we get:
$ make PAHOLE=./bad-pahole defconfig ... *** *** pahole './bad-pahole' could not be found. pahole will not be used. *** ... $ grep CONFIG_PAHOLE_VERSION .config CONFIG_PAHOLE_VERSION=0Co-developed-by Nicolas Schier <[email protected]>Signed-off-by Nicolas Schier <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>
Quoted 8 lines
Reworked to catch successful programs that may not output what we expect from pahole as well as to do the checking step-by-step (for better error messages).
I didn't change the regular expression to reduce the changes (except adding
p) -- it can be improved separately.Also, please note that I added Nicolas as co-author since he proposed part of the solution, but he has not formally signed off yet.
thanks, no objections.
Quoted 9 lines
scripts/pahole-version.sh | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)scripts/pahole-version.sh +0
-0@@ -5,9 +5,33 @@ #
scripts/pahole-version.sh line 13
Quoted 10 lines
scripts/pahole-version.sh +6
-2# Prints pahole's version in a 3-digit form, such as 119 for v1.19. -if [ ! -x "$(command -v "$@")" ]; then - echo 0 +set -e +trap "echo 0; exit 1" EXIT + +if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used."
shellcheck likes to have '$*' instead of '$@', but I can't think of a set of arguments which might cause problems.
Quoted 4 lines
scripts/pahole-version.sh +4
-0+ echo >&2 "***" + exit 1 +fi +
scripts/pahole-version.sh line 27
Quoted 10 lines
scripts/pahole-version.sh +10
-0+output=$("$@" --version 2>/dev/null) || code=$? +if [ -n "$code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$@' to check the pahole version failed with" + echo >&2 "*** code $code. pahole will not be used." + echo >&2 "***" + exit 1 +fi + +output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9]+)/\1\2/p')
I'd rather like to have
output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9][0-9])/\1\2/p')
here (thus, explicitly check against a two number subversion), so that we can detect also versions like 1.100 or 2.1 and bail out.
Kind regards,
Nicolas
Quoted 2 lines · Nicolas Schier
thanks, no objections.
Thanks for taking a look!
Quoted 6 lines
I'd rather like to have
output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9][0-9])/\1\2/p')here (thus, explicitly check against a two number subversion), so that we can detect also versions like 1.100 or 2.1 and bail out.
So I didn't change that here to avoid more changes in the same commit, but happy to do that if preferred.
However, do we want to make it too strict? i.e. I don't think it is very unexpected to get v1.100 or v2.1 -- it may not be what current pahole does or ever do, but I am not sure we gain much by being so strict.
(Similarly, for the ^..$ suggestion, it could be that pahole decides to to something like pahole v1.25, i.e. name version, like other programs).
Either way, I am happy -- I doubt pahole changes too much, and if it does, we can change this too.
Cheers,
Miguel
Quoted 14 lines · Miguel Ojeda
Quoted 2 lines · Nicolas Schier
thanks, no objections.
Thanks for taking a look!
Quoted 6 lines
I'd rather like to have
output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9][0-9])/\1\2/p')here (thus, explicitly check against a two number subversion), so that we can detect also versions like 1.100 or 2.1 and bail out.
Quoted 7 lines
So I didn't change that here to avoid more changes in the same commit, but happy to do that if preferred.
However, do we want to make it too strict? i.e. I don't think it is very unexpected to get v1.100 or v2.1 -- it may not be what current
paholedoes or ever do, but I am not sure we gain much by being so strict.
I am not sure whether pahole never releases v2.0
$ echo v2.0 | sed -nE 's/v([0-9]+)\.([0-9]+)/\1\2/p' 20
Not a syntax error, but the version comparison will not work correctly.
Quoted 11 lines
(Similarly, for the ^..$ suggestion, it could be that
paholedecides to to something likepahole v1.25, i.e.name version, like other programs).Either way, I am happy -- I doubt
paholechanges too much, and if it does, we can change this too.Cheers,
Miguel
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 3 lines · Miguel Ojeda
Like patch "rust: suppress error messages from
CONFIG_{RUSTC,BINDGEN}_VERSION_TEXT" [1],
Better to point the commit instead of the patch in ML.
Like commit 5ce86c6c8613 ("rust: suppress error messages from CONFIG_{RUSTC,BINDGEN}_VERSION_TEXT"),
Quoted 129 lines
do not assume the file existing
and being executable implies executing it will succeed.Instead, bail out if executing it fails for any reason, as well as if the program does not print to standard output what we are expecting from
pahole --version. The script needs to ensure that it always returns an integer, since its output will go into aKconfigint-type symbol.In addition, check whether the program exists first, and provide error messages for each error condition, similar to how it is done in e.g.
scripts/rust_is_available.sh.For instance, currently
paholemay be built for another architecture or may be a program we do not expect that fails:$ echo 'bad' > bad-pahole $ chmod u+x bad-pahole $ make PAHOLE=./bad-pahole defconfig ... ./bad-pahole: 1: bad: not found init/Kconfig:112: syntax error init/Kconfig:112: invalid statementWith this applied, we get instead:
***
*** Running './bad-pahole' to check the pahole version failed with *** code 127. pahole will not be used.
***
...
$ grepCONFIG_PAHOLE_VERSION.configCONFIG_PAHOLE_VERSION=0Similarly,
paholecurrently may be a program that returns successfully, but that does not print the version that we would expect:$ echo 'echo' > bad-pahole $ chmod u+x bad-pahole $ make PAHOLE=./bad-pahole defconfig ... init/Kconfig:114: syntax error init/Kconfig:114: invalid statementWith this applied, we get instead:
***
*** pahole './bad-pahole' returned an unexpected version output. *** pahole will not be used.
***
...
$ grepCONFIG_PAHOLE_VERSION.configCONFIG_PAHOLE_VERSION=0Finally, with this applied, if the program does not exist, we get:
$ make PAHOLE=./bad-pahole defconfig ... *** *** pahole './bad-pahole' could not be found. pahole will not be used. *** ... $ grep CONFIG_PAHOLE_VERSION .config CONFIG_PAHOLE_VERSION=0Co-developed-by Nicolas Schier <[email protected]>Signed-off-by Nicolas Schier <[email protected]>Signed-off-by Miguel Ojeda <[email protected]>---
v1: https://lore.kernel.org/all/[email protected]/
v2:Reworked to catch successful programs that may not output what we expect from pahole as well as to do the checking step-by-step (for better error messages).
I didn't change the regular expression to reduce the changes (except adding
p) -- it can be improved separately.Also, please note that I added Nicolas as co-author since he proposed part of the solution, but he has not formally signed off yet.
scripts/pahole-version.sh | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)scripts/pahole-version.sh +27
-3@@ -5,9 +5,33 @@ # # Prints pahole's version in a 3-digit form, such as 119 for v1.19. -if [ ! -x "$(command -v "$@")" ]; then - echo 0 +set -e +trap "echo 0; exit 1" EXIT + +if ! command -v "$@" >/dev/null; then + echo >&2 "***" + echo >&2 "*** pahole '$@' could not be found. pahole will not be used." + echo >&2 "***" + exit 1 +fi + +output=$("$@" --version 2>/dev/null) || code=$? +if [ -n "$code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$@' to check the pahole version failed with" + echo >&2 "*** code $code. pahole will not be used." + echo >&2 "***" + exit 1 +fi + +output=$(echo "$output" | sed -nE 's/v([0-9]+)\.([0-9]+)/\1\2/p') +if [ -z "${output}" ]; then + echo >&2 "***" + echo >&2 "*** pahole '$@' returned an unexpected version output." + echo >&2 "*** pahole will not be used." + echo >&2 "***" exit 1 fi -"$@" --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/' +echo "${output}" +trap EXITbase-commit:
431c1646e1f86b949fa3685efc50b660a364c2b6--
2.46.0
Signature · 2 lines
Best Regards Masahiro Yamada