diff mbox series

[v6,1/8] distro/include: rework debug build

Message ID 20251217152421.1181080-1-hongxu.jia@windriver.com
State New
Headers show
Series [v6,1/8] distro/include: rework debug build | expand

Commit Message

Hongxu Jia Dec. 17, 2025, 3:24 p.m. UTC
The problem with DEBUG_BUILD is that we have a lot of debug information
in builds anyway and this is now unclear what it means. The
documentation.conf entry mentions packages which is now incorrect too.
The variable is a very old one and the interface is poorly designed
compared to other areas now.

This commit drop DEBUG_BUILD, and add debug_build.inc to instead.
In bitbake.conf, use ??= to set *_OPTIMIZATION, in debug_build.inc to
use ?= to override *_OPTIMIZATION

Make a config fragment to use include_all debug_build.inc to allow other
layers to add their own debug build configurations, user should use the
following ways to enable debug build

  $ bitbake-config-build enable-fragment core/yocto/debug-build

Or

  $ echo 'OE_FRAGMENTS += "core/yocto/debug-build"' >> conf/local.conf

Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Suggested-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/conf/bitbake.conf                                 | 9 +++------
 meta/conf/distro/include/debug_build.inc               | 5 +++++
 meta/conf/documentation.conf                           | 3 +--
 meta/conf/fragments/yocto/debug-build.conf             | 8 ++++++++
 meta/conf/templates/default/local.conf.sample.extended | 2 +-
 5 files changed, 18 insertions(+), 9 deletions(-)
 create mode 100644 meta/conf/distro/include/debug_build.inc
 create mode 100644 meta/conf/fragments/yocto/debug-build.conf
diff mbox series

Patch

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 88f4d0df69..653d396c79 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -659,13 +659,10 @@  DEBUG_PREFIX_MAP ?= "${DEBUG_PREFIX_MAP_EXTRA} \
 "
 DEBUG_LEVELFLAG ?= "-g"
 
-FULL_OPTIMIZATION = "-O2 ${DEBUG_LEVELFLAG}"
-DEBUG_OPTIMIZATION = "-Og ${DEBUG_LEVELFLAG}"
-SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
-SELECTED_OPTIMIZATION[vardeps] += "FULL_OPTIMIZATION DEBUG_OPTIMIZATION DEBUG_BUILD"
+FULL_OPTIMIZATION ??= "-O2 ${DEBUG_LEVELFLAG}"
+SELECTED_OPTIMIZATION ??= "${FULL_OPTIMIZATION}"
 # compiler flags for native/nativesdk
-BUILD_OPTIMIZATION = "${@oe.utils.vartrue('DEBUG_BUILD', '-Og -g', '-O2', d)}"
-BUILD_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
+BUILD_OPTIMIZATION ??= "-O2"
 
 ##################################################################
 # Reproducibility
diff --git a/meta/conf/distro/include/debug_build.inc b/meta/conf/distro/include/debug_build.inc
new file mode 100644
index 0000000000..9ae6be10c9
--- /dev/null
+++ b/meta/conf/distro/include/debug_build.inc
@@ -0,0 +1,5 @@ 
+# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when fragment 'core/yocto/debug-build' is enabled.
+DEBUG_OPTIMIZATION ?= "-Og ${DEBUG_LEVELFLAG}"
+SELECTED_OPTIMIZATION ?= "${DEBUG_OPTIMIZATION}"
+# compiler flags for native/nativesdk
+BUILD_OPTIMIZATION ?= "-Og -g"
diff --git a/meta/conf/documentation.conf b/meta/conf/documentation.conf
index 741130a392..cdd6566f3c 100644
--- a/meta/conf/documentation.conf
+++ b/meta/conf/documentation.conf
@@ -129,7 +129,6 @@  CVE_CHECK_LAYER_INCLUDELIST[doc] = "Defines which layers to include during cve-c
 D[doc] = "The destination directory."
 DATE[doc] = "The date the build was started using YMD format."
 DATETIME[doc] = "The date and time the build was started."
-DEBUG_BUILD[doc] = "Specifies to build packages with debugging information. This influences the value of the SELECTED_OPTIMIZATION variable."
 DEBUG_OPTIMIZATION[doc] = "The options to pass in TARGET_CFLAGS and CFLAGS when compiling a system for debugging. This variable defaults to '-Og ${DEBUG_LEVELFLAG}'."
 DEFAULT_PREFERENCE[doc] = "Specifies a weak bias for recipe selection priority."
 DEPENDS[doc] = "Lists a recipe's build-time dependencies (i.e. other recipe files)."
@@ -370,7 +369,7 @@  SDK_OUTPUT[doc] = "The location used by the OpenEmbedded build system when creat
 SDKIMAGE_FEATURES[doc] = "Equivalent to IMAGE_FEATURES. However, this variable applies to the SDK generated from an image using the command 'bitbake -c populate_sdk imagename'."
 SDKMACHINE[doc] = "Specifies the architecture (i.e. i686 or x86_64) for which to build SDK and ADT items."
 SECTION[doc] = "The section in which packages should be categorized. Package management utilities can make use of this variable."
-SELECTED_OPTIMIZATION[doc] = "The variable takes the value of FULL_OPTIMIZATION unless DEBUG_BUILD = '1'. In this case, the value of DEBUG_OPTIMIZATION is used."
+SELECTED_OPTIMIZATION[doc] = "The variable takes the value of FULL_OPTIMIZATION unless fragment 'core/yocto/debug-build' is enabled. In this case, the value of DEBUG_OPTIMIZATION is used."
 SERIAL_CONSOLES[doc] = "Defines the serial consoles (TTYs) to enable using getty."
 SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS[doc] = "A list of recipe dependencies that should not be used to determine signatures of tasks from one recipe when they depend on tasks from another recipe."
 SIGGEN_EXCLUDERECIPES_ABISAFE[doc] = "A list of recipes that are completely stable and will never change."
diff --git a/meta/conf/fragments/yocto/debug-build.conf b/meta/conf/fragments/yocto/debug-build.conf
new file mode 100644
index 0000000000..5bdc1366b4
--- /dev/null
+++ b/meta/conf/fragments/yocto/debug-build.conf
@@ -0,0 +1,8 @@ 
+BB_CONF_FRAGMENT_SUMMARY = "Specifies to build recipes with debugging information. \
+This influences the value of the SELECTED_OPTIMIZATION variable."
+BB_CONF_FRAGMENT_DESCRIPTION = "Enables full debug and backtrace capabilities for all programs \
+and libraries in the image, by modifying the SELECTED_OPTIMIZATION variable, \
+setting it to "DEBUG_OPTIMIZATION"."
+
+# Allow other layers to add their own debug build configurations
+include_all conf/distro/include/debug_build.inc
diff --git a/meta/conf/templates/default/local.conf.sample.extended b/meta/conf/templates/default/local.conf.sample.extended
index a898b18d59..0e96d40daa 100644
--- a/meta/conf/templates/default/local.conf.sample.extended
+++ b/meta/conf/templates/default/local.conf.sample.extended
@@ -67,7 +67,7 @@ 
 #
 # Uncomment this to change the optimization to make debugging easer, at the
 # possible cost of performance.
-# DEBUG_BUILD = "1"
+# OE_FRAGMENTS += "core/yocto/debug-build"
 #
 # Uncomment this to disable the stripping of the installed binaries
 # INHIBIT_PACKAGE_STRIP = "1"