Patchwork [v2] base.bbclass: Add support to EXTRA_DISTRO_FEATURES

login
register
mail settings
Submitter Otavio Salvador
Date July 31, 2013, 1:11 a.m.
Message ID <1375233090-5072-1-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/54805/
State New
Headers show

Comments

Otavio Salvador - July 31, 2013, 1:11 a.m.
This allow the addition and removal of distro features easily. To add
a feature, use:

 EXTRA_DISTRO_FEATURES += "wayland"

and to remove, use '~' prefix, as:

 EXTRA_DISTRO_FEATURES += "~x11"

This code has been mostly copied from Mentor Graphics public layer but
changed the variable name for a more descriptive name. The original
code can be seen at user_feature.bbclass at:

 http://git.yoctoproject.org/cgit/cgit.cgi/meta-mentor

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
Changes for v2:
- Use data copy to fix wrong prepend/append expanding.

 meta/classes/base.bbclass |  4 ++++
 meta/lib/oe/utils.py      | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
Otavio Salvador - July 31, 2013, 1:35 a.m.
On Tue, Jul 30, 2013 at 10:11 PM, Otavio Salvador
<otavio@ossystems.com.br> wrote:
> This allow the addition and removal of distro features easily. To add
> a feature, use:
>
>  EXTRA_DISTRO_FEATURES += "wayland"
>
> and to remove, use '~' prefix, as:
>
>  EXTRA_DISTRO_FEATURES += "~x11"
>
> This code has been mostly copied from Mentor Graphics public layer but
> changed the variable name for a more descriptive name. The original
> code can be seen at user_feature.bbclass at:
>
>  http://git.yoctoproject.org/cgit/cgit.cgi/meta-mentor
>
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>

Both does not work for all cases. I am still checking why.

--
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
Ross Burton - July 31, 2013, 8:51 a.m.
On 31 July 2013 02:11, Otavio Salvador <otavio@ossystems.com.br> wrote:
> This allow the addition and removal of distro features easily. To add
> a feature, use:
>
>  EXTRA_DISTRO_FEATURES += "wayland"
>
> and to remove, use '~' prefix, as:
>
>  EXTRA_DISTRO_FEATURES += "~x11"

I'm not sure I like the use of "extra" and "remove", as they're
contradictory.  It's too early to come up with a better suggestion
though. :(

Ross
Otavio Salvador - July 31, 2013, 11:41 a.m.
On Wed, Jul 31, 2013 at 5:51 AM, Burton, Ross <ross.burton@intel.com> wrote:
> On 31 July 2013 02:11, Otavio Salvador <otavio@ossystems.com.br> wrote:
>> This allow the addition and removal of distro features easily. To add
>> a feature, use:
>>
>>  EXTRA_DISTRO_FEATURES += "wayland"
>>
>> and to remove, use '~' prefix, as:
>>
>>  EXTRA_DISTRO_FEATURES += "~x11"
>
> I'm not sure I like the use of "extra" and "remove", as they're
> contradictory.  It's too early to come up with a better suggestion
> though. :(

I agree but I couldn't also come up with better name for this.

--
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
Phil Blundell - July 31, 2013, 11:47 a.m.
On Tue, 2013-07-30 at 22:11 -0300, Otavio Salvador wrote:
> +    l = d.createCopy()
> +    l.finalize()

Doesn't this mean you're now going to get the overrides applied twice?
It seems as though making a copy here kind of defeats the point of
calling finalize() in the first place.

p.
Otavio Salvador - July 31, 2013, 3:18 p.m.
On Wed, Jul 31, 2013 at 8:47 AM, Phil Blundell <pb@pbcl.net> wrote:
> On Tue, 2013-07-30 at 22:11 -0300, Otavio Salvador wrote:
>> +    l = d.createCopy()
>> +    l.finalize()
>
> Doesn't this mean you're now going to get the overrides applied twice?
> It seems as though making a copy here kind of defeats the point of
> calling finalize() in the first place.

I sent a v3 which fixes the issue.

Patch

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index 9c92e0b..83f6458 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -298,6 +298,9 @@  def buildcfg_neededvars(d):
     if pesteruser:
         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))
 
+EXTRA_DISTRO_FEATURES ?= ""
+EXTRA_DISTRO_FEATURES[type] = "list"
+
 addhandler base_eventhandler
 base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.BuildStarted"
 python base_eventhandler() {
@@ -307,6 +310,7 @@  python base_eventhandler() {
         preferred_ml_updates(e.data)
         oe.utils.features_backfill("DISTRO_FEATURES", e.data)
         oe.utils.features_backfill("MACHINE_FEATURES", e.data)
+        oe.utils.extra_distro_features(e.data)
 
     if isinstance(e, bb.event.BuildStarted):
         localdata = bb.data.createCopy(e.data)
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 82987e8..b2e65a4 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -117,6 +117,27 @@  def features_backfill(var,d):
     if addfeatures:
         d.appendVar(var, " " + " ".join(addfeatures))
 
+def extra_distro_features(d):
+    import oe.data
+
+    l = d.createCopy()
+    l.finalize()
+
+    extra_features = oe.data.typed_value('EXTRA_DISTRO_FEATURES', l)
+    if not extra_features:
+        return
+
+    distro_features = l.getVar('DISTRO_FEATURES', True).split()
+    for feature in extra_features:
+        if feature.startswith('~'):
+            feature = feature[1:]
+            if feature in distro_features:
+                distro_features.remove(feature)
+        else:
+            if feature not in distro_features:
+                distro_features.append(feature)
+
+    d.setVar('DISTRO_FEATURES', ' '.join(distro_features))
 
 def packages_filter_out_system(d):
     """