Patchwork [2/7] wic: Create and use new functions for getting bitbake variables

login
register
mail settings
Submitter tom.zanussi@linux.intel.com
Date Feb. 4, 2014, 1:16 a.m.
Message ID <967948fec09ce9eaf92e5780b45b7feb788bb1cb.1391476329.git.tom.zanussi@linux.intel.com>
Download mbox | patch
Permalink /patch/66287/
State Accepted
Commit 3cb93017e64b409e887e37f255ae49bb4e274465
Headers show

Comments

tom.zanussi@linux.intel.com - Feb. 4, 2014, 1:16 a.m.
Add get_bitbake_var() and bitbake_env_lines() functions for use by
plugins, which will need access to them for customization.

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 scripts/lib/image/engine.py      | 20 +++++++++++++++-----
 scripts/lib/mic/utils/oe/misc.py | 16 ++++++++++++++++
 scripts/wic                      |  6 ++++++
 3 files changed, 37 insertions(+), 5 deletions(-)

Patch

diff --git a/scripts/lib/image/engine.py b/scripts/lib/image/engine.py
index 0e8b89e..2dd98b9 100644
--- a/scripts/lib/image/engine.py
+++ b/scripts/lib/image/engine.py
@@ -60,16 +60,26 @@  def verify_build_env():
     return True
 
 
-def find_artifacts(image_name):
+def find_bitbake_env_lines(image_name):
     """
-    Gather the build artifacts for the current image (the image_name
-    e.g. core-image-minimal) for the current MACHINE set in local.conf
+    If image_name is empty, plugins might still be able to use the
+    environment, so set it regardless.
     """
     bitbake_env_cmd = "bitbake -e %s" % image_name
     rc, bitbake_env_lines = exec_cmd(bitbake_env_cmd)
     if rc != 0:
-        print "Couldn't get '%s' output, exiting." % bitbake_env_cmd
-        sys.exit(1)
+        print "Couldn't get '%s' output." % bitbake_env_cmd
+        return None
+
+    return bitbake_env_lines
+
+
+def find_artifacts(image_name):
+    """
+    Gather the build artifacts for the current image (the image_name
+    e.g. core-image-minimal) for the current MACHINE set in local.conf
+    """
+    bitbake_env_lines = get_bitbake_env_lines()
 
     rootfs_dir = kernel_dir = hdddir = staging_data_dir = native_sysroot = ""
 
diff --git a/scripts/lib/mic/utils/oe/misc.py b/scripts/lib/mic/utils/oe/misc.py
index 097d44c..77dfe03 100644
--- a/scripts/lib/mic/utils/oe/misc.py
+++ b/scripts/lib/mic/utils/oe/misc.py
@@ -109,6 +109,15 @@  def add_wks_var(key, val):
 
 BOOTDD_EXTRA_SPACE = 16384
 
+__bitbake_env_lines = ""
+
+def set_bitbake_env_lines(bitbake_env_lines):
+    global __bitbake_env_lines
+    __bitbake_env_lines = bitbake_env_lines
+
+def get_bitbake_env_lines():
+    return __bitbake_env_lines
+
 def get_line_val(line, key):
     """
     Extract the value from the VAR="val" string
@@ -118,3 +127,10 @@  def get_line_val(line, key):
         stripped_line = stripped_line.replace('\"', '')
         return stripped_line
     return None
+
+def get_bitbake_var(key):
+    for line in __bitbake_env_lines.split('\n'):
+        if (get_line_val(line, key)):
+            val = get_line_val(line, key)
+            return val
+    return None
diff --git a/scripts/wic b/scripts/wic
index b6fd16c..4ea5569 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -98,6 +98,12 @@  def wic_create_subcommand(args, usage_str):
 
     print "Creating image(s)...\n"
 
+    bitbake_env_lines = find_bitbake_env_lines(options.image_name)
+    if not bitbake_env_lines:
+        print "Couldn't get bitbake environment, exiting."
+        sys.exit(1)
+    set_bitbake_env_lines(bitbake_env_lines)
+
     bootimg_dir = staging_data_dir = hdddir = ""
 
     if options.image_name: