diff mbox series

[9/9] debug_build.inc: support disable debug build for specific recipe when DEBUG_BUILD is enabled globally

Message ID 20250919075536.1744673-1-hongxu.jia@windriver.com
State New
Headers show
Series None | expand

Commit Message

Hongxu Jia Sept. 19, 2025, 7:55 a.m. UTC
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, we have to set DEBUG_BUILD = "0" in the recipe.
In this situation, conf/distro/include/debug_build.inc is included,
although set DEBUG_BUILD = "0" in qemu recipe, the debug build is still
enabled for qemu and break qemu build.

This commit sets SELECTED_OPTIMIZATION, BUILD_OPTLEVE and
BUILD_OPTIMIZATION conditionally according to the value of
DEBUG_BUILD, then disable debug build for specific recipe
could work

Also move DEBUG_BUILD setting from qemu.inc to debug_build.inc

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/conf/distro/include/debug_build.inc | 18 +++++++++++++++---
 meta/recipes-devtools/qemu/qemu.inc      |  4 ----
 2 files changed, 15 insertions(+), 7 deletions(-)

Comments

patchtest@automation.yoctoproject.org Sept. 19, 2025, 8:01 a.m. UTC | #1
Thank you for your submission. Patchtest identified one
or more issues with the patch. Please see the log below for
more information:

---
Testing patch /home/patchtest/share/mboxes/9-9-debug_build.inc-support-disable-debug-build-for-specific-recipe-when-DEBUG_BUILD-is-enabled-globally.patch

FAIL: test shortlog length: Edit shortlog so that it is 90 characters or less (currently 101 characters) (test_mbox.TestMbox.test_shortlog_length)

PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test shortlog format (test_mbox.TestMbox.test_shortlog_format)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)

SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint)
SKIP: pretest src uri left files: Patch cannot be merged (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: Patch cannot be merged (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)

---

Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this
email with an explanation of why the patch should be accepted. If you
believe these results are due to an error in patchtest, please submit a
bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category
under 'Yocto Project Subprojects'). For more information on specific
failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank
you!
Peter Kjellerstedt Sept. 19, 2025, 10:49 p.m. UTC | #2
> -----Original Message-----
> From: Hongxu Jia <hongxu.jia@windriver.com>
> Sent: den 19 september 2025 09:56
> To: openembedded-core@lists.openembedded.org; Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> Subject: [PATCH 9/9] debug_build.inc: support disable debug build for specific recipe when DEBUG_BUILD is enabled globally
> 
> 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, we have to set DEBUG_BUILD = "0" in the recipe.
> In this situation, conf/distro/include/debug_build.inc is included,
> although set DEBUG_BUILD = "0" in qemu recipe, the debug build is still
> enabled for qemu and break qemu build.
> 
> This commit sets SELECTED_OPTIMIZATION, BUILD_OPTLEVE and
> BUILD_OPTIMIZATION conditionally according to the value of
> DEBUG_BUILD, then disable debug build for specific recipe
> could work
> 
> Also move DEBUG_BUILD setting from qemu.inc to debug_build.inc
> 
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>

Unfortunately, I think this defeats the purpose of this whole 
change. :( I.e., when parsing debug_build.inc you should know 
that DEBUG_BUILD is set to 1. If that is not the case, then 
what's the point of moving everything to that file? You would 
still have to check DEBUG_BUILD for every variable you modify.

Here is a solution I came up with that would maintain the 
property that debug_build.inc is only included if DEBUG_BUILD 
is set to 1 for a given recipe. Add this to bitbake.conf:

INHERIT += "debug_build"

Then create meta/classes-global/debug_build.bbclass with 
this line:

inherit_defer debug_build_deferred

and create meta/classes-recipe/debug_build_deferred.bbclass 
with this line:

include_all ${@oe.utils.vartrue('DEBUG_BUILD', 'conf/distro/include/debug_build.inc', '', d)}

Having to have the two bbclasses to defer the include_all 
so that debug_build.inc is only included if DEBUG_BUILD is 
actually set for a given recipe is a bit awkward, but it 
seems to work. At least with my quick test I could modify 
DEBUG_BUILD in a recipe and debug_build.inc would only be 
included when it was set to 1.

//Peter

> ---
>  meta/conf/distro/include/debug_build.inc | 18 +++++++++++++++---
>  meta/recipes-devtools/qemu/qemu.inc      |  4 ----
>  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/meta/conf/distro/include/debug_build.inc b/meta/conf/distro/include/debug_build.inc
> index 81b6a5f234..c3f19666e6 100644
> --- a/meta/conf/distro/include/debug_build.inc
> +++ b/meta/conf/distro/include/debug_build.inc
> @@ -1,10 +1,14 @@
>  # Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when DEBUG_BUILD is enabled.
>  DEBUG_OPTLEVEL ?= "-Og"
>  DEBUG_OPTIMIZATION = "${DEBUG_OPTLEVEL} ${DEBUG_LEVELFLAG}"
> -SELECTED_OPTIMIZATION = "${DEBUG_OPTIMIZATION}"
> +SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
> +SELECTED_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
> +
>  # compiler flags for native/nativesdk
> -BUILD_OPTLEVEL = "-Og"
> -BUILD_OPTIMIZATION = "${BUILD_OPTLEVEL} -g"
> +BUILD_OPTLEVEL = "${@oe.utils.vartrue('DEBUG_BUILD', '-Og', '-O2', d)}"
> +BUILD_OPTLEVEL[vardeps] += "DEBUG_BUILD"
> +BUILD_OPTIMIZATION += "${@oe.utils.vartrue('DEBUG_BUILD', '-g', '', d)}"
> +BUILD_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
> 
>  # The modern compilers and code seem to require extra steps to avoid DEBUG errors,
>  # this file collects debug tuning configuration to address DEBUG errors.
> @@ -53,3 +57,11 @@ MESON_BUILDTYPE ?= "debug"
>  # For cargo.bbclass
>  BUILD_MODE ?= ""
>  BUILD_DIR ?= "debug"
> +
> +# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
> +# upstream states qemu doesn't work without optimization
> +DEBUG_BUILD:pn-qemu = "0"
> +DEBUG_BUILD:pn-qemu-native = "0"
> +DEBUG_BUILD:pn-qemu-system-native = "0"
> +DEBUG_BUILD:pn-nativesdk-qemu = "0"
> +
> diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-
> devtools/qemu/qemu.inc
> index 2ee76e9a7c..7bd28dbbb5 100644
> --- a/meta/recipes-devtools/qemu/qemu.inc
> +++ b/meta/recipes-devtools/qemu/qemu.inc
> @@ -58,10 +58,6 @@ COMPATIBLE_HOST:mipsarchn32 = "null"
>  COMPATIBLE_HOST:mipsarchn64 = "null"
>  COMPATIBLE_HOST:riscv32 = "null"
> 
> -# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
> -# upstream states qemu doesn't work without optimization
> -DEBUG_BUILD = "0"
> -
>  do_install:append() {
>      # Prevent QA warnings about installed ${localstatedir}/run
>      if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi
> --
> 2.34.1
Hongxu Jia Sept. 22, 2025, 6:45 a.m. UTC | #3
On 9/20/25 06:49, Peter Kjellerstedt via lists.openembedded.org 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.
>
>> -----Original Message-----
>> From: Hongxu Jia <hongxu.jia@windriver.com>
>> Sent: den 19 september 2025 09:56
>> To: openembedded-core@lists.openembedded.org; Peter Kjellerstedt <peter.kjellerstedt@axis.com>
>> Subject: [PATCH 9/9] debug_build.inc: support disable debug build for specific recipe when DEBUG_BUILD is enabled globally
>>
>> 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, we have to set DEBUG_BUILD = "0" in the recipe.
>> In this situation, conf/distro/include/debug_build.inc is included,
>> although set DEBUG_BUILD = "0" in qemu recipe, the debug build is still
>> enabled for qemu and break qemu build.
>>
>> This commit sets SELECTED_OPTIMIZATION, BUILD_OPTLEVE and
>> BUILD_OPTIMIZATION conditionally according to the value of
>> DEBUG_BUILD, then disable debug build for specific recipe
>> could work
>>
>> Also move DEBUG_BUILD setting from qemu.inc to debug_build.inc
>>
>> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> Unfortunately, I think this defeats the purpose of this whole
> change. :( I.e., when parsing debug_build.inc you should know
> that DEBUG_BUILD is set to 1. If that is not the case, then
> what's the point of moving everything to that file? You would
> still have to check DEBUG_BUILD for every variable you modify.
>
> Here is a solution I came up with that would maintain the
> property that debug_build.inc is only included if DEBUG_BUILD
> is set to 1 for a given recipe. Add this to bitbake.conf:
>
> INHERIT += "debug_build"
>
> Then create meta/classes-global/debug_build.bbclass with
> this line:
>
> inherit_defer debug_build_deferred
>
> and create meta/classes-recipe/debug_build_deferred.bbclass
> with this line:
>
> include_all ${@oe.utils.vartrue('DEBUG_BUILD', 'conf/distro/include/debug_build.inc', '', d)}
>
> Having to have the two bbclasses to defer the include_all
> so that debug_build.inc is only included if DEBUG_BUILD is
> actually set for a given recipe is a bit awkward, but it
> seems to work. At least with my quick test I could modify
> DEBUG_BUILD in a recipe and debug_build.inc would only be
> included when it was set to 1.

Many thanks for your suggestion, I will follow it with slightly 
simplified, v2 incoming

//Hongxu

> //Peter
>
>> ---
>>   meta/conf/distro/include/debug_build.inc | 18 +++++++++++++++---
>>   meta/recipes-devtools/qemu/qemu.inc      |  4 ----
>>   2 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/meta/conf/distro/include/debug_build.inc b/meta/conf/distro/include/debug_build.inc
>> index 81b6a5f234..c3f19666e6 100644
>> --- a/meta/conf/distro/include/debug_build.inc
>> +++ b/meta/conf/distro/include/debug_build.inc
>> @@ -1,10 +1,14 @@
>>   # Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when DEBUG_BUILD is enabled.
>>   DEBUG_OPTLEVEL ?= "-Og"
>>   DEBUG_OPTIMIZATION = "${DEBUG_OPTLEVEL} ${DEBUG_LEVELFLAG}"
>> -SELECTED_OPTIMIZATION = "${DEBUG_OPTIMIZATION}"
>> +SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
>> +SELECTED_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
>> +
>>   # compiler flags for native/nativesdk
>> -BUILD_OPTLEVEL = "-Og"
>> -BUILD_OPTIMIZATION = "${BUILD_OPTLEVEL} -g"
>> +BUILD_OPTLEVEL = "${@oe.utils.vartrue('DEBUG_BUILD', '-Og', '-O2', d)}"
>> +BUILD_OPTLEVEL[vardeps] += "DEBUG_BUILD"
>> +BUILD_OPTIMIZATION += "${@oe.utils.vartrue('DEBUG_BUILD', '-g', '', d)}"
>> +BUILD_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
>>
>>   # The modern compilers and code seem to require extra steps to avoid DEBUG errors,
>>   # this file collects debug tuning configuration to address DEBUG errors.
>> @@ -53,3 +57,11 @@ MESON_BUILDTYPE ?= "debug"
>>   # For cargo.bbclass
>>   BUILD_MODE ?= ""
>>   BUILD_DIR ?= "debug"
>> +
>> +# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
>> +# upstream states qemu doesn't work without optimization
>> +DEBUG_BUILD:pn-qemu = "0"
>> +DEBUG_BUILD:pn-qemu-native = "0"
>> +DEBUG_BUILD:pn-qemu-system-native = "0"
>> +DEBUG_BUILD:pn-nativesdk-qemu = "0"
>> +
>> diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-
>> devtools/qemu/qemu.inc
>> index 2ee76e9a7c..7bd28dbbb5 100644
>> --- a/meta/recipes-devtools/qemu/qemu.inc
>> +++ b/meta/recipes-devtools/qemu/qemu.inc
>> @@ -58,10 +58,6 @@ COMPATIBLE_HOST:mipsarchn32 = "null"
>>   COMPATIBLE_HOST:mipsarchn64 = "null"
>>   COMPATIBLE_HOST:riscv32 = "null"
>>
>> -# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
>> -# upstream states qemu doesn't work without optimization
>> -DEBUG_BUILD = "0"
>> -
>>   do_install:append() {
>>       # Prevent QA warnings about installed ${localstatedir}/run
>>       if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi
>> --
>> 2.34.1
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#223775): https://lists.openembedded.org/g/openembedded-core/message/223775
> Mute This Topic: https://lists.openembedded.org/mt/115324540/3617049
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [hongxu.jia@eng.windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/meta/conf/distro/include/debug_build.inc b/meta/conf/distro/include/debug_build.inc
index 81b6a5f234..c3f19666e6 100644
--- a/meta/conf/distro/include/debug_build.inc
+++ b/meta/conf/distro/include/debug_build.inc
@@ -1,10 +1,14 @@ 
 # Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when DEBUG_BUILD is enabled.
 DEBUG_OPTLEVEL ?= "-Og"
 DEBUG_OPTIMIZATION = "${DEBUG_OPTLEVEL} ${DEBUG_LEVELFLAG}"
-SELECTED_OPTIMIZATION = "${DEBUG_OPTIMIZATION}"
+SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
+SELECTED_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
+
 # compiler flags for native/nativesdk
-BUILD_OPTLEVEL = "-Og"
-BUILD_OPTIMIZATION = "${BUILD_OPTLEVEL} -g"
+BUILD_OPTLEVEL = "${@oe.utils.vartrue('DEBUG_BUILD', '-Og', '-O2', d)}"
+BUILD_OPTLEVEL[vardeps] += "DEBUG_BUILD"
+BUILD_OPTIMIZATION += "${@oe.utils.vartrue('DEBUG_BUILD', '-g', '', d)}"
+BUILD_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
 
 # The modern compilers and code seem to require extra steps to avoid DEBUG errors,
 # this file collects debug tuning configuration to address DEBUG errors.
@@ -53,3 +57,11 @@  MESON_BUILDTYPE ?= "debug"
 # For cargo.bbclass
 BUILD_MODE ?= ""
 BUILD_DIR ?= "debug"
+
+# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
+# upstream states qemu doesn't work without optimization
+DEBUG_BUILD:pn-qemu = "0"
+DEBUG_BUILD:pn-qemu-native = "0"
+DEBUG_BUILD:pn-qemu-system-native = "0"
+DEBUG_BUILD:pn-nativesdk-qemu = "0"
+
diff --git a/meta/recipes-devtools/qemu/qemu.inc b/meta/recipes-devtools/qemu/qemu.inc
index 2ee76e9a7c..7bd28dbbb5 100644
--- a/meta/recipes-devtools/qemu/qemu.inc
+++ b/meta/recipes-devtools/qemu/qemu.inc
@@ -58,10 +58,6 @@  COMPATIBLE_HOST:mipsarchn32 = "null"
 COMPATIBLE_HOST:mipsarchn64 = "null"
 COMPATIBLE_HOST:riscv32 = "null"
 
-# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
-# upstream states qemu doesn't work without optimization
-DEBUG_BUILD = "0"
-
 do_install:append() {
     # Prevent QA warnings about installed ${localstatedir}/run
     if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi