Patchwork [3/4] cross.bbclass: add virtclass handler

login
register
mail settings
Submitter Otavio Salvador
Date Feb. 7, 2012, 9:09 p.m.
Message ID <3aaae21268883e5ebcc5373f99517045613ad102.1328648562.git.otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/20917/
State New
Headers show

Comments

Otavio Salvador - Feb. 7, 2012, 9:09 p.m.
Allow use of BBCLASSEXTEND with 'cross' and use of virtclass-cross in
recipes.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/classes/cross.bbclass |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
Richard Purdie - Feb. 8, 2012, 10:52 a.m.
On Tue, 2012-02-07 at 21:09 +0000, Otavio Salvador wrote:
> Allow use of BBCLASSEXTEND with 'cross' and use of virtclass-cross in
> recipes.
> 
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> ---
>  meta/classes/cross.bbclass |   39 +++++++++++++++++++++++++++++++++++++++
>  1 files changed, 39 insertions(+), 0 deletions(-)
> 
> diff --git a/meta/classes/cross.bbclass b/meta/classes/cross.bbclass
> index 5681ab9..a764902 100644
> --- a/meta/classes/cross.bbclass
> +++ b/meta/classes/cross.bbclass
> @@ -55,6 +55,45 @@ libexecdir = "${exec_prefix}/libexec/${CROSS_TARGET_SYS_DIR}"
>  
>  do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE}"
>  
> +python cross_virtclass_handler () {
> +    if not isinstance(e, bb.event.RecipePreFinalise):
> +        return
> +
> +    classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
> +    if "cross" not in classextend:
> +        return
> +
> +    pn = e.data.getVar("PN", True)
> +    if not pn.endswith("-cross"):
> +        return
> +
> +    def map_dependencies(varname, d, suffix = ""):
> +        if suffix:
> +            varname = varname + "_" + suffix
> +        deps = d.getVar(varname, True)
> +        if not deps:
> +            return
> +        deps = bb.utils.explode_deps(deps)
> +        newdeps = []
> +        for dep in deps:
> +            if dep.endswith("-cross"):
> +                newdeps.append(dep)
> +            else:
> +                newdeps.append(dep + "-cross")
> +        bb.data.setVar(varname, " ".join(newdeps), d)
> +
> +    for pkg in (e.data.getVar("PACKAGES", True).split() + [""]):
> +        map_dependencies("RDEPENDS", e.data, pkg)
> +        map_dependencies("RRECOMMENDS", e.data, pkg)
> +        map_dependencies("RSUGGESTS", e.data, pkg)
> +        map_dependencies("RPROVIDES", e.data, pkg)
> +        map_dependencies("RREPLACES", e.data, pkg)

I want to highlight what this code does and I don't understand when it
would do something that makes sense. If for example we have a recipe
which:

RDEPENDS = "libc zlib"

it will now:

RDEPENDS = "lib-cross zlib-cross"

or a native recipe which had:

RDEPENDS = "pkgconfig-native"

will now:

RDEPENDS = "pkgconfig-native-cross"

Can you point me at the recipe you're using this in? I suspect we should
just remove the map_dependencies() pieces from this class entirely and
handle dependency issues with the override manually. I think at this
point all the BBCLASSEXTEND is going to give you is the removal of the
need to add a separate .bb file with "inherit cross" in it and enable an
override for your to use. I'm not sure we can write generic dependency
mapping code that would work for -cross.

Cheers,

Richard
Otavio Salvador - Feb. 8, 2012, 11:04 a.m.
On Wed, Feb 8, 2012 at 08:52, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> Can you point me at the recipe you're using this in? I suspect we should
> just remove the map_dependencies() pieces from this class entirely and
> handle dependency issues with the override manually. I think at this
> point all the BBCLASSEXTEND is going to give you is the removal of the
> need to add a separate .bb file with "inherit cross" in it and enable an
> override for your to use. I'm not sure we can write generic dependency
> mapping code that would work for -cross.
>

We use it a lot in the meta-chicken layer (
https://github.com/OSSystems/meta-chicken).

I agree about dropping map_dependencies from it. I will look at it and send
it again.

Patch

diff --git a/meta/classes/cross.bbclass b/meta/classes/cross.bbclass
index 5681ab9..a764902 100644
--- a/meta/classes/cross.bbclass
+++ b/meta/classes/cross.bbclass
@@ -55,6 +55,45 @@  libexecdir = "${exec_prefix}/libexec/${CROSS_TARGET_SYS_DIR}"
 
 do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE}"
 
+python cross_virtclass_handler () {
+    if not isinstance(e, bb.event.RecipePreFinalise):
+        return
+
+    classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
+    if "cross" not in classextend:
+        return
+
+    pn = e.data.getVar("PN", True)
+    if not pn.endswith("-cross"):
+        return
+
+    def map_dependencies(varname, d, suffix = ""):
+        if suffix:
+            varname = varname + "_" + suffix
+        deps = d.getVar(varname, True)
+        if not deps:
+            return
+        deps = bb.utils.explode_deps(deps)
+        newdeps = []
+        for dep in deps:
+            if dep.endswith("-cross"):
+                newdeps.append(dep)
+            else:
+                newdeps.append(dep + "-cross")
+        bb.data.setVar(varname, " ".join(newdeps), d)
+
+    for pkg in (e.data.getVar("PACKAGES", True).split() + [""]):
+        map_dependencies("RDEPENDS", e.data, pkg)
+        map_dependencies("RRECOMMENDS", e.data, pkg)
+        map_dependencies("RSUGGESTS", e.data, pkg)
+        map_dependencies("RPROVIDES", e.data, pkg)
+        map_dependencies("RREPLACES", e.data, pkg)
+
+    bb.data.setVar("OVERRIDES", e.data.getVar("OVERRIDES", False) + ":virtclass-cross", e.data)
+}
+
+addhandler cross_virtclass_handler
+
 do_install () {
 	oe_runmake 'DESTDIR=${D}' install
 }