diff mbox series

[v5,1/5] distro/include: Add debug_build.inc when DEBUG_BUILD is enabled

Message ID 20251010075258.2161972-1-hongxu.jia@windriver.com
State New
Headers show
Series [v5,1/5] distro/include: Add debug_build.inc when DEBUG_BUILD is enabled | expand

Commit Message

Hongxu Jia Oct. 10, 2025, 7:52 a.m. UTC
In bitbake.conf, use ??= to set *_OPTIMIZATION, add a new include
file debug_build.inc to use ?= to override *_OPTIMIZATION when
DEBUG_BUILD is enabled

When DEBUG_BUILD is enabled:
- Defer inherit bblcass debug_build, while setting DEBUG_BUILD = "1" in
  local.conf, the debug build is enabled globally. For the recipe (such
  as qemu) which doesn't work without optimization, set DEBUG_BUILD = "0"
  to disable it for a given recipe

- Use include_all to allow other layers to add their own debug build
  configurations

Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/classes-global/base.bbclass         | 3 +++
 meta/classes-recipe/debug_build.bbclass  | 8 ++++++++
 meta/conf/bitbake.conf                   | 9 +++------
 meta/conf/distro/include/debug_build.inc | 5 +++++
 meta/conf/documentation.conf             | 2 +-
 5 files changed, 20 insertions(+), 7 deletions(-)
 create mode 100644 meta/classes-recipe/debug_build.bbclass
 create mode 100644 meta/conf/distro/include/debug_build.inc

Comments

Richard Purdie Dec. 15, 2025, noon UTC | #1
On Fri, 2025-10-10 at 15:52 +0800, hongxu via lists.openembedded.org wrote:
> In bitbake.conf, use ??= to set *_OPTIMIZATION, add a new include
> file debug_build.inc to use ?= to override *_OPTIMIZATION when
> DEBUG_BUILD is enabled
> 
> When DEBUG_BUILD is enabled:
> - Defer inherit bblcass debug_build, while setting DEBUG_BUILD = "1" in
>   local.conf, the debug build is enabled globally. For the recipe (such
>   as qemu) which doesn't work without optimization, set DEBUG_BUILD = "0"
>   to disable it for a given recipe
> 
> - Use include_all to allow other layers to add their own debug build
>   configurations
> 
> Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/classes-global/base.bbclass         | 3 +++
>  meta/classes-recipe/debug_build.bbclass  | 8 ++++++++
>  meta/conf/bitbake.conf                   | 9 +++------
>  meta/conf/distro/include/debug_build.inc | 5 +++++
>  meta/conf/documentation.conf             | 2 +-
>  5 files changed, 20 insertions(+), 7 deletions(-)
>  create mode 100644 meta/classes-recipe/debug_build.bbclass
>  create mode 100644 meta/conf/distro/include/debug_build.inc
> 
> diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
> index 6de17d1bb5..0f4398e26f 100644
> --- a/meta/classes-global/base.bbclass
> +++ b/meta/classes-global/base.bbclass
> @@ -35,6 +35,9 @@ TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
>  inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
>  inherit_defer toolchain/${TOOLCHAIN}
>  
> +DEBUG_BUILD ??= "0"
> +inherit_defer ${@oe.utils.vartrue('DEBUG_BUILD', 'debug_build', '', d)}
> +
>  def lsb_distro_identifier(d):
>      adjust = d.getVar('LSB_DISTRO_ADJUST')
>      adjust_func = None
> diff --git a/meta/classes-recipe/debug_build.bbclass b/meta/classes-recipe/debug_build.bbclass
> new file mode 100644
> index 0000000000..a917e9cbc9
> --- /dev/null
> +++ b/meta/classes-recipe/debug_build.bbclass
> @@ -0,0 +1,8 @@
> +#
> +# Copyright OpenEmbedded Contributors
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +# Allow other layers to add their own debug build configurations
> +include_all conf/distro/include/debug_build.inc
> diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
> index 5406e542db..52ceb76bbb 100644
> --- a/meta/conf/bitbake.conf
> +++ b/meta/conf/bitbake.conf
> @@ -658,13 +658,10 @@ DEBUG_PREFIX_MAP ?= "\
>  "
>  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..95e09e64f5
> --- /dev/null
> +++ b/meta/conf/distro/include/debug_build.inc
> @@ -0,0 +1,5 @@
> +# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when 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..2a7418ccb3 100644
> --- a/meta/conf/documentation.conf
> +++ b/meta/conf/documentation.conf
> @@ -129,7 +129,7 @@ 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_BUILD[doc] = "Specifies to build packages with debugging information. This influences the value of the SELECTED_OPTIMIZATION variable and includes file conf/distro/include/debug_build.inc"
>  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)."

Sorry about the delay in getting to this, we had to focus on the
release. I have been giving this some thought and it is heading the
right way but I have a couple of ideas.

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.

Rather than keeping "DEBUG_BUILD" alive, perhaps we drop that and
simply document the INHERIT instead? I did wonder about making it a
config fragment instead too instead of a class?

I'm also wondering whether we should remove SELECTED_OPTIMIZATION
entirely? Certainly DEBUG_OPTIMIZATION and FULL_OPTIMIZATION can be
dropped. Whether that should be this patch or another, I don't mind.

Cheers,

Richard
Khem Raj Dec. 15, 2025, 12:30 p.m. UTC | #2
On Mon, Dec 15, 2025 at 7:00 AM Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> On Fri, 2025-10-10 at 15:52 +0800, hongxu via lists.openembedded.org
> wrote:
> > In bitbake.conf, use ??= to set *_OPTIMIZATION, add a new include
> > file debug_build.inc to use ?= to override *_OPTIMIZATION when
> > DEBUG_BUILD is enabled
> >
> > When DEBUG_BUILD is enabled:
> > - Defer inherit bblcass debug_build, while setting DEBUG_BUILD = "1" in
> >   local.conf, the debug build is enabled globally. For the recipe (such
> >   as qemu) which doesn't work without optimization, set DEBUG_BUILD = "0"
> >   to disable it for a given recipe
> >
> > - Use include_all to allow other layers to add their own debug build
> >   configurations
> >
> > Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> > Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> > ---
> >  meta/classes-global/base.bbclass         | 3 +++
> >  meta/classes-recipe/debug_build.bbclass  | 8 ++++++++
> >  meta/conf/bitbake.conf                   | 9 +++------
> >  meta/conf/distro/include/debug_build.inc | 5 +++++
> >  meta/conf/documentation.conf             | 2 +-
> >  5 files changed, 20 insertions(+), 7 deletions(-)
> >  create mode 100644 meta/classes-recipe/debug_build.bbclass
> >  create mode 100644 meta/conf/distro/include/debug_build.inc
> >
> > diff --git a/meta/classes-global/base.bbclass
> b/meta/classes-global/base.bbclass
> > index 6de17d1bb5..0f4398e26f 100644
> > --- a/meta/classes-global/base.bbclass
> > +++ b/meta/classes-global/base.bbclass
> > @@ -35,6 +35,9 @@ TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
> >  inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
> >  inherit_defer toolchain/${TOOLCHAIN}
> >
> > +DEBUG_BUILD ??= "0"
> > +inherit_defer ${@oe.utils.vartrue('DEBUG_BUILD', 'debug_build', '', d)}
> > +
> >  def lsb_distro_identifier(d):
> >      adjust = d.getVar('LSB_DISTRO_ADJUST')
> >      adjust_func = None
> > diff --git a/meta/classes-recipe/debug_build.bbclass
> b/meta/classes-recipe/debug_build.bbclass
> > new file mode 100644
> > index 0000000000..a917e9cbc9
> > --- /dev/null
> > +++ b/meta/classes-recipe/debug_build.bbclass
> > @@ -0,0 +1,8 @@
> > +#
> > +# Copyright OpenEmbedded Contributors
> > +#
> > +# SPDX-License-Identifier: MIT
> > +#
> > +
> > +# Allow other layers to add their own debug build configurations
> > +include_all conf/distro/include/debug_build.inc
> > diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
> > index 5406e542db..52ceb76bbb 100644
> > --- a/meta/conf/bitbake.conf
> > +++ b/meta/conf/bitbake.conf
> > @@ -658,13 +658,10 @@ DEBUG_PREFIX_MAP ?= "\
> >  "
> >  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..95e09e64f5
> > --- /dev/null
> > +++ b/meta/conf/distro/include/debug_build.inc
> > @@ -0,0 +1,5 @@
> > +# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when
> 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..2a7418ccb3 100644
> > --- a/meta/conf/documentation.conf
> > +++ b/meta/conf/documentation.conf
> > @@ -129,7 +129,7 @@ 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_BUILD[doc] = "Specifies to build packages with debugging
> information. This influences the value of the SELECTED_OPTIMIZATION
> variable and includes file conf/distro/include/debug_build.inc"
> >  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)."
>
> Sorry about the delay in getting to this, we had to focus on the
> release. I have been giving this some thought and it is heading the
> right way but I have a couple of ideas.
>
> 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.
>
> Rather than keeping "DEBUG_BUILD" alive, perhaps we drop that and
> simply document the INHERIT instead? I did wonder about making it a
> config fragment instead too instead of a class?
>
> I'm also wondering whether we should remove SELECTED_OPTIMIZATION
> entirely? Certainly DEBUG_OPTIMIZATION and FULL_OPTIMIZATION can be
> dropped. Whether that should be this patch or another, I don't mind.


I think simplifying this would be useful. All these variables have grown
overtime and adding one one will add to this. Perhaps the final value of
optimization settings could be computed from fragments.


>
> Cheers,
>
> Richard
>
Hongxu Jia Dec. 16, 2025, 9:06 a.m. UTC | #3
On 12/15/25 20:00, Richard Purdie wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Fri, 2025-10-10 at 15:52 +0800, hongxu via lists.openembedded.org wrote:
>> In bitbake.conf, use ??= to set *_OPTIMIZATION, add a new include
>> file debug_build.inc to use ?= to override *_OPTIMIZATION when
>> DEBUG_BUILD is enabled
>>
>> When DEBUG_BUILD is enabled:
>> - Defer inherit bblcass debug_build, while setting DEBUG_BUILD = "1" in
>>    local.conf, the debug build is enabled globally. For the recipe (such
>>    as qemu) which doesn't work without optimization, set DEBUG_BUILD = "0"
>>    to disable it for a given recipe
>>
>> - Use include_all to allow other layers to add their own debug build
>>    configurations
>>
>> Suggested-by: Peter Kjellerstedt<peter.kjellerstedt@axis.com>
>> Signed-off-by: Hongxu Jia<hongxu.jia@windriver.com>
>> ---
>>   meta/classes-global/base.bbclass         | 3 +++
>>   meta/classes-recipe/debug_build.bbclass  | 8 ++++++++
>>   meta/conf/bitbake.conf                   | 9 +++------
>>   meta/conf/distro/include/debug_build.inc | 5 +++++
>>   meta/conf/documentation.conf             | 2 +-
>>   5 files changed, 20 insertions(+), 7 deletions(-)
>>   create mode 100644 meta/classes-recipe/debug_build.bbclass
>>   create mode 100644 meta/conf/distro/include/debug_build.inc
>>
>> diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
>> index 6de17d1bb5..0f4398e26f 100644
>> --- a/meta/classes-global/base.bbclass
>> +++ b/meta/classes-global/base.bbclass
>> @@ -35,6 +35,9 @@ TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
>>   inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
>>   inherit_defer toolchain/${TOOLCHAIN}
>>
>> +DEBUG_BUILD ??= "0"
>> +inherit_defer ${@oe.utils.vartrue('DEBUG_BUILD', 'debug_build', '', d)}
>> +
>>   def lsb_distro_identifier(d):
>>       adjust = d.getVar('LSB_DISTRO_ADJUST')
>>       adjust_func = None
>> diff --git a/meta/classes-recipe/debug_build.bbclass b/meta/classes-recipe/debug_build.bbclass
>> new file mode 100644
>> index 0000000000..a917e9cbc9
>> --- /dev/null
>> +++ b/meta/classes-recipe/debug_build.bbclass
>> @@ -0,0 +1,8 @@
>> +#
>> +# Copyright OpenEmbedded Contributors
>> +#
>> +# SPDX-License-Identifier: MIT
>> +#
>> +
>> +# Allow other layers to add their own debug build configurations
>> +include_all conf/distro/include/debug_build.inc
>> diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
>> index 5406e542db..52ceb76bbb 100644
>> --- a/meta/conf/bitbake.conf
>> +++ b/meta/conf/bitbake.conf
>> @@ -658,13 +658,10 @@ DEBUG_PREFIX_MAP ?= "\
>>   "
>>   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..95e09e64f5
>> --- /dev/null
>> +++ b/meta/conf/distro/include/debug_build.inc
>> @@ -0,0 +1,5 @@
>> +# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when 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..2a7418ccb3 100644
>> --- a/meta/conf/documentation.conf
>> +++ b/meta/conf/documentation.conf
>> @@ -129,7 +129,7 @@ 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_BUILD[doc] = "Specifies to build packages with debugging information. This influences the value of the SELECTED_OPTIMIZATION variable and includes file conf/distro/include/debug_build.inc"
>>   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)."
> Sorry about the delay in getting to this, we had to focus on the
> release. I have been giving this some thought and it is heading the
> right way but I have a couple of ideas.
>
> 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.
>
> Rather than keeping "DEBUG_BUILD" alive, perhaps we drop that and
> simply document the INHERIT instead? I did wonder about making it a
> config fragment instead too instead of a class?
Got it, I will try to drop DEBUG_BUILD and add a config fragment to instead
>
> I'm also wondering whether we should remove SELECTED_OPTIMIZATION
> entirely? Certainly DEBUG_OPTIMIZATION and FULL_OPTIMIZATION can be
> dropped. Whether that should be this patch or another, I don't mind.

It is not easy to remove *_OPTIMIZATION, especially SELECTED_OPTIMIZATION,

with a simple grep,

...

$ grep SELECTED_OPTIMIZATION -rn meta 
meta/recipes-kernel/perf/perf.bb:88:TARGET_CC_ARCH += 
"${SELECTED_OPTIMIZATION} ${DEBUG_PREFIX_MAP}" 
meta/recipes-kernel/systemtap/systemtap_git.inc:18: if 
bb.utils.contains("SELECTED_OPTIMIZATION", "-O0", "x", "", d) == "x": 
meta/conf/templates/default/local.conf.sample.extended:101:# 
SELECTED_OPTIMIZATION = "${PROFILE_OPTIMIZATION}" grep: 
meta/conf/.documentation.conf.swp: binary file matches 
meta/conf/distro/include/lto.inc:48:SELECTED_OPTIMIZATION:append = 
"${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${LTO}', '', d)}" 
meta/conf/distro/include/lto.inc:51:SELECTED_OPTIMIZATION[vardeps] += 
"LTO LTOEXTRA" meta/conf/distro/include/security_flags.inc:13:OPTLEVEL = 
"${@bb.utils.filter('SELECTED_OPTIMIZATION', '-O0 -O1 -O2 -O3 -Ofast -Og 
-Os -Oz -O', d)}" 
meta/conf/distro/include/security_flags.inc:64:TARGET_CC_ARCH:append:pn-binutils 
= " ${SELECTED_OPTIMIZATION}" 
meta/conf/distro/include/security_flags.inc:65:TARGET_CC_ARCH:append:pn-gcc 
= " ${SELECTED_OPTIMIZATION}" 
meta/conf/distro/include/security_flags.inc:66:TARGET_CC_ARCH:append:pn-gdb 
= " ${SELECTED_OPTIMIZATION}" meta/conf/bitbake.conf:612:TARGET_CFLAGS = 
"${TARGET_CPPFLAGS} ${SELECTED_OPTIMIZATION} ${DEBUG_PREFIX_MAP} -pipe" 
meta/conf/bitbake.conf:663:SELECTED_OPTIMIZATION ??= 
"${FULL_OPTIMIZATION}" 
meta/recipes-support/xxhash/xxhash_0.8.3.bb:15:CFLAGS += 
"${@bb.utils.contains('SELECTED_OPTIMIZATION', '-Og', 
'-DXXH_NO_INLINE_HINTS', '', d)}" 
meta/recipes-devtools/valgrind/valgrind_3.26.0.bb:70:SELECTED_OPTIMIZATION 
= "${DEBUG_LEVELFLAG}"

...

Variable TARGET_CC_ARCH need to append ${SELECTED_OPTIMIZATION} 
conditionally

It is possible to remove DEBUG_OPTIMIZATION and FULL_OPTIMIZATION, I 
will try it in other thread out of these serials

//Hongxu

> Cheers,
>
> Richard
Peter Kjellerstedt Dec. 17, 2025, 8:43 p.m. UTC | #4
> -----Original Message-----
> From: Richard Purdie <richard.purdie@linuxfoundation.org>
> Sent: den 15 december 2025 13:01
> To: hongxu.jia@eng.windriver.com; Peter Kjellerstedt <peter.kjellerstedt@axis.com>; randy.macleod@windriver.com; raj.khem@gmail.com; openembedded-core@lists.openembedded.org; mathieu.dubois-briand@bootlin.com
> Subject: Re: [OE-core] [PATCH v5 1/5] distro/include: Add debug_build.inc when DEBUG_BUILD is enabled
> 
> On Fri, 2025-10-10 at 15:52 +0800, hongxu via lists.openembedded.org wrote:
> > In bitbake.conf, use ??= to set *_OPTIMIZATION, add a new include
> > file debug_build.inc to use ?= to override *_OPTIMIZATION when
> > DEBUG_BUILD is enabled
> >
> > When DEBUG_BUILD is enabled:
> > - Defer inherit bblcass debug_build, while setting DEBUG_BUILD = "1" in
> >   local.conf, the debug build is enabled globally. For the recipe (such
> >   as qemu) which doesn't work without optimization, set DEBUG_BUILD = "0"
> >   to disable it for a given recipe
> >
> > - Use include_all to allow other layers to add their own debug build
> >   configurations
> >
> > Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> > Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> > ---
> >  meta/classes-global/base.bbclass         | 3 +++
> >  meta/classes-recipe/debug_build.bbclass  | 8 ++++++++
> >  meta/conf/bitbake.conf                   | 9 +++------
> >  meta/conf/distro/include/debug_build.inc | 5 +++++
> >  meta/conf/documentation.conf             | 2 +-
> >  5 files changed, 20 insertions(+), 7 deletions(-)
> >  create mode 100644 meta/classes-recipe/debug_build.bbclass
> >  create mode 100644 meta/conf/distro/include/debug_build.inc
> >
> > diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
> > index 6de17d1bb5..0f4398e26f 100644
> > --- a/meta/classes-global/base.bbclass
> > +++ b/meta/classes-global/base.bbclass
> > @@ -35,6 +35,9 @@ TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
> >  inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
> >  inherit_defer toolchain/${TOOLCHAIN}
> >
> > +DEBUG_BUILD ??= "0"
> > +inherit_defer ${@oe.utils.vartrue('DEBUG_BUILD', 'debug_build', '', d)}
> > +
> >  def lsb_distro_identifier(d):
> >      adjust = d.getVar('LSB_DISTRO_ADJUST')
> >      adjust_func = None
> > diff --git a/meta/classes-recipe/debug_build.bbclass b/meta/classes-recipe/debug_build.bbclass
> > new file mode 100644
> > index 0000000000..a917e9cbc9
> > --- /dev/null
> > +++ b/meta/classes-recipe/debug_build.bbclass
> > @@ -0,0 +1,8 @@
> > +#
> > +# Copyright OpenEmbedded Contributors
> > +#
> > +# SPDX-License-Identifier: MIT
> > +#
> > +
> > +# Allow other layers to add their own debug build configurations
> > +include_all conf/distro/include/debug_build.inc
> > diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
> > index 5406e542db..52ceb76bbb 100644
> > --- a/meta/conf/bitbake.conf
> > +++ b/meta/conf/bitbake.conf
> > @@ -658,13 +658,10 @@ DEBUG_PREFIX_MAP ?= "\
> >  "
> >  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..95e09e64f5
> > --- /dev/null
> > +++ b/meta/conf/distro/include/debug_build.inc
> > @@ -0,0 +1,5 @@
> > +# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when
> 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..2a7418ccb3 100644
> > --- a/meta/conf/documentation.conf
> > +++ b/meta/conf/documentation.conf
> > @@ -129,7 +129,7 @@ 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_BUILD[doc] = "Specifies to build packages with debugging
> information. This influences the value of the SELECTED_OPTIMIZATION
> variable and includes file conf/distro/include/debug_build.inc"
> >  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)."
> 
> Sorry about the delay in getting to this, we had to focus on the
> release. I have been giving this some thought and it is heading the
> right way but I have a couple of ideas.
> 
> 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.
> 
> Rather than keeping "DEBUG_BUILD" alive, perhaps we drop that and
> simply document the INHERIT instead? I did wonder about making it a
> config fragment instead too instead of a class?
> 
> I'm also wondering whether we should remove SELECTED_OPTIMIZATION
> entirely? Certainly DEBUG_OPTIMIZATION and FULL_OPTIMIZATION can be
> dropped. Whether that should be this patch or another, I don't mind.
> 
> Cheers,
> 
> Richard

This doesn't make much sense to me. DEBUG_BUILD is something that I 
enable per recipe, typically in local.conf, or temporarily in the 
recipe itself to avoid having to re-parse everything. I do not see 
how fragments would be even remotely usable for this use case.
(Though you could of course have a fragment that sets DEBUG_BUILD = "1" 
if you want to build everything for debug.)

For years, I have been telling my developers not to invent their own 
ways of enabling debugging for their recipes, but rather rely on and 
hook into the official way, i.e., setting DEBUG_BUILD = "1" for the 
recipe. Please do not change this!

//Peter
diff mbox series

Patch

diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
index 6de17d1bb5..0f4398e26f 100644
--- a/meta/classes-global/base.bbclass
+++ b/meta/classes-global/base.bbclass
@@ -35,6 +35,9 @@  TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
 inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
 inherit_defer toolchain/${TOOLCHAIN}
 
+DEBUG_BUILD ??= "0"
+inherit_defer ${@oe.utils.vartrue('DEBUG_BUILD', 'debug_build', '', d)}
+
 def lsb_distro_identifier(d):
     adjust = d.getVar('LSB_DISTRO_ADJUST')
     adjust_func = None
diff --git a/meta/classes-recipe/debug_build.bbclass b/meta/classes-recipe/debug_build.bbclass
new file mode 100644
index 0000000000..a917e9cbc9
--- /dev/null
+++ b/meta/classes-recipe/debug_build.bbclass
@@ -0,0 +1,8 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Allow other layers to add their own debug build configurations
+include_all conf/distro/include/debug_build.inc
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 5406e542db..52ceb76bbb 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -658,13 +658,10 @@  DEBUG_PREFIX_MAP ?= "\
 "
 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..95e09e64f5
--- /dev/null
+++ b/meta/conf/distro/include/debug_build.inc
@@ -0,0 +1,5 @@ 
+# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when 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..2a7418ccb3 100644
--- a/meta/conf/documentation.conf
+++ b/meta/conf/documentation.conf
@@ -129,7 +129,7 @@  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_BUILD[doc] = "Specifies to build packages with debugging information. This influences the value of the SELECTED_OPTIMIZATION variable and includes file conf/distro/include/debug_build.inc"
 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)."