[PATCH] kconfig: merge_config: use an empty file as initfile
From: Daniel Gomez
Date: Fri Mar 28 2025 - 10:35:02 EST
From: Daniel Gomez <da.gomez@xxxxxxxxxxx>
The scripts/kconfig/merge_config.sh script requires an existing
$INITFILE (or the $1 argument) as a base file for merging Kconfig
fragments. However, an empty $INITFILE can serve as an initial starting
point, later referenced by the KCONFIG_ALLCONFIG Makefile variable
if -m is not used. This variable can point to any configuration file
containing preset config symbols (the merged output) as stated in
Documentation/kbuild/kconfig.rst. When -m is used $INITFILE will
contain just the merge output requiring the user to run make (i.e.
KCONFIG_ALLCONFIG=<$INITFILE> make <allnoconfig/alldefconfig> or make
olddefconfig).
Instead of failing when `$INITFILE` is missing, create an empty file and
use it as the starting point for merges.
Signed-off-by: Daniel Gomez <da.gomez@xxxxxxxxxxx>
---
Commit b9fe99c5b994 ("kbuild: mergeconfig: move an error check
to merge_config.sh") moves the check for .config to exist from
scripts/kconfig/Makefile to the scripts/kconfig/merge_config.sh.
But this is no longer necessary.
This avoid having to run a make <target> to create a first .config file.
Workflow:
./scripts/kconfig/merge_config.sh \
-m .config \
<fragment list>
make olddefconfig
Here the logs with upstream scripts/kconfig/merge_config.sh (to show
.config is created with tinyconfig).
make tinyconfig V=1
{..}
make -f ./scripts/Makefile.build obj=scripts/kconfig tinyconfig
KCONFIG_ALLCONFIG=kernel/configs/tiny-base.config make -f ./Makefile allnoconfig
make -f ./scripts/Makefile.build obj=scripts/basic
make -f ./scripts/Makefile.build obj=scripts/kconfig allnoconfig
scripts/kconfig/conf --allnoconfig Kconfig
configuration written to .config
make -f ./Makefile tiny.config
make -f ./scripts/Makefile.build obj=scripts/basic
make -f ./scripts/Makefile.build obj=scripts/kconfig tiny.config
cmd_merge_fragments tiny.config
./scripts/kconfig/merge_config.sh -m .config
./kernel/configs/tiny.config ./arch/x86/configs/tiny.config
Using .config as base
Merging ./kernel/configs/tiny.config
Value of CONFIG_CC_OPTIMIZE_FOR_SIZE is redefined by fragment
./kernel/configs/tiny.config:
Previous value: # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
New value: CONFIG_CC_OPTIMIZE_FOR_SIZE=y
Value of CONFIG_KERNEL_XZ is redefined by fragment
./kernel/configs/tiny.config:
Previous value: # CONFIG_KERNEL_XZ is not set
New value: CONFIG_KERNEL_XZ=y
Value of CONFIG_SLUB_TINY is redefined by fragment
./kernel/configs/tiny.config:
Previous value: # CONFIG_SLUB_TINY is not set
New value: CONFIG_SLUB_TINY=y
Merging ./arch/x86/configs/tiny.config
Value of CONFIG_UNWINDER_GUESS is redefined by fragment
./arch/x86/configs/tiny.config:
Previous value: # CONFIG_UNWINDER_GUESS is not set
New value: CONFIG_UNWINDER_GUESS=y
merged configuration written to .config (needs make)
make -f ./Makefile olddefconfig
make -f ./scripts/Makefile.build obj=scripts/basic
make -f ./scripts/Makefile.build obj=scripts/kconfig olddefconfig
scripts/kconfig/conf --olddefconfig Kconfig
configuration written to .config
---
scripts/kconfig/merge_config.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/kconfig/merge_config.sh b/scripts/kconfig/merge_config.sh
index 0b7952471c18f6882b8978f839f3170bb41fb01f..ad35a60de350ae1c5b60d39bf752115d27276f52 100755
--- a/scripts/kconfig/merge_config.sh
+++ b/scripts/kconfig/merge_config.sh
@@ -112,8 +112,8 @@ INITFILE=$1
shift;
if [ ! -r "$INITFILE" ]; then
- echo "The base file '$INITFILE' does not exist. Exit." >&2
- exit 1
+ echo "The base file '$INITFILE' does not exist. Creating one..." >&2
+ touch $INITFILE
fi
MERGE_LIST=$*
---
base-commit: e21edb1638e82460f126a6e49bcdd958d452929c
change-id: 20250328-fix-merge-config-87fe109017e9
Best regards,
--
Daniel Gomez <da.gomez@xxxxxxxxxxx>