Skip to contentSkip to conversation

core/pkg-kconfig: use olddefconfig when available

PATCH New Yann E. MORIN 3 participants 5 messages Apr 23, 2016 – Apr 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 core/pkg-kconfig: use olddefconfig when available

From: Romain Izard <[email protected]>

Using 'yes "" | make oldconfig' to regenerate a .config file from an existing defconfig does not work reliably in all cases. Specifically, it does not work well with tristate choice entries.

The correct way to do it is to use 'make olddefconfig', but this target is not supported in projects that use an old version of kconfig. As most projects do not use tristate entries, there is no need for them to upgrade.

'oldnoconfig' is an alias for 'olddefconfig', but it also is the only name for this target between Linux versions 2.6.36 and 3.6.

Check which targets are supported by the current project, and use the appropriate method to regenerate the .config file.

[yann.morin.1998 at free.fr: use a shell construct instead of makefile code]
Cc Arnout Vandecappelle <[email protected]>
Cc Thomas Petazzoni <[email protected]>

---
Note: the helper to extract the make rule could very well be made more generic, by passing the make command to run instead of passing the package name. However, there is no need for it for now, and that would make thecalls to that macro a little bit longer (e.g. for a kconfig package):

    $$(call MAKE_RULE,$$($(2)_KCONFIG_MAKE),oldconfig)

This far from unreadable, but since there is no need for a generic wrapper for, we keep it as-is. When/if there is such a need, we can revisit it.

---
Changelog:
v1: New patch
v2: Use oldnoconfig instead of olddefconfig
Fix silent mode
Change the pattern in both places where it is used Use a macro to avoid redundancy
v3: Do not use $(call ...)

    Use the $(2)_KCONFIG_MAKE variable

v4: No change
v5: Detect available methods and use the most recent one
v6: Remove colon from matched rule names
v7: Use shell construct, not makefile code (Yann)

---
 package/pkg-kconfig.mk | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
package/pkg-kconfig.mk +28 -4
index 4033915..63140f7 100644
@@ -11,6 +11,15 @@
 #
 ################################################################################
 
+# Helper to extract the make rule specified in $(2) from all the make rules
+# of the package specified in $(1).
+# Returns a non-empty string (the rule itself) of the rule exist; returns
+# an empty string if the rule does not exist.
+define KCONFIG_RULES
+	$($(1)_KCONFIG_MAKE) -pn config 2>/dev/null | \
+	sed -r -e '/^$(2):/!d'
+endef
+
 ################################################################################
 # inner-kconfig-package -- generates the make targets needed to support a
 # kconfig package
@@ -60,18 +69,33 @@ $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES): | $(1)-patch
 $(2)_KCONFIG_MAKE = \
 	$$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) $$($(2)_KCONFIG_OPTS)
 
+# The correct way to regenerate a .config file is to use 'make olddefconfig'.
+# For historical reasons, the target name is 'oldnoconfig' between Linux kernel
+# versions 2.6.36 and 3.6, and remains as an alias in later versions.
+# In older versions, and in some other projects that use kconfig, the target is
+# not supported at all, and we use 'yes "" | make oldconfig' as a fallback
+# only, as this can fail in complex cases.
+define $(2)_REGEN_DOT_CONFIG
+	$$(Q)if [ "`$$(call KCONFIG_RULES,$(2),olddefconfig)`" ]; then \
+		$$($(2)_KCONFIG_MAKE) olddefconfig || exit 1; \
+	elif [ "`$$(call KCONFIG_RULES,$(2),oldnoconfig)`" ]; then \
+		$$($(2)_KCONFIG_MAKE) oldnoconfig || exit 1; \
+	else \
+		(yes "" | $$($(2)_KCONFIG_MAKE) oldconfig) || exit 1; \
+	fi
+endef
+
 # The specified source configuration file and any additional configuration file
 # fragments are merged together to .config, after the package has been patched.
 # Since the file could be a defconfig file it needs to be expanded to a
-# full .config first. We use 'make oldconfig' because this can be safely
-# done even when the package does not support defconfigs.
+# full .config first.
 $$($(2)_DIR)/.config: $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES)
 	$$(Q)$$(if $$($(2)_KCONFIG_DEFCONFIG), \
 		$$($(2)_KCONFIG_MAKE) $$($(2)_KCONFIG_DEFCONFIG), \
 		cp $$($(2)_KCONFIG_FILE) $$(@))
 	$$(Q)support/kconfig/merge_config.sh -m -O $$(@D) \
 		$$(@) $$($(2)_KCONFIG_FRAGMENT_FILES)
-	$$(Q)yes "" | $$($(2)_KCONFIG_MAKE) oldconfig
+	$$($(2)_REGEN_DOT_CONFIG)
 
 # If _KCONFIG_FILE or _KCONFIG_FRAGMENT_FILES exists, this dependency is
 # already implied, but if we only have a _KCONFIG_DEFCONFIG we have to add
@@ -82,7 +106,7 @@ $$($(2)_DIR)/.config: | $(1)-patch
 # The exact rules are specified by the package .mk file.
 define $(2)_FIXUP_DOT_CONFIG
 	$$($(2)_KCONFIG_FIXUP_CMDS)
-	$$(Q)yes "" | $$($(2)_KCONFIG_MAKE) oldconfig
+	$$($(2)_REGEN_DOT_CONFIG)
 	$$(Q)touch $$($(2)_DIR)/.stamp_kconfig_fixup_done
 endef
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 core/pkg-kconfig: use olddefconfig when available

Hello,

package/pkg-kconfig.mk line 16

Quoted 3 lines · Yann E. MORIN
package/pkg-kconfig.mk +3 -0
+# Helper to extract the make rule specified in $(2) from all the make rules
+# of the package specified in $(1).
+# Returns a non-empty string (the rule itself) of the rule exist; returns

of the rule exist -> if the rule exists

package/pkg-kconfig.mk $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES): | $(1)-patch · line 73

Quoted 2 lines
package/pkg-kconfig.mk +2 -0
+# The correct way to regenerate a .config file is to use 'make olddefconfig'.
+# For historical reasons, the target name is 'oldnoconfig' between Linux kernel

I believe it sounded better with:

"the target name *was* 'oldnoconfig' ..."

I've applied after fixing those minor nits! Thanks Romain and Yann for working on this topic!

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 core/pkg-kconfig: use olddefconfig when available

In reply to Yann E. MORIN

Hello,

Quoted 14 lines · Yann E. MORIN

From: Romain Izard <[email protected]>

Using 'yes "" | make oldconfig' to regenerate a .config file from an existing defconfig does not work reliably in all cases. Specifically, it does not work well with tristate choice entries.

The correct way to do it is to use 'make olddefconfig', but this target is not supported in projects that use an old version of kconfig. As most projects do not use tristate entries, there is no need for them to upgrade.

'oldnoconfig' is an alias for 'olddefconfig', but it also is the only name for this target between Linux versions 2.6.36 and 3.6.

Quoted 8 lines

Check which targets are supported by the current project, and use the appropriate method to regenerate the .config file.

[yann.morin.1998 at free.fr: use a shell construct instead of makefile code]
Cc Arnout Vandecappelle <[email protected]>
Cc Thomas Petazzoni <[email protected]>

I am sorry, but I had to revert this commit. While it works in simple situations, it badly breaks the Busybox build in some situations:

http://autobuild.buildroot.org/?reason=busybox-1.24.2

With just Busybox enabled in a minimal configuration, everything is fine. Enable "libtirpc" in the configuration, do a full rebuild -> Busybox will fail to build. I don't know if it's related specifically to libtirpc or to some of its dependencies, but it fails.

A very quick research couldn't spot the source of the problem, so I simply reverted for now. Could you work on this and submit a new version of the patch that addresses this problem?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#3 lore raw

PATCH 1/1 core/pkg-kconfig: use olddefconfig when available

2016-04-25 15:35 GMT+02:00 Thomas Petazzoni
<[email protected]>:

Quoted 7 lines

Hello,

I am sorry, but I had to revert this commit. While it works in simple situations, it badly breaks the Busybox build in some situations:

http://autobuild.buildroot.org/?reason=busybox-1.24.2

Quoted 9 lines

With just Busybox enabled in a minimal configuration, everything is fine. Enable "libtirpc" in the configuration, do a full rebuild -> Busybox will fail to build. I don't know if it's related specifically to libtirpc or to some of its dependencies, but it fails.

A very quick research couldn't spot the source of the problem, so I simply reverted for now. Could you work on this and submit a new version of the patch that addresses this problem?

When testing with qemu_x86_defconfig, libtirpc and busybox I reproduce the issue. Calling 'make busybox-menuconfig' returns errors when updating the config file to merge buildroot-managed options with the new busybox config file, as it tries to launch olddefconfig.

The first error in the build is "bash: command not found".

There is a problem with the shell command we tried to generate, as the command line contains multiple levels of backticks. This comes from libtirpc, which uses backticks to generate its CFLAGS.

It is possible to fix this by replacing the backticks in the (2)_REGEN_DOT_CONFIG macro. Unfortunately, $(...) is detected by make as its own syntax, so it is necessarily to use quadruple dollars.

The v6 revision of the patch, as it did not use backticks, did not have this problem.

Best regards,

Signature · 1 line
Romain Izard
#4 lore raw

PATCH 1/1 core/pkg-kconfig: use olddefconfig when available

Romain, All,

On 2016-04-25 18:42 +0200, Romain Izard spake thusly:

Quoted 24 lines

2016-04-25 15:35 GMT+02:00 Thomas Petazzoni
<[email protected]>:

Quoted 7 lines

Hello,

I am sorry, but I had to revert this commit. While it works in simple situations, it badly breaks the Busybox build in some situations:

http://autobuild.buildroot.org/?reason=busybox-1.24.2

Quoted 9 lines

With just Busybox enabled in a minimal configuration, everything is fine. Enable "libtirpc" in the configuration, do a full rebuild -> Busybox will fail to build. I don't know if it's related specifically to libtirpc or to some of its dependencies, but it fails.

A very quick research couldn't spot the source of the problem, so I simply reverted for now. Could you work on this and submit a new version of the patch that addresses this problem?

When testing with qemu_x86_defconfig, libtirpc and busybox I reproduce the issue. Calling 'make busybox-menuconfig' returns errors when updating the config file to merge buildroot-managed options with the new busybox config file, as it tries to launch olddefconfig.

Quoted 5 lines

The first error in the build is "bash: command not found".

There is a problem with the shell command we tried to generate, as the command line contains multiple levels of backticks. This comes from libtirpc, which uses backticks to generate its CFLAGS.

No, it does not come from libtirpc. It comes from the busybox package, see:
https://git.buildroot.org/buildroot/tree/package/busybox/busybox.mk#n23
https://git.buildroot.org/buildroot/tree/package/busybox/busybox.mk#n26

And that's really the reason why I dislike back-quotes...

However, because our .mk are written in Makefile, and we can't always know the number of expansion the Makefile variables will undergo, we can't safely use $(xxx) to replace xxx... Sad... :-(

Quoted 3 lines

It is possible to fix this by replacing the backticks in the (2)_REGEN_DOT_CONFIG macro. Unfortunately, $(...) is detected by make as its own syntax, so it is necessarily to use quadruple dollars.

Meh... Peolple like to think they'd be happier if they had more $, but really more $ really hurts! ;-p

Quoted 2 lines

The v6 revision of the patch, as it did not use backticks, did not have this problem.

I'm afraid we'll have to resort to using the makefile syntax, indeed...

Romain, could you please respin your latest revision that was using the Makefile syntax? IIRC, I did add my reviewed-by tag to it, so you can keep it (unless you were to tweak the code). However, please add an explanation in the commit log that we can't use shell constructs, something along the lines of:

We use a Makefile syntax because using a shell construct does not work:
- some packages may have shell-expansion in their _KCONFIG_OPTS
- we can't safely use $() for command substituion, so we have to use ``
- `` does not nest nicely
Using a shell construct here to check the rule, would mean using ``, which could conflict with the `` from the package's _KCONFIG_OPTS.

(Feel free to adapt or re-use as-is! ;-) )

Tyanks!

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'