scripts/config: honor $KBUILD_OUTPUT by default
PATCH v5 1/1 scripts/config: honor $KBUILD_OUTPUT by default
If $KBUILD_OUTPUT is set, use it by default if --file is not passed.
Fix the issue when the script silently updates a stale .config in the root directory, while the user expects ${KBUILD_OUTPUT}/.config to be updated.
Handle properly if the config file is a relative path.
The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how the Makefile and other tools work (e.g., scripts/diffconfig).
How to reproduce the issue:
rm .config export KBUILD_OUTPUT=.out make defconfig ./scripts/config \ -e CONFIG_UBSAN grep: .config: No such file or directory
How the patch was tested:
make mrproper export KBUILD_OUTPUT=.out make defconfig grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config || echo "OK"
Test the basic usage:
./scripts/config -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"
Test --refresh picks up correct config file by using $KBUILD_OUTPUT:
./scripts/config -d CONFIG_UBSAN ./scripts/config --refresh -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"
Test --file takes precedence over $KBUILD_OUTPUT and a relative path is handled properly:
./scripts/config -d CONFIG_UBSAN mkdir .out2 cp .out/.config .out2/.my_config grep "CONFIG_UBSAN=y" .out2/.my_config ./scripts/config --file .out2/.my_config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" .out2/.my_config && echo "OK" ls .out/.out2 || echo "OK" ls .out/.out || echo "OK"
Test --file can accept files with hyphen:
./scripts/config -d CONFIG_UBSAN cp .out/.config -- -my_config grep "CONFIG_UBSAN=y" -- -my_config || echo "OK" ./scripts/config --refresh \ -e CONFIG_UBSAN --file -my_config grep "CONFIG_UBSAN=y" -- -my_config && echo "OK"
---
v5:
- Per Nathan Chancellor's suggestion, improved handling $FN path by realpath
- https://lore.kernel.org/lkml/179097210878.309835.10523307262544578337.b4-review@b4/
- Documented the new test scenario in the git commit message
v4:
- Addressed Nicolas Schier's comments - dropped the change how '--refresh' is handled
- Implemented conversion of $FN to the absolute path which helps with '--refresh' and relative paths
- Documented testing steps in the commit message
v3:
- Added an example in the commit message how to reproduce the issue
v2:
- Addressed comments by sashiko:
- https://sashiko.dev/#/patchset/20260920064350.17999-1-voytikd%40gmail.com
- use basename when --refresh is used
- remove echo which can be misleading when --file is passed
v1:
- https://lore.kernel.org/all/[email protected]/
--- scripts/config | 5 +++++ 1 file changed, 5 insertions(+)
scripts/config +5 -0
@@ -130,6 +130,10 @@ on_exit() { trap on_exit EXIT FN=.config +if [ -n "${KBUILD_OUTPUT}" ]; then + FN=${KBUILD_OUTPUT}/${FN} +fi + CMDS=() while [[ $# -gt 0 ]]; do if [ "$1" = "--file" ]; then
@@ -143,6 +147,7 @@ while [[ $# -gt 0 ]]; do shift fi done +FN=$(realpath -q -- "$FN" || echo "$FN") set -- "${CMDS[@]}" if [ "$1" = "" ] ; then
Signature · 1 line
2.55.0
Nathan Chancellor
maintainerHi Dmitry,
Quoted 96 lines
If $KBUILD_OUTPUT is set, use it by default if --file is not passed.
Fix the issue when the script silently updates a stale .config in the root directory, while the user expects ${KBUILD_OUTPUT}/.config to be updated.
Handle properly if the config file is a relative path.The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how the
Makefileand other tools work (e.g.,scripts/diffconfig).How to reproduce the issue:
rm .config export KBUILD_OUTPUT=.out make defconfig ./scripts/config \ -e CONFIG_UBSAN grep: .config: No such file or directoryHow the patch was tested:
make mrproper export KBUILD_OUTPUT=.out make defconfig grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config || echo "OK"Test the basic usage:
./scripts/config -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"Test --refresh picks up correct config file by using $KBUILD_OUTPUT:
./scripts/config -d CONFIG_UBSAN ./scripts/config --refresh -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"Test --file takes precedence over $KBUILD_OUTPUT and a relative path is handled properly:
./scripts/config -d CONFIG_UBSAN mkdir .out2 cp .out/.config .out2/.my_config grep "CONFIG_UBSAN=y" .out2/.my_config ./scripts/config --file .out2/.my_config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" .out2/.my_config && echo "OK" ls .out/.out2 || echo "OK" ls .out/.out || echo "OK"Test --file can accept files with hyphen:
./scripts/config -d CONFIG_UBSAN cp .out/.config -- -my_config grep "CONFIG_UBSAN=y" -- -my_config || echo "OK" ./scripts/config --refresh \ -e CONFIG_UBSAN --file -my_config grep "CONFIG_UBSAN=y" -- -my_config && echo "OK"Signed-off-by Dmitry Voytik <[email protected]>---
v5:
- Per Nathan Chancellor's suggestion, improved handling $FN path by realpath
- https://lore.kernel.org/lkml/179097210878.309835.10523307262544578337.b4-review@b4/
- Documented the new test scenario in the git commit message
v4:
- Addressed Nicolas Schier's comments - dropped the change how '--refresh' is handled
- Implemented conversion of $FN to the absolute path which helps with '--refresh' and relative paths
- Documented testing steps in the commit message
v3:
- Added an example in the commit message how to reproduce the issue
v2:
- Addressed comments by sashiko:
- https://sashiko.dev/#/patchset/20260920064350.17999-1-voytikd%40gmail.com
- use basename when --refresh is used
- remove echo which can be misleading when --file is passed
v1:
- https://lore.kernel.org/all/[email protected]/--- scripts/config | 5 +++++ 1 file changed, 5 insertions(+)scripts/config +4
-0@@ -130,6 +130,10 @@ on_exit() { trap on_exit EXIT FN=.config +if [ -n "${KBUILD_OUTPUT}" ]; then + FN=${KBUILD_OUTPUT}/${FN} +fi + CMDS=() while [[ $# -gt 0 ]]; do if [ "$1" = "--file" ]; then
scripts/config while [[ $# -gt 0 ]]; do · line 150
Quoted 4 lines
scripts/config +1
-0@@ -143,6 +147,7 @@ while [[ $# -gt 0 ]]; do shift fi done +FN=$(realpath -q -- "$FN" || echo "$FN")
Sashiko has some further complaints about this:
https://sashiko.dev/#/patchset/[email protected]
Due to travel and Linux Plumbers, I am not sure I will be able to think about the best way to resolve this before I finalize the Kbuild tree for 7.4, so this may need to be deferred until after 7.4-rc1 is released (i.e., it will target 7.5). One option that immediately comes to mind is requiring $KBUILD_OUTPUT to exist already and only running realpath on $KBUILD_OUTPUT, which would leave the script unchanged for the case of $KBUILD_OUTPUT being unset, which seems safer to me:
if [ -n "$KBUILD_OUTPUT" ]; then
if [ ! -d "$KBUILD_OUTPUT" ]; then
echo "KBUILD_OUTPUT is set but does not exist or is not a directory, create it before running $myname" >&2
exit 1
fi
FN=$(realpath "$KBUILD_OUTPUT")/$FNfi
This would leave a relative '--file' value + KBUILD_OUTPUT + '--refresh' in a weird state still but it appears that commit f757f6011c92 ("kbuild:
fix argument parsing in scripts/config") got that wrong almost two years ago so it doesn't feel like it is worth caring about that until someone actually complains about it (but I might be missing something).
Signature · 2 lines
Cheers, Nathan
Hi Nathan,
Thanks again for looking into this.
Quoted 106 lines · Nathan Chancellor
Hi Dmitry,
Quoted 96 lines
If $KBUILD_OUTPUT is set, use it by default if --file is not passed.
Fix the issue when the script silently updates a stale .config in the root directory, while the user expects ${KBUILD_OUTPUT}/.config to be updated.
Handle properly if the config file is a relative path.The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how the
Makefileand other tools work (e.g.,scripts/diffconfig).How to reproduce the issue:
rm .config
export KBUILD_OUTPUT=.out
make defconfig
./scripts/config\
-eCONFIG_UBSAN
grep: .config: No such file or directoryHow the patch was tested:
make mrproper export KBUILD_OUTPUT=.out make defconfig grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config || echo "OK"Test the basic usage:
./scripts/config-eCONFIG_UBSAN
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"Test --refresh picks up correct config file by using $KBUILD_OUTPUT:
./scripts/config -d CONFIG_UBSAN ./scripts/config --refresh -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "OK"Test --file takes precedence over $KBUILD_OUTPUT and a relative path is handled properly:
./scripts/config -d CONFIG_UBSAN mkdir .out2 cp .out/.config .out2/.my_config grep "CONFIG_UBSAN=y" .out2/.my_config ./scripts/config --file .out2/.my_config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" .out2/.my_config && echo "OK" ls .out/.out2 || echo "OK" ls .out/.out || echo "OK"Test --file can accept files with hyphen:
./scripts/config -d CONFIG_UBSAN cp .out/.config -- -my_config grep "CONFIG_UBSAN=y" -- -my_config || echo "OK" ./scripts/config --refresh \ -e CONFIG_UBSAN --file -my_config grep "CONFIG_UBSAN=y" -- -my_config && echo "OK"Signed-off-by Dmitry Voytik <[email protected]>---
v5:
- Per Nathan Chancellor's suggestion, improved handling $FN path by realpath
- https://lore.kernel.org/lkml/179097210878.309835.10523307262544578337.b4-review@b4/
- Documented the new test scenario in the git commit message
v4:
- Addressed Nicolas Schier's comments - dropped the change how '--refresh' is handled
- Implemented conversion of $FN to the absolute path which helps with '--refresh' and relative paths
- Documented testing steps in the commit message
v3:
- Added an example in the commit message how to reproduce the issue
v2:
- Addressed comments by sashiko:
- https://sashiko.dev/#/patchset/20260920064350.17999-1-voytikd%40gmail.com
- use basename when --refresh is used
- remove echo which can be misleading when --file is passed
v1:
- https://lore.kernel.org/all/[email protected]/--- scripts/config | 5 +++++ 1 file changed, 5 insertions(+)scripts/config +4
-0@@ -130,6 +130,10 @@ on_exit() { trap on_exit EXIT FN=.config +if [ -n "${KBUILD_OUTPUT}" ]; then + FN=${KBUILD_OUTPUT}/${FN} +fi + CMDS=() while [[ $# -gt 0 ]]; do if [ "$1" = "--file" ]; thenscripts/config while [[ $# -gt 0 ]]; do · line 150
Quoted 4 lines
scripts/config +1
-0@@ -143,6 +147,7 @@ while [[ $# -gt 0 ]]; do shift fi done +FN=$(realpath -q -- "$FN" || echo "$FN")Sashiko has some further complaints about this:
Quoted 1 line
I saw this, but I thought other *NIX environments were not supported -- only those based on GNU coreutils.
Sashiko's comment on filename that can break echo was a bit contrived IMHO. Anyhow, lesson learned, next time I'll make sure there is zero sashiko's complaints :)
Quoted 1 line
Due to travel and Linux Plumbers,
Have fun!
Quoted 4 lines
I am not sure I will be able to think
about the best way to resolve this before I finalize theKbuildtree for 7.4, so this may need to be deferred until after 7.4-rc1 is released (i.e., it will target 7.5).
I understand. Thank you for your work!
Quoted 5 lines
One option that immediately comes to mind is
requiring $KBUILD_OUTPUT to exist already and only running realpath on $KBUILD_OUTPUT, which would leave the script unchanged for the case of $KBUILD_OUTPUT being unset, which seems safer to me:
Quoted 7 lines
if [ -n "$KBUILD_OUTPUT" ]; then
if [ ! -d "$KBUILD_OUTPUT" ]; then echo "KBUILD_OUTPUT is set but does not exist or is not a directory, create it before running $myname" >&2 exit 1 fi FN=$(realpath "$KBUILD_OUTPUT")/$FNfi
I like this approach. Let me try that. If sashiko doesn't complain, I'll post a v6 patch.
Quoted 9 lines
This would leave a relative '--file' value +
KBUILD_OUTPUT+ '--refresh' in a weird state still but it appears that commitf757f6011c92("kbuild:
fix argument parsing inscripts/config") got that wrong almost two years ago so it doesn't feel like it is worth caring about that until someone actually complains about it (but I might be missing something).--
Cheers,
Nathan
Thanks and best regards,
Dmitry Voytik.