* [PATCH v7] scripts/config: honor $KBUILD_OUTPUT by default
@ 2026-10-06 16:11 Dmitry Voytik
2026-11-13 4:59 ` Nathan Chancellor
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Voytik @ 2026-10-06 16:11 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier
Cc: Nicolas Schier, linux-kernel, linux-kbuild, 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.
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:
make mrproper
export KBUILD_OUTPUT=.out
make defconfig
./scripts/config \
-e CONFIG_UBSAN
Error reported:
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
grep "CONFIG_UBSAN=y" $KBUILD_OUTPUT/.config && echo "FAIL"
./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 && echo "FAIL"
./scripts/config --file .out2/.my_config --refresh \
-e CONFIG_UBSAN
grep "CONFIG_UBSAN=y" .out2/.my_config && echo "OK"
ls .out/.out2 && echo "FAIL"
ls .out/.out && echo "FAIL"
Test --file can accept files with hyphen:
./scripts/config -d CONFIG_UBSAN
cp .out/.config -- -my_config
grep "CONFIG_UBSAN=y" -- -my_config && echo "FAIL"
./scripts/config --refresh \
-e CONFIG_UBSAN --file -my_config
grep "CONFIG_UBSAN=y" -- -my_config && echo "OK"
Signed-off-by: Dmitry Voytik <voytikd@gmail.com>
---
v7:
* Adressed https://sashiko.dev/#/patchset/20261006142337.821859-1-voytikd%40gmail.com
v6:
* Per Nathan Chancellor's suggestions, simplified
* https://lore.kernel.org/lkml/179121581235.2275809.12565811683284940522.b4-review@b4/
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/20260920064350.17999-1-voytikd@gmail.com/
---
scripts/config | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/scripts/config b/scripts/config
index 32428ea909c2..1e29e449077c 100755
--- a/scripts/config
+++ b/scripts/config
@@ -130,13 +130,15 @@ on_exit() {
trap on_exit EXIT
FN=.config
+
+
CMDS=()
while [[ $# -gt 0 ]]; do
if [ "$1" = "--file" ]; then
if [ "$2" = "" ]; then
usage
fi
- FN="$2"
+ FN=$(realpath -q -- "$2" || printf -- "%s\n" "$2")
shift 2
else
CMDS+=("$1")
@@ -144,6 +146,16 @@ while [[ $# -gt 0 ]]; do
fi
done
+# ignore $KBUILD_OUTPUT if "--file" option is present
+if [[ "$FN" == ".config" && -n "$KBUILD_OUTPUT" ]]; then
+ if [[ ! -d "$KBUILD_OUTPUT" ]]; then
+ echo "KBUILD_OUTPUT is set but does not exist or is not a " >&2
+ echo "directory. Create it before running $myname." >&2
+ exit 1
+ fi
+ FN=$(realpath -- "$KBUILD_OUTPUT")/"$FN"
+fi
+
set -- "${CMDS[@]}"
if [ "$1" = "" ] ; then
usage
@@ -200,7 +212,7 @@ while [ "$1" != "" ] ; do
;;
--state|-s)
- if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
+ if grep -q "# ${CONFIG_}$ARG is not set" "$FN" ; then
echo n
else
V="$(grep "^${CONFIG_}$ARG=" $FN)"
@@ -229,7 +241,7 @@ while [ "$1" != "" ] ; do
;;
--refresh)
- yes "" | make oldconfig KCONFIG_CONFIG=$FN
+ yes "" | make oldconfig KCONFIG_CONFIG="$FN"
;;
*)
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v7] scripts/config: honor $KBUILD_OUTPUT by default
2026-10-06 16:11 [PATCH v7] scripts/config: honor $KBUILD_OUTPUT by default Dmitry Voytik
@ 2026-11-13 4:59 ` Nathan Chancellor
2026-11-14 18:56 ` Nicolas Schier
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2026-11-13 4:59 UTC (permalink / raw)
To: Dmitry Voytik
Cc: Nathan Chancellor, Nicolas Schier, Nicolas Schier, linux-kernel,
linux-kbuild
Hi Dmitry,
On 2026-10-06 18:11 +0200, Dmitry Voytik wrote:
> 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).
I was finally able to sit down and look at this a little bit more. I
think we can avoid the use of realpath altogether, which would avoid
most of what Sashiko is complaining about. I tested the following diff
with your examples and they appear to pass without any issues. Please
give it a shot. I think we can drop most of the reproduction and
examples in the commit message. If you want to include them for others,
please put it below the '---' where you have the changelog, as I don't
think it needs to end up in git history.
diff --git a/scripts/config b/scripts/config
index 32428ea909c2..497551538433 100755
--- a/scripts/config
+++ b/scripts/config
@@ -144,6 +144,22 @@ while [[ $# -gt 0 ]]; do
fi
done
+# If no '--file' was specified, use KBUILD_OUTPUT as the base if it exists
+if [[ "$FN" = ".config" && -n "$KBUILD_OUTPUT" ]]; then
+ if [[ ! -d "$KBUILD_OUTPUT" ]]; then
+ echo "KBUILD_OUTPUT is set ('$KBUILD_OUTPUT') but does not exist or is not a directory." >&2
+ echo "Create it before running $myname or use '--file' to specify configuration file." >&2
+ exit 1
+ fi
+ FN="$KBUILD_OUTPUT/$FN"
+fi
+# Turn FN into an absolute path if it is relative so that '--refresh' works on
+# the correct file. This does not use realpath, as $FN may not exist yet.
+case "$FN" in
+ /*) ;;
+ *) FN="$PWD/$FN" ;;
+esac
+
set -- "${CMDS[@]}"
if [ "$1" = "" ] ; then
usage
@@ -200,10 +216,10 @@ while [ "$1" != "" ] ; do
;;
--state|-s)
- if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
+ if grep -q "# ${CONFIG_}$ARG is not set" "$FN" ; then
echo n
else
- V="$(grep "^${CONFIG_}$ARG=" $FN)"
+ V="$(grep "^${CONFIG_}$ARG=" "$FN")"
if [ $? != 0 ] ; then
echo undef
else
@@ -229,7 +245,7 @@ while [ "$1" != "" ] ; do
;;
--refresh)
- yes "" | make oldconfig KCONFIG_CONFIG=$FN
+ yes "" | make oldconfig KCONFIG_CONFIG="$FN"
;;
*)
--
Cheers,
Nathan
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v7] scripts/config: honor $KBUILD_OUTPUT by default
2026-11-13 4:59 ` Nathan Chancellor
@ 2026-11-14 18:56 ` Nicolas Schier
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Schier @ 2026-11-14 18:56 UTC (permalink / raw)
To: Nathan Chancellor; +Cc: Dmitry Voytik, linux-kernel, linux-kbuild
On Thu, Nov 12, 2026 at 09:59:06PM -0700, Nathan Chancellor wrote:
> Hi Dmitry,
>
> On 2026-10-06 18:11 +0200, Dmitry Voytik wrote:
> > 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).
>
> I was finally able to sit down and look at this a little bit more. I
> think we can avoid the use of realpath altogether, which would avoid
> most of what Sashiko is complaining about. I tested the following diff
> with your examples and they appear to pass without any issues. Please
> give it a shot.
Thanks, somehow the sashiko mail missed my inbox.
realpath on Linux uses '-E' behaviour by default, which is what we want:
check existence of all directory path components of the given path.
Adding the POSIX '-E' option explicitly should solve the non-Linux
issues.
As a follow-up, I would like to add support for $KCONFIG_CONFIG as well.
> I think we can drop most of the reproduction and
> examples in the commit message. If you want to include them for others,
> please put it below the '---' where you have the changelog, as I don't
> think it needs to end up in git history.
+1
But still thanks for providing the test examples, it was and is indeed
helpful for my follow-up tests.
>
> diff --git a/scripts/config b/scripts/config
> index 32428ea909c2..497551538433 100755
> --- a/scripts/config
> +++ b/scripts/config
> @@ -144,6 +144,22 @@ while [[ $# -gt 0 ]]; do
> fi
> done
>
> +# If no '--file' was specified, use KBUILD_OUTPUT as the base if it exists
> +if [[ "$FN" = ".config" && -n "$KBUILD_OUTPUT" ]]; then
> + if [[ ! -d "$KBUILD_OUTPUT" ]]; then
> + echo "KBUILD_OUTPUT is set ('$KBUILD_OUTPUT') but does not exist or is not a directory." >&2
> + echo "Create it before running $myname or use '--file' to specify configuration file." >&2
> + exit 1
> + fi
> + FN="$KBUILD_OUTPUT/$FN"
> +fi
> +# Turn FN into an absolute path if it is relative so that '--refresh' works on
> +# the correct file. This does not use realpath, as $FN may not exist yet.
> +case "$FN" in
> + /*) ;;
> + *) FN="$PWD/$FN" ;;
> +esac
> +
> set -- "${CMDS[@]}"
> if [ "$1" = "" ] ; then
> usage
> @@ -200,10 +216,10 @@ while [ "$1" != "" ] ; do
> ;;
>
> --state|-s)
> - if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then
> + if grep -q "# ${CONFIG_}$ARG is not set" "$FN" ; then
> echo n
> else
> - V="$(grep "^${CONFIG_}$ARG=" $FN)"
> + V="$(grep "^${CONFIG_}$ARG=" "$FN")"
> if [ $? != 0 ] ; then
> echo undef
> else
> @@ -229,7 +245,7 @@ while [ "$1" != "" ] ; do
> ;;
>
> --refresh)
> - yes "" | make oldconfig KCONFIG_CONFIG=$FN
> + yes "" | make oldconfig KCONFIG_CONFIG="$FN"
> ;;
>
> *)
>
> --
> Cheers,
> Nathan
>
Looks good to me, thanks.
Reviewed-by: Nicolas Schier <nsc@fjasle.eu>
--
Nicolas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-14 18:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-06 16:11 [PATCH v7] scripts/config: honor $KBUILD_OUTPUT by default Dmitry Voytik
2026-11-13 4:59 ` Nathan Chancellor
2026-11-14 18:56 ` Nicolas Schier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox