scripts/config: honor $KBUILD_OUTPUT by default
PATCH v3 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.
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
---
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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/config +5 -1
@@ -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
@@ -229,7 +233,7 @@ while [ "$1" != "" ] ; do ;; --refresh) - yes "" | make oldconfig KCONFIG_CONFIG=$FN + yes "" | make oldconfig KCONFIG_CONFIG=$(basename $FN) ;; *)
Signature · 1 line
2.55.0
Nicolas Schier
maintainerQuoted 48 lines · Dmitry Voytik
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.
The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how theMakefileand 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 directorySigned-off-by Dmitry Voytik <[email protected]>---
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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)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 [ "$1" != "" ] ; do · line 236
Quoted 5 lines
scripts/config +1
-1@@ -229,7 +233,7 @@ while [ "$1" != "" ] ; do ;; --refresh) - yes "" | make oldconfig KCONFIG_CONFIG=$FN + yes "" | make oldconfig KCONFIG_CONFIG=$(basename $FN)
Thanks for attempting to fix the '--refresh' option. But this way, this may lead to very unexpected behaviour, as it regardlessly modifies the path to the config file, even if it was specified via --file.
If --file is given, it should take precedence over any KBUILD_OUTPUT (or KCONFIG_CONFIG) from the environment and not be changed unrequested.
It would be a tiny bit nicer to just strip the KBUILD_OUTPUT path from FN, e.g. (untested):
yes "" | make oldconfig KCONFIG_CONFIG="${FN#${KBUILD_OUTPUT}/}"But I am still not feeling happy with that.
Signature · 1 line
Nicolas
Hi Nicolas,
Thank you for taking your time and reviewing the patch.
Quoted 60 lines · Nicolas Schier
Quoted 48 lines · Dmitry Voytik
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.
The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how theMakefileand 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 directorySigned-off-by Dmitry Voytik <[email protected]>---
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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)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 [ "$1" != "" ] ; do · line 236
Quoted 5 lines
scripts/config +1
-1@@ -229,7 +233,7 @@ while [ "$1" != "" ] ; do ;; --refresh) - yes "" | make oldconfig KCONFIG_CONFIG=$FN + yes "" | make oldconfig KCONFIG_CONFIG=$(basename $FN)Thanks for attempting to fix the '--refresh' option. But this way, this may lead to very unexpected behaviour, as it regardlessly modifies the path to the config file, even if it was specified via --file.
Quoted 2 lines
If --file is given, it should take precedence over any
KBUILD_OUTPUT(orKCONFIG_CONFIG) from the environment and not be changed unrequested.
Thanks. I misunderstood what KBUILD_OUTPUT really means. For some reason, I thought it should be a filename and not a full path. The documentation entry is a bit vague on it.
Quoted 6 lines
It would be a tiny bit nicer to just strip the
KBUILD_OUTPUTpath from FN, e.g. (untested):yes "" | make oldconfig KCONFIG_CONFIG="${FN#${KBUILD_OUTPUT}/}"But I am still not feeling happy with that.
Thanks for the suggestion! So, what I did - I just completely dropped the second change hunk, i.e. kept it as is:
yes "" | make oldconfig KCONFIG_CONFIG=$FN
I tested the following three scenarios and it looks like it works as expected:
make mrproper
export KBUILD_OUTPUT=.out
make defconfig
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config
# test basic use case:
./scripts/config \
-e CONFIG_UBSAN
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config
./scripts/config -d CONFIG_UBSAN# test --refresh picks up correct config file by using $KBUILD_OUTPUT
./scripts/config --refresh \
-e CONFIG_UBSAN
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config
./scripts/config -d CONFIG_UBSAN# test --file takes precedence over $KBUILD_OUTPUT
cp .out/.config .my_config
grep "CONFIG_UBSAN=y" .my_config
./scripts/config --file $(pwd)/.my_config --refresh \
-e CONFIG_UBSAN
grep "CONFIG_UBSAN=y" .my_configIf you are fine with the above, I can send v4 with adding the above testing steps into the commit message.
Thanks!
Quoted 2 lines
--
Nicolas
Signature · 2 lines
Best Regards, Dmitry Voytik.
Nicolas Schier
maintainerQuoted 102 lines · Dmitry Voytik
Hi Nicolas,
Thank you for taking your time and reviewing the patch.
Quoted 60 lines · Nicolas Schier
Quoted 48 lines · Dmitry Voytik
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.
The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how theMakefileand 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 directorySigned-off-by Dmitry Voytik <[email protected]>---
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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)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 [ "$1" != "" ] ; do · line 236
Quoted 5 lines
scripts/config +1
-1@@ -229,7 +233,7 @@ while [ "$1" != "" ] ; do ;; --refresh) - yes "" | make oldconfig KCONFIG_CONFIG=$FN + yes "" | make oldconfig KCONFIG_CONFIG=$(basename $FN)Thanks for attempting to fix the '--refresh' option. But this way, this may lead to very unexpected behaviour, as it regardlessly modifies the path to the config file, even if it was specified via --file.
Quoted 2 lines
If --file is given, it should take precedence over any
KBUILD_OUTPUT(orKCONFIG_CONFIG) from the environment and not be changed unrequested.Thanks. I misunderstood what
KBUILD_OUTPUTreally means. For some reason, I thought it should be a filename and not a full path. The documentation entry is a bit vague on it.Quoted 6 lines
It would be a tiny bit nicer to just strip the
KBUILD_OUTPUTpath from FN, e.g. (untested):yes "" | make oldconfig KCONFIG_CONFIG="${FN#${KBUILD_OUTPUT}/}"But I am still not feeling happy with that.
Thanks for the suggestion! So, what I did - I just completely dropped the second change hunk, i.e. kept it as is:
yes "" | make oldconfig KCONFIG_CONFIG=$FNI tested the following three scenarios and it looks like it works as expected:
make mrproper
export KBUILD_OUTPUT=.out
make defconfig
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config# test basic use case: ./scripts/config \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config ./scripts/config -d CONFIG_UBSAN# test --refresh picks up correct config file by using $KBUILD_OUTPUT ./scripts/config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config ./scripts/config -d CONFIG_UBSAN
Quoted 6 lines
# test --file takes precedence over $KBUILD_OUTPUT
cp .out/.config .my_config
grep "CONFIG_UBSAN=y" .my_config
./scripts/config --file $(pwd)/.my_config --refresh \
-e CONFIG_UBSAN
grep "CONFIG_UBSAN=y" .my_configThis one shows one of the problems with scripts/config: while the script itself handles relative paths to --file FILE from the current working directory, a call of Kbuild changes the working directory to $(KBUILD_OUTOUT) and realtive paths in KCONFIG_CONFIG are resolved from there.
I don't have a solution in mind, that fits it all. But I think it's important to not make things worse (or more unexpected) than before, by accident.
Quoted 2 lines
If you are fine with the above, I can send v4 with adding the above testing steps into the commit message.
yeah, please send a v4 and then let's see what we'll do with it, ok?
Thanks and kind regards,
Nicolas
Hi Nicolas,
Thanks for the review!
Quoted 111 lines · Nicolas Schier
Quoted 102 lines · Dmitry Voytik
Hi Nicolas,
Thank you for taking your time and reviewing the patch.
Quoted 60 lines · Nicolas Schier
Quoted 48 lines · Dmitry Voytik
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.
The problem can be worked around with --file, but this is easy to miss, and is inconsistent with how theMakefileand 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 directorySigned-off-by Dmitry Voytik <[email protected]>---
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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)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 [ "$1" != "" ] ; do · line 236
Quoted 5 lines
scripts/config +1
-1@@ -229,7 +233,7 @@ while [ "$1" != "" ] ; do ;; --refresh) - yes "" | make oldconfig KCONFIG_CONFIG=$FN + yes "" | make oldconfig KCONFIG_CONFIG=$(basename $FN)Thanks for attempting to fix the '--refresh' option. But this way, this may lead to very unexpected behaviour, as it regardlessly modifies the path to the config file, even if it was specified via --file.
Quoted 2 lines
If --file is given, it should take precedence over any
KBUILD_OUTPUT(orKCONFIG_CONFIG) from the environment and not be changed unrequested.Thanks. I misunderstood what
KBUILD_OUTPUTreally means. For some reason, I thought it should be a filename and not a full path. The documentation entry is a bit vague on it.Quoted 6 lines
It would be a tiny bit nicer to just strip the
KBUILD_OUTPUTpath from FN, e.g. (untested):yes "" | make oldconfig KCONFIG_CONFIG="${FN#${KBUILD_OUTPUT}/}"But I am still not feeling happy with that.
Thanks for the suggestion! So, what I did - I just completely dropped the second change hunk, i.e. kept it as is:
yes "" | make oldconfig KCONFIG_CONFIG=$FNI tested the following three scenarios and it looks like it works as expected:
make mrproper
export KBUILD_OUTPUT=.out
make defconfig
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config# test basic use case: ./scripts/config \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config ./scripts/config -d CONFIG_UBSAN# test --refresh picks up correct config file by using $KBUILD_OUTPUT ./scripts/config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config ./scripts/config -d CONFIG_UBSANQuoted 6 lines
# test --file takes precedence over $KBUILD_OUTPUT cp .out/.config .my_config grep "CONFIG_UBSAN=y" .my_config ./scripts/config --file $(pwd)/.my_config --refresh \ -e CONFIG_UBSAN grep "CONFIG_UBSAN=y" .my_config
Quoted 5 lines
This one shows one of the problems with
scripts/config: while the script itself handles relative paths to --file FILE from the current working directory, a call ofKbuildchanges the working directory to $(KBUILD_OUTOUT) and realtive paths inKCONFIG_CONFIGare resolved from there.
Indeed, with the patch, if I pass a relative path, it creates the config file in an unexpected place:
make mrproper
export KBUILD_OUTPUT=.out
make defconfig
mkdir .out2
cp .out/.config .out2/.my_config
./scripts/config --file .out2/.my_config \
--refresh \
-e CONFIG_UBSAN
ls .out/.out2/.my_configAlso, apparently, the following test case with --refresh misbehaves:
./scripts/config --refresh \
-e CONFIG_UBSANIt creates .out/.out/.config :)
I decided to always enforce converting $FN to the absolute path:
diff --git a/scripts/config b/scripts/config
index 4e29c3084fec..0b28fc498195 100755
--- a/scripts/config
+++ b/scripts/config
@@ -147,6 +147,7 @@ while [[ $# -gt 0 ]]; do
shift
fi
done
+FN=$(realpath "$FN")
set -- "${CMDS[@]}"
if [ "$1" = "" ] ; thenWith this change, all tests pass, no side effects as it seems.
Quoted 8 lines
I don't have a solution in mind, that fits it all. But I think it's important to not make things worse (or more unexpected) than before, by accident.
Quoted 2 lines
If you are fine with the above, I can send v4 with adding the above testing steps into the commit message.
yeah, please send a v4 and then let's see what we'll do with it, ok?
I'll send a v4 patch.
Thanks for the review!
Quoted 2 lines
Thanks and kind regards,
Nicolas
Best Regards,
Dmitry Voytik.