[1/2] base: improve PACKAGECONFIG handling logic

Submitted by Ross Burton on Sept. 10, 2013, 5:15 p.m.

Details

Message ID 1378833306-27394-1-git-send-email-ross.burton@intel.com
State New
Headers show

Commit Message

Ross Burton Sept. 10, 2013, 5:15 p.m.
The existing code for handling PACKAGECONFIG lists wasn't the cleanest Python
around.  Instead of diving into the list directly using indices and lengths, use
pop() to iterate through the list.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/classes/base.bbclass |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index dfa580c..12c8741 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -420,7 +420,7 @@  python () {
         def appendVar(varname, appends):
             if not appends:
                 return
-            if varname.find("DEPENDS") != -1:
+            if "DEPENDS_" in varname:
                 if pn.startswith("nativesdk-"):
                     appends = expandFilter(appends, "", "nativesdk-")
                 if pn.endswith("-native"):
@@ -442,12 +442,15 @@  python () {
                 bb.error("Only enable,disable,depend,rdepend can be specified!")
 
             if flag in pkgconfig:
-                if num >= 3 and items[2]:
-                    extradeps.append(items[2])
-                if num >= 4 and items[3]:
-                    extrardeps.append(items[3])
-                if num >= 1 and items[0]:
-                    extraconf.append(items[0])
+                if items:
+                    extraconf.append(items.pop(0))
+                # Skip over disable
+                if items:
+                    items.pop(0)
+                if items:
+                    extradeps.append(items.pop(0))
+                if items:
+                    extrardeps.append(items.pop(0))
             elif num >= 2 and items[1]:
                     extraconf.append(items[1])
         appendVar('DEPENDS', extradeps)

Comments

Ross Burton Sept. 10, 2013, 5:17 p.m.
On 10 September 2013 18:15, Ross Burton <ross.burton@intel.com> wrote:
> -                if num >= 3 and items[2]:
> -                    extradeps.append(items[2])
> -                if num >= 4 and items[3]:
> -                    extrardeps.append(items[3])
> -                if num >= 1 and items[0]:
> -                    extraconf.append(items[0])
> +                if items:
> +                    extraconf.append(items.pop(0))
> +                # Skip over disable
> +                if items:
> +                    items.pop(0)
> +                if items:
> +                    extradeps.append(items.pop(0))
> +                if items:
> +                    extrardeps.append(items.pop(0))

I should note that in a PACKAGECONFIG[foo] such as ",,,foo" this will
add some whitespace to EXTRA_OECONF and DEPENDS.  If this is a massive
concern I can sort it, but the clear code trumps the odd extra
whitespace in my mind.

Ross
Martin Jansa Sept. 10, 2013, 6:49 p.m.
On Tue, Sep 10, 2013 at 06:17:27PM +0100, Burton, Ross wrote:
> On 10 September 2013 18:15, Ross Burton <ross.burton@intel.com> wrote:
> > -                if num >= 3 and items[2]:
> > -                    extradeps.append(items[2])
> > -                if num >= 4 and items[3]:
> > -                    extrardeps.append(items[3])
> > -                if num >= 1 and items[0]:
> > -                    extraconf.append(items[0])
> > +                if items:
> > +                    extraconf.append(items.pop(0))
> > +                # Skip over disable
> > +                if items:
> > +                    items.pop(0)
> > +                if items:
> > +                    extradeps.append(items.pop(0))
> > +                if items:
> > +                    extrardeps.append(items.pop(0))
> 
> I should note that in a PACKAGECONFIG[foo] such as ",,,foo" this will
> add some whitespace to EXTRA_OECONF and DEPENDS.  If this is a massive
> concern I can sort it, but the clear code trumps the odd extra
> whitespace in my mind.

EXTRA_OECONF/DEPENDS space will probably force do_compile/do_install
tasks to execute again, while RDEPENDS/RRECOMMENDS only PACKAGECONFIGs
could be enabled with only do_package re-executed.

I don't know how many PACKAGECONFIG options we have without first 3
parameters, but in your example with foo it would be significant change.