base: Add deferred class event handler
PATCH 1/5 base: Add deferred class event handler
Use the new deferred class event to set the class overrides earlier. This improves interaction of the override with PACKAGECONFIG values that control conditional inherits (such as python support).
This also allows toolchain configuration in an easier and more user friendly way.
--- meta/classes-global/base.bbclass | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
meta/classes-global/base.bbclass +10 -1
@@ -267,10 +267,19 @@ def buildcfg_neededvars(d): bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser)) addhandler base_eventhandler -base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed" +base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed bb.event.RecipePreDeferredInherits" python base_eventhandler() { import bb.runqueue + if isinstance(e, bb.event.RecipePreDeferredInherits): + # Use this to snoop on class extensions and set these up before the deferred inherits + # are processed which allows overrides on conditional variables. + if "native" in e.inherits: + d.setVar('CLASSOVERRIDE', 'class-native') + elif "nativesdk" in e.inherits: + d.setVar('CLASSOVERRIDE', 'class-nativesdk') + return + if isinstance(e, bb.event.ConfigParsed): if not d.getVar("NATIVELSBSTRING", False): d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
PATCH 2/5 toolchain: Provide abstraction for recipe specific toolchain selection
This implements a toolchain selection mechanism, defaulting to gcc as per the existing defaults.
Introduce a variable called TOOLCHAIN, which denotes the familiar name for toolchain e.g. "gcc" which selects GNU compiler + binutils as default C/C++ toolchain or "clang" which will use LLVM/Clang Compiler
TOOLCHAIN variable has a global fallback to "gcc" in configuration metadata. A distro can switch to using say "clang" as default system compiler by defining
TOOLCHAIN ?= "clang"
In local.conf or other distro specific global configuration metadata
It is also selectable at recipe scope, since not all packages are buildable with either clang or gcc, a recipe can explicitly demand a given toolchain e.g. glibc can not be built with clang therefore glibc recipe sets.
TOOLCHAIN = "gcc"
Based on ideas/work by Khem Raj <[email protected]>
---
meta/classes-global/base.bbclass | 6 ++++++
.../toolchain/clang.inc => classes/toolchain/clang.bbclass} | 0
.../build-gcc.inc => classes/toolchain/gcc-native.bbclass} | 0
.../toolchain/gcc.inc => classes/toolchain/gcc.bbclass} | 0
meta/conf/bitbake.conf | 3 ---
meta/recipes-devtools/binutils/binutils-cross.inc | 2 ++
meta/recipes-devtools/clang/clang-cross_git.bb | 1 +
meta/recipes-devtools/clang/clang-crosssdk_git.bb | 1 +
8 files changed, 10 insertions(+), 3 deletions(-)
rename meta/{conf/toolchain/clang.inc => classes/toolchain/clang.bbclass} (100%)
rename meta/{conf/toolchain/build-gcc.inc => classes/toolchain/gcc-native.bbclass} (100%)
rename meta/{conf/toolchain/gcc.inc => classes/toolchain/gcc.bbclass} (100%)meta/classes-global/base.bbclass +6 -0
@@ -19,6 +19,12 @@ PACKAGECONFIG_CONFARGS ??= "" inherit metadata_scm +TOOLCHAIN ??= "gcc" +TOOLCHAIN:class-native ??= "gcc" +TOOLCHAIN:class-nativesdk ??= "gcc" +inherit toolchain/gcc-native +inherit_defer toolchain/${TOOLCHAIN} + def lsb_distro_identifier(d): adjust = d.getVar('LSB_DISTRO_ADJUST') adjust_func = None
meta/classes/toolchain/clang.bbclass renamed from meta/conf/toolchain/clang.inc +0 -0
meta/classes/toolchain/gcc-native.bbclass renamed from meta/conf/toolchain/build-gcc.inc +0 -0
meta/classes/toolchain/gcc.bbclass renamed from meta/conf/toolchain/gcc.inc +0 -0
meta/conf/bitbake.conf +0 -3
@@ -834,9 +834,6 @@ include conf/licenses.conf require conf/sanity.conf include conf/bblock.conf -require toolchain/gcc.inc -require toolchain/build-gcc.inc - ################################################################## # Weak variables (usually to retain backwards compatibility) ##################################################################
meta/recipes-devtools/binutils/binutils-cross.inc +2 -0
@@ -9,6 +9,8 @@ TARGET_ARCH[vardepvalue] = "${TARGET_ARCH}" INHIBIT_DEFAULT_DEPS = "1" INHIBIT_AUTOTOOLS_DEPS = "1" +TOOLCHAIN = "gcc" + SRC_URI += "file://0002-binutils-cross-Do-not-generate-linker-script-directo.patch" # Specify lib-path else we use a load of search dirs which we don't use
meta/recipes-devtools/clang/clang-cross_git.bb +1 -0
@@ -11,6 +11,7 @@ PN = "clang-cross-${TARGET_ARCH}" require common-clang.inc require common-source.inc inherit cross +TOOLCHAIN = "clang" DEPENDS += "clang-native virtual/cross-binutils" #INHIBIT_PACKAGE_STRIP = "1"
meta/recipes-devtools/clang/clang-crosssdk_git.bb +1 -0
@@ -11,6 +11,7 @@ PN = "clang-crosssdk-${SDK_SYS}" require common-clang.inc require common-source.inc inherit crosssdk +TOOLCHAIN = "clang" DEPENDS += "clang-native nativesdk-clang-glue virtual/nativesdk-cross-binutils virtual/nativesdk-libc" do_install() {
Re: [OE-core] [PATCH 2/5] toolchain: Provide abstraction for recipe specific toolchain selection
Quoted 20 lines · Richard Purdie via lists.openembedded.org
This implements a toolchain selection mechanism, defaulting to gcc as per the existing defaults.
Introduce a variable called TOOLCHAIN, which denotes the familiar name for toolchain e.g. "gcc" which selects GNU compiler + binutils as default C/C++ toolchain or "clang" which will use LLVM/Clang Compiler
TOOLCHAIN variable has a global fallback to "gcc" in configuration metadata. A distro can switch to using say "clang" as default system compiler by defining
TOOLCHAIN ?= "clang"
In local.conf or other distro specific global configuration metadata
It is also selectable at recipe scope, since not all packages are buildable with either clang or gcc, a recipe can explicitly demand a given toolchain e.g. glibc can not be built with clang therefore glibc recipe sets.
Quoted 6 lines
TOOLCHAIN = "gcc"
Based on ideas/work by Khem Raj <[email protected]>
Signed-off-by Richard Purdie <[email protected]>---
I might be late here, but just a note about this patch: it looks like it will require a fix in meta-arm, as it is breaking build of edk2-firmware:
| bits.c: In function 'Efirst': | syn.h:173:48: error: too many arguments to function 'fpReach[r->ntype]'; expected 0, have 3 | 173 | (a) = (*(fpReach[(p)->ntype]))( p, k, rk );} | | ~^~~~~~~~~~~~~~~~~~~~~~~ | bits.c:224:9: note: in expansion of macro 'REACH' | 224 | REACH(r, 1, &rk, a); | | ^~~~~
https://autobuilder.yoctoproject.org/valkyrie/#/builders/75/builds/1711
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [OE-core] [PATCH 2/5] toolchain: Provide abstraction for recipe specific toolchain selection
Quoted 40 lines · Mathieu Dubois-Briand
Quoted 20 lines · Richard Purdie via lists.openembedded.org
This implements a toolchain selection mechanism, defaulting to gcc as per the existing defaults.
Introduce a variable called TOOLCHAIN, which denotes the familiar name for toolchain e.g. "gcc" which selects GNU compiler + binutils as default C/C++ toolchain or "clang" which will use LLVM/Clang Compiler
TOOLCHAIN variable has a global fallback to "gcc" in configuration metadata. A distro can switch to using say "clang" as default system compiler by defining
TOOLCHAIN ?= "clang"
In local.conf or other distro specific global configuration metadata
It is also selectable at recipe scope, since not all packages are buildable with either clang or gcc, a recipe can explicitly demand a given toolchain e.g. glibc can not be built with clang therefore glibc recipe sets.
Quoted 6 lines
TOOLCHAIN = "gcc"
Based on ideas/work by Khem Raj <[email protected]>
Signed-off-by Richard Purdie <[email protected]>---
I might be late here, but just a note about this patch: it looks like it will require a fix in meta-arm, as it is breaking build of edk2-firmware:
| bits.c: In function 'Efirst': | syn.h:173:48: error: too many arguments to function 'fpReach[r->ntype]'; expected 0, have 3 | 173 | (a) = (*(fpReach[(p)->ntype]))( p, k, rk );} | | ~^~~~~~~~~~~~~~~~~~~~~~~ | bits.c:224:9: note: in expansion of macro 'REACH' | 224 | REACH(r, 1, &rk, a); | | ^~~~~
Sorry, I used some garbage in place of Ross address, trying again...
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 3/5 toolchain/gcc/clang: Update PREFERRED_PROVIDER to work with multilibs
In reply to Richard PurdieAs currently written, the PREFERRED_PROVIDER entries don't work with multilib since they are added after the manipulations by multilib_global at ConfigParsed time. We therefore need to spell out the configs correctly for multilib.
To avoid variable overwritten warnings from the expansion, we then have to expand out the nativesdk providers usng class overrides.
--- meta/classes/toolchain/clang.bbclass | 21 ++++++++++++--------- meta/classes/toolchain/gcc.bbclass | 22 ++++++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-)
meta/classes/toolchain/clang.bbclass +12 -9
@@ -14,15 +14,18 @@ STRINGS = "${HOST_PREFIX}llvm-strings" NM = "${HOST_PREFIX}llvm-nm" READELF = "${HOST_PREFIX}llvm-readelf" -PREFERRED_PROVIDER_virtual/cross-cc = "${MLPREFIX}clang-cross-${TARGET_ARCH}" -PREFERRED_PROVIDER_virtual/cross-c++ = "${MLPREFIX}clang-cross-${TARGET_ARCH}" -PREFERRED_PROVIDER_virtual/compilerlibs = "gcc-runtime" -PREFERRED_PROVIDER_virtual/cross-cc:class-nativesdk = "clang-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/cross-c++:class-nativesdk = "clang-crosssdk-${SDK_SYS}" - -PREFERRED_PROVIDER_virtual/nativesdk-cross-cc = "clang-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/nativesdk-cross-c++ = "clang-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/nativesdk-compilerlibs = "nativesdk-gcc-runtime" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-cc = "${MLPREFIX}clang-cross-${TARGET_ARCH}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-c++ = "${MLPREFIX}clang-cross-${TARGET_ARCH}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}compilerlibs = "${MLPREFIX}gcc-runtime" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-cc:class-nativesdk = "clang-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-c++:class-nativesdk = "clang-crosssdk-${SDK_SYS}" + +PREFERRED_PROVIDER_virtual/nativesdk-cross-cc:class-crosssdk = "clang-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-cross-c++:class-crosssdk = "clang-crosssdk-${SDK_SYS}" + +PREFERRED_PROVIDER_virtual/nativesdk-cross-cc:class-cross-canadian = "clang-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-cross-c++:class-cross-canadian = "clang-crosssdk-${SDK_SYS}" + BASE_DEFAULT_DEPS:append:class-target = " compiler-rt"
meta/classes/toolchain/gcc.bbclass +14 -8
@@ -14,14 +14,20 @@ STRINGS = "${HOST_PREFIX}strings" NM = "${HOST_PREFIX}gcc-nm" READELF = "${HOST_PREFIX}readelf" -PREFERRED_PROVIDER_virtual/cross-cc = "${MLPREFIX}gcc-cross-${TARGET_ARCH}" -PREFERRED_PROVIDER_virtual/cross-c++ = "${MLPREFIX}gcc-cross-${TARGET_ARCH}" -PREFERRED_PROVIDER_virtual/compilerlibs = "gcc-runtime" -PREFERRED_PROVIDER_virtual/cross-cc:class-nativesdk = "gcc-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/cross-c++:class-nativesdk = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-cc = "${MLPREFIX}gcc-cross-${TARGET_ARCH}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-c++ = "${MLPREFIX}gcc-cross-${TARGET_ARCH}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}compilerlibs = "${MLPREFIX}gcc-runtime" -PREFERRED_PROVIDER_virtual/nativesdk-cross-cc = "gcc-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/nativesdk-cross-c++ = "gcc-crosssdk-${SDK_SYS}" -PREFERRED_PROVIDER_virtual/nativesdk-compilerlibs = "nativesdk-gcc-runtime" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-cc:class-nativesdk = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}cross-c++:class-nativesdk = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/${MLPREFIX}compilerlibs:class-nativesdk = "nativesdk-gcc-runtime" + +PREFERRED_PROVIDER_virtual/nativesdk-cross-cc:class-crosssdk = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-cross-c++:class-crosssdk = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-compilerlibs:class-crosssdk = "nativesdk-gcc-runtime" + +PREFERRED_PROVIDER_virtual/nativesdk-cross-cc:class-cross-canadian = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-cross-c++:class-cross-canadian = "gcc-crosssdk-${SDK_SYS}" +PREFERRED_PROVIDER_virtual/nativesdk-compilerlibs:class-cross-canadian = "nativesdk-gcc-runtime" TCOVERRIDE = "toolchain-gcc"
PATCH 4/5 bitbake.conf: Automatically defer native and nativesdk inherits
In reply to Richard Purdie--- meta/conf/bitbake.conf | 2 ++ 1 file changed, 2 insertions(+)
meta/conf/bitbake.conf +2 -0
@@ -947,6 +947,8 @@ BB_DEFAULT_UMASK ??= "022" BB_CONSOLELOG ?= "${LOG_DIR}/cooker/${MACHINE}/${DATETIME}.log" BB_DEFAULT_EVENTLOG ?= "${LOG_DIR}/eventlog/${DATETIME}.json" +BB_DEFER_BBCLASSES = "native nativesdk" + # Setup our default hash policy BB_SIGNATURE_HANDLER ?= "OEBasicHash" BB_HASHEXCLUDE_COMMON ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DIR \
PATCH 5/5 cross/crosssdk: Allow deferring of these classes too
In reply to Richard Purdie--- meta/classes-recipe/crosssdk.bbclass | 1 + meta/conf/bitbake.conf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/crosssdk.bbclass +1 -0
@@ -4,6 +4,7 @@ # SPDX-License-Identifier: MIT # +BB_DEFER_BBCLASSES:remove = "cross" inherit cross CLASSOVERRIDE = "class-crosssdk"
meta/conf/bitbake.conf +1 -1
@@ -947,7 +947,7 @@ BB_DEFAULT_UMASK ??= "022" BB_CONSOLELOG ?= "${LOG_DIR}/cooker/${MACHINE}/${DATETIME}.log" BB_DEFAULT_EVENTLOG ?= "${LOG_DIR}/eventlog/${DATETIME}.json" -BB_DEFER_BBCLASSES = "native nativesdk" +BB_DEFER_BBCLASSES = "native nativesdk cross crosssdk" # Setup our default hash policy BB_SIGNATURE_HANDLER ?= "OEBasicHash"