Re: [PATCH v8] scripts/config: honor $KBUILD_OUTPUT by default
From: Nathan Chancellor
Date: Wed Nov 18 2026 - 03:10:34 EST
On Tue, Nov 17, 2026 at 07:25:17PM +0000, Julian Braha wrote:
> On 11/17/26 13:25, Dmitry Voytik wrote:
> > +# If no '--file' was specified, use KBUILD_OUTPUT as the base if it exists
> > +if [[ "$FN" = ".config" && -n "$KBUILD_OUTPUT" ]]; then
>
> Right so this will give different results with:
> '--file .config'
> and:
> '--file ./.config'
>
> but maybe that was intentional -- i.e. we're assuming a user passing
> '.config' intends it to be '$KBUILD_OUTPUT/.config' while a user passing
> './.config' would intend CWD/.config?
It was intentional since I had figured they were passing the default
value so they should get the default behavior. Maybe it would be better
to only do this when no '--file' value was provided period though to
avoid some unexpected behavior?
diff --git a/scripts/config b/scripts/config
index 32428ea909c2..b09058ea1815 100755
--- a/scripts/config
+++ b/scripts/config
@@ -130,12 +130,14 @@ on_exit() {
trap on_exit EXIT
FN=.config
+USER_SET_FILE=0
CMDS=()
while [[ $# -gt 0 ]]; do
if [ "$1" = "--file" ]; then
if [ "$2" = "" ]; then
usage
fi
+ USER_SET_FILE=1
FN="$2"
shift 2
else
@@ -144,6 +146,22 @@ while [[ $# -gt 0 ]]; do
fi
done
+# If no '--file' was specified, use KBUILD_OUTPUT as the base if it exists
+if [[ "$USER_SET_FILE" = "0" && -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 +218,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 +247,7 @@ while [ "$1" != "" ] ; do
;;
--refresh)
- yes "" | make oldconfig KCONFIG_CONFIG=$FN
+ yes "" | make oldconfig KCONFIG_CONFIG="$FN"
;;
*)
--
Cheers,
Nathan