Patchwork [bitbake-devel,PATCH_V2,06/16] hob & bitbake: append a value to a variable from hob throught bitbake

login
register
mail settings
Submitter Cristiana Voicu
Date July 25, 2013, 11:42 a.m.
Message ID <1374752549-29471-7-git-send-email-cristiana.voicu@intel.com>
Download mbox | patch
Permalink /patch/54461/
State New
Headers show

Comments

Cristiana Voicu - July 25, 2013, 11:42 a.m.
It was necessary to append ${TOPDIR}/recipes/images to BBFILES.
Implemented the mechanism to append a value to a variable: a command and
the method in cooker.

[YOCTO #4193]
Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
---
 bitbake/lib/bb/command.py                   |    3 ++-
 bitbake/lib/bb/cooker.py                    |   29 +++++++++++++++++++++++++++
 bitbake/lib/bb/data.py                      |    4 ++++
 bitbake/lib/bb/ui/crumbs/builder.py         |    1 +
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |   15 +++++++++++++-
 5 files changed, 50 insertions(+), 2 deletions(-)
Paul Eggleton - July 26, 2013, 2:21 p.m.
Hi Cristiana,

On Thursday 25 July 2013 14:42:19 Cristiana Voicu wrote:
> --- a/bitbake/lib/bb/ui/crumbs/builder.py
> +++ b/bitbake/lib/bb/ui/crumbs/builder.py
> @@ -440,6 +440,7 @@ class Builder(gtk.Window):
>          self.handler.connect("recipe-populated",        
> self.handler_recipe_populated_cb) self.handler.connect("package-populated",
>        self.handler_package_populated_cb)
> 
> +        self.handler.append_to_bbfiles("${TOPDIR}/recipes/images/*bb")

Shoudn't this be /*.bb ?


>          self.initiate_new_build_async()
> 
>          signal.signal(signal.SIGINT, self.event_handle_SIGINT)
> diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py index 42fd0b9..e13ebe7 100644
> --- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> @@ -471,9 +471,22 @@ class HobHandler(gobject.GObject):
> 
>      def set_var_in_file(self, var, val, default_file=None):
>          self.runCommand(["enableDataTracking"])
> -        self.server.runCommand(["setVarFile", var, val, default_file])
> +        self.server.runCommand(["setVarFile", var, val, default_file,
> "set"]) self.runCommand(["disableDataTracking"])
> 
> +    def append_var_in_file(self, var, val, default_file=None):
> +        self.server.runCommand(["setVarFile", var, val, default_file,
> "append"]) +
> +    def append_to_bbfiles(self, val):
> +        bbfiles = self.runCommand(["getVariable", "BBFILES"]) or ""
> +        bbfiles = bbfiles.split()
> +        # replace TOPDIR in val, if necessary
> +        if "${TOPDIR}" in val:
> +            topdir = self.get_topdir()
> +            val = val.replace("${TOPDIR}", topdir)
> +        if val not in bbfiles:
> +            self.append_var_in_file("BBFILES",
> "${TOPDIR}/recipes/images/*bb", "local.conf") +

1) We should not be expanding ${TOPDIR} using direct string replacement. Do we 
even need to do this?

2) In any case it appears to be using a hardcoded value instead of val when it 
calls append_var_in_file()

Cheers,
Paul
Cristiana Voicu - July 26, 2013, 2:35 p.m.
Hi Paul,

I have implemented this way because Hob receives BB_FILES already expanded, when it uses getVariable() method.
Also I chose to save it hardcoded (using TOPDIR), to be more general in local.conf (in case the local.conf is moved)
Thanks,
Cristiana 


-----Original Message-----
From: Paul Eggleton [mailto:paul.eggleton@linux.intel.com] 
Sent: Friday, July 26, 2013 5:22 PM
To: Voicu, Cristiana
Cc: bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH_V2 06/16] hob & bitbake: append a value to a variable from hob throught bitbake

Hi Cristiana,

On Thursday 25 July 2013 14:42:19 Cristiana Voicu wrote:
> --- a/bitbake/lib/bb/ui/crumbs/builder.py
> +++ b/bitbake/lib/bb/ui/crumbs/builder.py
> @@ -440,6 +440,7 @@ class Builder(gtk.Window):
>          self.handler.connect("recipe-populated",        
> self.handler_recipe_populated_cb) self.handler.connect("package-populated",
>        self.handler_package_populated_cb)
> 
> +        
> + self.handler.append_to_bbfiles("${TOPDIR}/recipes/images/*bb")

Shoudn't this be /*.bb ?


>          self.initiate_new_build_async()
> 
>          signal.signal(signal.SIGINT, self.event_handle_SIGINT) diff 
> --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py index 42fd0b9..e13ebe7 
> 100644
> --- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> @@ -471,9 +471,22 @@ class HobHandler(gobject.GObject):
> 
>      def set_var_in_file(self, var, val, default_file=None):
>          self.runCommand(["enableDataTracking"])
> -        self.server.runCommand(["setVarFile", var, val, default_file])
> +        self.server.runCommand(["setVarFile", var, val, default_file,
> "set"]) self.runCommand(["disableDataTracking"])
> 
> +    def append_var_in_file(self, var, val, default_file=None):
> +        self.server.runCommand(["setVarFile", var, val, default_file,
> "append"]) +
> +    def append_to_bbfiles(self, val):
> +        bbfiles = self.runCommand(["getVariable", "BBFILES"]) or ""
> +        bbfiles = bbfiles.split()
> +        # replace TOPDIR in val, if necessary
> +        if "${TOPDIR}" in val:
> +            topdir = self.get_topdir()
> +            val = val.replace("${TOPDIR}", topdir)
> +        if val not in bbfiles:
> +            self.append_var_in_file("BBFILES",
> "${TOPDIR}/recipes/images/*bb", "local.conf") +

1) We should not be expanding ${TOPDIR} using direct string replacement. Do we even need to do this?

2) In any case it appears to be using a hardcoded value instead of val when it calls append_var_in_file()

Cheers,
Paul
Paul Eggleton - July 26, 2013, 3:01 p.m.
On Friday 26 July 2013 14:35:38 Voicu, Cristiana wrote:
> > 1) We should not be expanding ${TOPDIR} using direct string replacement.
> > Do we even need to do this?
> 
> > 2) In any case it appears to be using a hardcoded value instead of val
> > when it calls append_var_in_file()
> 
> I have implemented this way because Hob receives BB_FILES already expanded,
> when it uses getVariable() method.

OK, but if you're going to expand the value you should use bitbake's own means 
of expanding it rather than trying to do so yourself.

> Also I chose to save it hardcoded (using TOPDIR), to be more general in
> local.conf (in case the local.conf is moved)

I agree you'd want ${TOPDIR} unexpanded in the value set in local.conf. 
However, if you pass in a path to the function (which in this case includes 
the ${TOPDIR} reference) surely that's the value you'd save into local.conf 
and not an additional hardcoded value?

Cheers,
Paul

Patch

diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
index c38eab7..460b597 100644
--- a/bitbake/lib/bb/command.py
+++ b/bitbake/lib/bb/command.py
@@ -230,7 +230,8 @@  class CommandsSync:
         var = params[0]
         val = params[1]
         default_file = params[2]
-        command.cooker.saveConfigurationVar(var, val, default_file)
+        op = params[3]
+        command.cooker.modifyConfigurationVar(var, val, default_file, op)
 
     def createConfigFile(self, command, params):
         """
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 096391f..9965417 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -162,6 +162,35 @@  class BBCooker:
         self.data = self.databuilder.data
         self.data_hash = self.databuilder.data_hash
 
+    def modifyConfigurationVar(self, var, val, default_file, op):
+        if op == "append":
+            self.appendConfigurationVar(var, val, default_file)
+        elif op == "set":
+            self.saveConfigurationVar(var, val, default_file)
+
+    def appendConfigurationVar(self, var, val, default_file):
+        #add append var operation to the end of default_file
+        default_file = bb.cookerdata.findConfigFile(default_file)
+
+        with open(default_file, 'r') as f:
+            contents = f.readlines()
+        f.close()
+
+        total = ""
+        for c in contents:
+            total += c
+
+        total += "#added by bitbake"
+        total += "\n%s += \"%s\"\n" % (var, val)
+
+        with open(default_file, 'w') as f:
+            f.write(total)
+        f.close()
+
+        #add to history
+        loginfo = {"op":append, "file":default_file, "line":total.count("\n")}
+        self.data.appendVar(var, val, **loginfo)
+
     def saveConfigurationVar(self, var, val, default_file):
 
         replaced = False
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py
index 87c4808..8c9cb0f 100644
--- a/bitbake/lib/bb/data.py
+++ b/bitbake/lib/bb/data.py
@@ -97,6 +97,10 @@  def delVar(var, d):
     """Removes a variable from the data set"""
     d.delVar(var)
 
+def appendVar(var, value, d):
+    """Append additional value to a variable"""
+    d.appendVar(var, value)
+
 def setVarFlag(var, flag, flagvalue, d):
     """Set a flag for a given variable to a given value"""
     d.setVarFlag(var, flag, flagvalue)
diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py
index 6bf4024..7e33f92 100755
--- a/bitbake/lib/bb/ui/crumbs/builder.py
+++ b/bitbake/lib/bb/ui/crumbs/builder.py
@@ -440,6 +440,7 @@  class Builder(gtk.Window):
         self.handler.connect("recipe-populated",         self.handler_recipe_populated_cb)
         self.handler.connect("package-populated",        self.handler_package_populated_cb)
 
+        self.handler.append_to_bbfiles("${TOPDIR}/recipes/images/*bb")
         self.initiate_new_build_async()
 
         signal.signal(signal.SIGINT, self.event_handle_SIGINT)
diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
index 42fd0b9..e13ebe7 100644
--- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
+++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
@@ -471,9 +471,22 @@  class HobHandler(gobject.GObject):
 
     def set_var_in_file(self, var, val, default_file=None):
         self.runCommand(["enableDataTracking"])
-        self.server.runCommand(["setVarFile", var, val, default_file])
+        self.server.runCommand(["setVarFile", var, val, default_file, "set"])
         self.runCommand(["disableDataTracking"])
 
+    def append_var_in_file(self, var, val, default_file=None):
+        self.server.runCommand(["setVarFile", var, val, default_file, "append"])
+
+    def append_to_bbfiles(self, val):
+        bbfiles = self.runCommand(["getVariable", "BBFILES"]) or ""
+        bbfiles = bbfiles.split()
+        # replace TOPDIR in val, if necessary
+        if "${TOPDIR}" in val:
+            topdir = self.get_topdir()
+            val = val.replace("${TOPDIR}", topdir)
+        if val not in bbfiles:
+            self.append_var_in_file("BBFILES", "${TOPDIR}/recipes/images/*bb", "local.conf")
+
     def get_parameters(self):
         # retrieve the parameters from bitbake
         params = {}