Patchwork [bitbake-devel] hob/bitbake: custom image is now using the base image

login
register
mail settings
Submitter Cristiana Voicu
Date Dec. 6, 2012, 1:15 p.m.
Message ID <1354799706-9226-1-git-send-email-cristiana.voicu@intel.com>
Download mbox | patch
Permalink /patch/40581/
State New
Headers show

Comments

Cristiana Voicu - Dec. 6, 2012, 1:15 p.m.
Till now, a custom image made in Hob was using only the packages from
the base image. Now it is using everything declared in the base image.
Also next to hob-image.bb, it creates another .bb file which is used
in building process. Those images are ignored by git.

[YOCTO #2601]
Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
---
 .gitignore                                  |    1 +
 bitbake/lib/bb/command.py                   |    8 +++++--
 bitbake/lib/bb/cooker.py                    |   31 +++++++++++++++++++++++++--
 bitbake/lib/bb/ui/crumbs/builder.py         |    3 +++
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |    5 +++--
 5 files changed, 42 insertions(+), 6 deletions(-)
Richard Purdie - Dec. 6, 2012, 3:22 p.m.
On Thu, 2012-12-06 at 15:15 +0200, Cristiana Voicu wrote:
> Till now, a custom image made in Hob was using only the packages from
> the base image. Now it is using everything declared in the base image.
> Also next to hob-image.bb, it creates another .bb file which is used
> in building process. Those images are ignored by git.
> 
> [YOCTO #2601]
> Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
> ---
>  .gitignore                                  |    1 +
>  bitbake/lib/bb/command.py                   |    8 +++++--
>  bitbake/lib/bb/cooker.py                    |   31 +++++++++++++++++++++++++--
>  bitbake/lib/bb/ui/crumbs/builder.py         |    3 +++
>  bitbake/lib/bb/ui/crumbs/hobeventhandler.py |    5 +++--
>  5 files changed, 42 insertions(+), 6 deletions(-)
> 
> diff --git a/.gitignore b/.gitignore
> index 88c91f6..003f09a 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -15,3 +15,4 @@ meta-*
>  *~
>  !meta-yocto
>  !meta-yocto-bsp
> +hob-image-*.bb
> diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
> index 3f28bca..48b09e4 100644
> --- a/bitbake/lib/bb/command.py
> +++ b/bitbake/lib/bb/command.py
> @@ -220,8 +220,12 @@ class CommandsAsync:
>          """
>          pkgs_to_build = params[0]
>          task = params[1]
> -
> -        command.cooker.buildTargets(pkgs_to_build, task)
> +        if len(params) > 2:
> +            base_image = params[2]
> +            package_queue = params[3]
> +            command.cooker.buildTargets(pkgs_to_build, task, base_image, package_queue)
> +        else:
> +            command.cooker.buildTargets(pkgs_to_build, task)
>      buildTargets.needcache = True
>  
>      def generateDepTreeEvent(self, command, params):
> diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
> index 6b58f91..22d8bd1 100644
> --- a/bitbake/lib/bb/cooker.py
> +++ b/bitbake/lib/bb/cooker.py
> @@ -23,7 +23,7 @@
>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  
>  from __future__ import print_function
> -import sys, os, glob, os.path, re, time
> +import sys, os, glob, os.path, re, time, shutil
>  import atexit
>  import itertools
>  import logging
> @@ -1127,11 +1127,14 @@ class BBCooker:
>  
>          self.server_registration_cb(buildFileIdle, rq)
>  
> -    def buildTargets(self, targets, task):
> +    def buildTargets(self, targets, task, base_image=None, package_queue=None):
>          """
>          Attempt to build the targets specified
>          """
>  
> +        if base_image != None and targets[0] == "hob-image":
> +            self.prepareHobImage(base_image, package_queue)
> +
>          # Need files parsed
>          self.updateCache()
>  
> @@ -1188,6 +1191,30 @@ class BBCooker:
>  
>          self.server_registration_cb(buildTargetsIdle, rq)

This looks good, I'd just ask for one tweak.

Rather than overload "buildTargets", lets add a new command say
"generateNewImage" which generates the this. Lets also not make this
"hob" specific, lets pass in the necessary parameters.

This may mean we need to also add a command to run "matchFile" on the
server so we can call the "generateNewImage" command with the right
options.

Cheers,

Richard


> +    def prepareHobImage(self, base_image, package_queue):
> +        '''
> +        Create a new hob-image with a "require" base_image statement
> +        '''
> +        hob_image = self.matchFile("hob-image.bb")
> +        base_image = self.matchFile(str(base_image) + ".bb")
> +        with open(hob_image, "a") as hobimagefile:
> +            hobimagefile.write("require " + base_image + "\n")
> +            package_install = "PACKAGE_INSTALL_forcevariable = \""
> +            for package in package_queue:
> +                package_install += str(package) + " "
> +            package_install += "\"\n"
> +            hobimagefile.write(package_install)
> +
> +        dir_hob_image = os.path.dirname(hob_image)
> +        timestr = time.strftime("%Y%m%d-%H%M%S")
> +        dest = dir_hob_image + "/hob-image-" + str(timestr) + ".bb"
> +        shutil.copyfile(hob_image, dest)
> +
> +        self.parser.reparse(hob_image)
> +
> +        with open(hob_image, "w") as hobimagefile:
> +            hobimagefile.write("inherit image\n")
> +
>      def updateCache(self):
>          if self.state == state.running:
>              return
> diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py
> index 2f3d6d0..663c322 100755
> --- a/bitbake/lib/bb/ui/crumbs/builder.py
> +++ b/bitbake/lib/bb/ui/crumbs/builder.py
> @@ -611,15 +611,18 @@ class Builder(gtk.Window):
>          # Build image
>          self.set_user_config()
>          toolchain_packages = []
> +        base_image = None
>          if self.configuration.toolchain_build:
>              toolchain_packages = self.package_model.get_selected_packages_toolchain()
>          if self.configuration.selected_image == self.recipe_model.__custom_image__:
>              packages = self.package_model.get_selected_packages()
>              image = self.hob_image
> +            base_image = self.configuration.initial_selected_image
>          else:
>              packages = []
>              image = self.configuration.selected_image
>          self.handler.generate_image(image,
> +                                    base_image,
>                                      self.hob_toolchain,
>                                      packages,
>                                      toolchain_packages,
> diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> index 8a2ac5f..1583f76 100644
> --- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> @@ -166,7 +166,7 @@ class HobHandler(gobject.GObject):
>              if self.toolchain_packages:
>                  self.runCommand(["setVariable", "TOOLCHAIN_TARGET_TASK", " ".join(self.toolchain_packages)])
>                  targets.append(self.toolchain)
> -            self.runCommand(["buildTargets", targets, self.default_task])
> +            self.runCommand(["buildTargets", targets, self.default_task, self.base_image, self.package_queue])
>  
>      def display_error(self):
>          self.clear_busy()
> @@ -386,8 +386,9 @@ class HobHandler(gobject.GObject):
>          self.commands_async.append(self.SUB_BUILD_RECIPES)
>          self.run_next_command(self.GENERATE_PACKAGES)
>  
> -    def generate_image(self, image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
> +    def generate_image(self, image, base_image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
>          self.image = image
> +        self.base_image = base_image
>          self.toolchain = toolchain
>          self.package_queue = image_packages
>          self.toolchain_packages = toolchain_packages
Cristiana Voicu - Dec. 6, 2012, 3:35 p.m.
Thanks! I will change it and I will send a new version.
Cristiana

-----Original Message-----
From: Richard Purdie [mailto:richard.purdie@linuxfoundation.org] 
Sent: Thursday, December 06, 2012 5:22 PM
To: Voicu, Cristiana
Cc: bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH] hob/bitbake: custom image is now using the base image

On Thu, 2012-12-06 at 15:15 +0200, Cristiana Voicu wrote:
> Till now, a custom image made in Hob was using only the packages from 
> the base image. Now it is using everything declared in the base image.
> Also next to hob-image.bb, it creates another .bb file which is used 
> in building process. Those images are ignored by git.
> 
> [YOCTO #2601]
> Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
> ---
>  .gitignore                                  |    1 +
>  bitbake/lib/bb/command.py                   |    8 +++++--
>  bitbake/lib/bb/cooker.py                    |   31 +++++++++++++++++++++++++--
>  bitbake/lib/bb/ui/crumbs/builder.py         |    3 +++
>  bitbake/lib/bb/ui/crumbs/hobeventhandler.py |    5 +++--
>  5 files changed, 42 insertions(+), 6 deletions(-)
> 
> diff --git a/.gitignore b/.gitignore
> index 88c91f6..003f09a 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -15,3 +15,4 @@ meta-*
>  *~
>  !meta-yocto
>  !meta-yocto-bsp
> +hob-image-*.bb
> diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py 
> index 3f28bca..48b09e4 100644
> --- a/bitbake/lib/bb/command.py
> +++ b/bitbake/lib/bb/command.py
> @@ -220,8 +220,12 @@ class CommandsAsync:
>          """
>          pkgs_to_build = params[0]
>          task = params[1]
> -
> -        command.cooker.buildTargets(pkgs_to_build, task)
> +        if len(params) > 2:
> +            base_image = params[2]
> +            package_queue = params[3]
> +            command.cooker.buildTargets(pkgs_to_build, task, base_image, package_queue)
> +        else:
> +            command.cooker.buildTargets(pkgs_to_build, task)
>      buildTargets.needcache = True
>  
>      def generateDepTreeEvent(self, command, params):
> diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index 
> 6b58f91..22d8bd1 100644
> --- a/bitbake/lib/bb/cooker.py
> +++ b/bitbake/lib/bb/cooker.py
> @@ -23,7 +23,7 @@
>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  
>  from __future__ import print_function -import sys, os, glob, os.path, 
> re, time
> +import sys, os, glob, os.path, re, time, shutil
>  import atexit
>  import itertools
>  import logging
> @@ -1127,11 +1127,14 @@ class BBCooker:
>  
>          self.server_registration_cb(buildFileIdle, rq)
>  
> -    def buildTargets(self, targets, task):
> +    def buildTargets(self, targets, task, base_image=None, package_queue=None):
>          """
>          Attempt to build the targets specified
>          """
>  
> +        if base_image != None and targets[0] == "hob-image":
> +            self.prepareHobImage(base_image, package_queue)
> +
>          # Need files parsed
>          self.updateCache()
>  
> @@ -1188,6 +1191,30 @@ class BBCooker:
>  
>          self.server_registration_cb(buildTargetsIdle, rq)

This looks good, I'd just ask for one tweak.

Rather than overload "buildTargets", lets add a new command say "generateNewImage" which generates the this. Lets also not make this "hob" specific, lets pass in the necessary parameters.

This may mean we need to also add a command to run "matchFile" on the server so we can call the "generateNewImage" command with the right options.

Cheers,

Richard


> +    def prepareHobImage(self, base_image, package_queue):
> +        '''
> +        Create a new hob-image with a "require" base_image statement
> +        '''
> +        hob_image = self.matchFile("hob-image.bb")
> +        base_image = self.matchFile(str(base_image) + ".bb")
> +        with open(hob_image, "a") as hobimagefile:
> +            hobimagefile.write("require " + base_image + "\n")
> +            package_install = "PACKAGE_INSTALL_forcevariable = \""
> +            for package in package_queue:
> +                package_install += str(package) + " "
> +            package_install += "\"\n"
> +            hobimagefile.write(package_install)
> +
> +        dir_hob_image = os.path.dirname(hob_image)
> +        timestr = time.strftime("%Y%m%d-%H%M%S")
> +        dest = dir_hob_image + "/hob-image-" + str(timestr) + ".bb"
> +        shutil.copyfile(hob_image, dest)
> +
> +        self.parser.reparse(hob_image)
> +
> +        with open(hob_image, "w") as hobimagefile:
> +            hobimagefile.write("inherit image\n")
> +
>      def updateCache(self):
>          if self.state == state.running:
>              return
> diff --git a/bitbake/lib/bb/ui/crumbs/builder.py 
> b/bitbake/lib/bb/ui/crumbs/builder.py
> index 2f3d6d0..663c322 100755
> --- a/bitbake/lib/bb/ui/crumbs/builder.py
> +++ b/bitbake/lib/bb/ui/crumbs/builder.py
> @@ -611,15 +611,18 @@ class Builder(gtk.Window):
>          # Build image
>          self.set_user_config()
>          toolchain_packages = []
> +        base_image = None
>          if self.configuration.toolchain_build:
>              toolchain_packages = self.package_model.get_selected_packages_toolchain()
>          if self.configuration.selected_image == self.recipe_model.__custom_image__:
>              packages = self.package_model.get_selected_packages()
>              image = self.hob_image
> +            base_image = self.configuration.initial_selected_image
>          else:
>              packages = []
>              image = self.configuration.selected_image
>          self.handler.generate_image(image,
> +                                    base_image,
>                                      self.hob_toolchain,
>                                      packages,
>                                      toolchain_packages, diff --git 
> a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py 
> b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> index 8a2ac5f..1583f76 100644
> --- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
> @@ -166,7 +166,7 @@ class HobHandler(gobject.GObject):
>              if self.toolchain_packages:
>                  self.runCommand(["setVariable", "TOOLCHAIN_TARGET_TASK", " ".join(self.toolchain_packages)])
>                  targets.append(self.toolchain)
> -            self.runCommand(["buildTargets", targets, self.default_task])
> +            self.runCommand(["buildTargets", targets, 
> + self.default_task, self.base_image, self.package_queue])
>  
>      def display_error(self):
>          self.clear_busy()
> @@ -386,8 +386,9 @@ class HobHandler(gobject.GObject):
>          self.commands_async.append(self.SUB_BUILD_RECIPES)
>          self.run_next_command(self.GENERATE_PACKAGES)
>  
> -    def generate_image(self, image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
> +    def generate_image(self, image, base_image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
>          self.image = image
> +        self.base_image = base_image
>          self.toolchain = toolchain
>          self.package_queue = image_packages
>          self.toolchain_packages = toolchain_packages

Patch

diff --git a/.gitignore b/.gitignore
index 88c91f6..003f09a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@  meta-*
 *~
 !meta-yocto
 !meta-yocto-bsp
+hob-image-*.bb
diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
index 3f28bca..48b09e4 100644
--- a/bitbake/lib/bb/command.py
+++ b/bitbake/lib/bb/command.py
@@ -220,8 +220,12 @@  class CommandsAsync:
         """
         pkgs_to_build = params[0]
         task = params[1]
-
-        command.cooker.buildTargets(pkgs_to_build, task)
+        if len(params) > 2:
+            base_image = params[2]
+            package_queue = params[3]
+            command.cooker.buildTargets(pkgs_to_build, task, base_image, package_queue)
+        else:
+            command.cooker.buildTargets(pkgs_to_build, task)
     buildTargets.needcache = True
 
     def generateDepTreeEvent(self, command, params):
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 6b58f91..22d8bd1 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -23,7 +23,7 @@ 
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 from __future__ import print_function
-import sys, os, glob, os.path, re, time
+import sys, os, glob, os.path, re, time, shutil
 import atexit
 import itertools
 import logging
@@ -1127,11 +1127,14 @@  class BBCooker:
 
         self.server_registration_cb(buildFileIdle, rq)
 
-    def buildTargets(self, targets, task):
+    def buildTargets(self, targets, task, base_image=None, package_queue=None):
         """
         Attempt to build the targets specified
         """
 
+        if base_image != None and targets[0] == "hob-image":
+            self.prepareHobImage(base_image, package_queue)
+
         # Need files parsed
         self.updateCache()
 
@@ -1188,6 +1191,30 @@  class BBCooker:
 
         self.server_registration_cb(buildTargetsIdle, rq)
 
+    def prepareHobImage(self, base_image, package_queue):
+        '''
+        Create a new hob-image with a "require" base_image statement
+        '''
+        hob_image = self.matchFile("hob-image.bb")
+        base_image = self.matchFile(str(base_image) + ".bb")
+        with open(hob_image, "a") as hobimagefile:
+            hobimagefile.write("require " + base_image + "\n")
+            package_install = "PACKAGE_INSTALL_forcevariable = \""
+            for package in package_queue:
+                package_install += str(package) + " "
+            package_install += "\"\n"
+            hobimagefile.write(package_install)
+
+        dir_hob_image = os.path.dirname(hob_image)
+        timestr = time.strftime("%Y%m%d-%H%M%S")
+        dest = dir_hob_image + "/hob-image-" + str(timestr) + ".bb"
+        shutil.copyfile(hob_image, dest)
+
+        self.parser.reparse(hob_image)
+
+        with open(hob_image, "w") as hobimagefile:
+            hobimagefile.write("inherit image\n")
+
     def updateCache(self):
         if self.state == state.running:
             return
diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py
index 2f3d6d0..663c322 100755
--- a/bitbake/lib/bb/ui/crumbs/builder.py
+++ b/bitbake/lib/bb/ui/crumbs/builder.py
@@ -611,15 +611,18 @@  class Builder(gtk.Window):
         # Build image
         self.set_user_config()
         toolchain_packages = []
+        base_image = None
         if self.configuration.toolchain_build:
             toolchain_packages = self.package_model.get_selected_packages_toolchain()
         if self.configuration.selected_image == self.recipe_model.__custom_image__:
             packages = self.package_model.get_selected_packages()
             image = self.hob_image
+            base_image = self.configuration.initial_selected_image
         else:
             packages = []
             image = self.configuration.selected_image
         self.handler.generate_image(image,
+                                    base_image,
                                     self.hob_toolchain,
                                     packages,
                                     toolchain_packages,
diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
index 8a2ac5f..1583f76 100644
--- a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
+++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
@@ -166,7 +166,7 @@  class HobHandler(gobject.GObject):
             if self.toolchain_packages:
                 self.runCommand(["setVariable", "TOOLCHAIN_TARGET_TASK", " ".join(self.toolchain_packages)])
                 targets.append(self.toolchain)
-            self.runCommand(["buildTargets", targets, self.default_task])
+            self.runCommand(["buildTargets", targets, self.default_task, self.base_image, self.package_queue])
 
     def display_error(self):
         self.clear_busy()
@@ -386,8 +386,9 @@  class HobHandler(gobject.GObject):
         self.commands_async.append(self.SUB_BUILD_RECIPES)
         self.run_next_command(self.GENERATE_PACKAGES)
 
-    def generate_image(self, image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
+    def generate_image(self, image, base_image, toolchain, image_packages=[], toolchain_packages=[], default_task="build"):
         self.image = image
+        self.base_image = base_image
         self.toolchain = toolchain
         self.package_queue = image_packages
         self.toolchain_packages = toolchain_packages