diff options
Diffstat (limited to 'scripts/lib')
| -rw-r--r-- | scripts/lib/image/engine.py | 23 | ||||
| -rw-r--r-- | scripts/lib/wic/plugins/source/rootfs.py | 9 | ||||
| -rw-r--r-- | scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py | 6 | ||||
| -rw-r--r-- | scripts/lib/wic/utils/oe/misc.py | 82 |
4 files changed, 33 insertions, 87 deletions
diff --git a/scripts/lib/image/engine.py b/scripts/lib/image/engine.py index 47950f8d15..92dcc5a4f9 100644 --- a/scripts/lib/image/engine.py +++ b/scripts/lib/image/engine.py | |||
| @@ -60,29 +60,6 @@ def verify_build_env(): | |||
| 60 | return True | 60 | return True |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | def find_artifacts(image_name): | ||
| 64 | """ | ||
| 65 | Gather the build artifacts for the current image (the image_name | ||
| 66 | e.g. core-image-minimal) for the current MACHINE set in local.conf | ||
| 67 | """ | ||
| 68 | bitbake_env_lines = misc.get_bitbake_env_lines() | ||
| 69 | |||
| 70 | rootfs_dir = kernel_dir = bootimg_dir = native_sysroot = "" | ||
| 71 | |||
| 72 | for line in bitbake_env_lines.split('\n'): | ||
| 73 | if misc.get_line_val(line, "IMAGE_ROOTFS"): | ||
| 74 | rootfs_dir = misc.get_line_val(line, "IMAGE_ROOTFS") | ||
| 75 | continue | ||
| 76 | if misc.get_line_val(line, "DEPLOY_DIR_IMAGE"): | ||
| 77 | kernel_dir = misc.get_line_val(line, "DEPLOY_DIR_IMAGE") | ||
| 78 | continue | ||
| 79 | if misc.get_line_val(line, "STAGING_DIR_NATIVE"): | ||
| 80 | native_sysroot = misc.get_line_val(line, "STAGING_DIR_NATIVE") | ||
| 81 | continue | ||
| 82 | |||
| 83 | return (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) | ||
| 84 | |||
| 85 | |||
| 86 | CANNED_IMAGE_DIR = "lib/image/canned-wks" # relative to scripts | 63 | CANNED_IMAGE_DIR = "lib/image/canned-wks" # relative to scripts |
| 87 | SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR | 64 | SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR |
| 88 | 65 | ||
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py index 12fbf67a6e..a90712b247 100644 --- a/scripts/lib/wic/plugins/source/rootfs.py +++ b/scripts/lib/wic/plugins/source/rootfs.py | |||
| @@ -29,7 +29,7 @@ import os | |||
| 29 | 29 | ||
| 30 | from wic import msger | 30 | from wic import msger |
| 31 | from wic.pluginbase import SourcePlugin | 31 | from wic.pluginbase import SourcePlugin |
| 32 | from wic.utils.oe.misc import find_bitbake_env_lines, find_artifact | 32 | from wic.utils.oe.misc import get_bitbake_var |
| 33 | 33 | ||
| 34 | class RootfsPlugin(SourcePlugin): | 34 | class RootfsPlugin(SourcePlugin): |
| 35 | """ | 35 | """ |
| @@ -43,12 +43,7 @@ class RootfsPlugin(SourcePlugin): | |||
| 43 | if os.path.isdir(rootfs_dir): | 43 | if os.path.isdir(rootfs_dir): |
| 44 | return rootfs_dir | 44 | return rootfs_dir |
| 45 | 45 | ||
| 46 | bitbake_env_lines = find_bitbake_env_lines(rootfs_dir) | 46 | image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) |
| 47 | if not bitbake_env_lines: | ||
| 48 | msg = "Couldn't get bitbake environment, exiting." | ||
| 49 | msger.error(msg) | ||
| 50 | |||
| 51 | image_rootfs_dir = find_artifact(bitbake_env_lines, "IMAGE_ROOTFS") | ||
| 52 | if not os.path.isdir(image_rootfs_dir): | 47 | if not os.path.isdir(image_rootfs_dir): |
| 53 | msg = "No valid artifact IMAGE_ROOTFS from image named" | 48 | msg = "No valid artifact IMAGE_ROOTFS from image named" |
| 54 | msg += " %s has been found at %s, exiting.\n" % \ | 49 | msg += " %s has been found at %s, exiting.\n" % \ |
diff --git a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py index 533eaa7bd1..76e7b033fb 100644 --- a/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +++ b/scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py | |||
| @@ -59,11 +59,7 @@ class RootfsPlugin(SourcePlugin): | |||
| 59 | if os.path.isdir(rootfs_dir): | 59 | if os.path.isdir(rootfs_dir): |
| 60 | return rootfs_dir | 60 | return rootfs_dir |
| 61 | 61 | ||
| 62 | bitbake_env_lines = misc.find_bitbake_env_lines(rootfs_dir) | 62 | image_rootfs_dir = misc.get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) |
| 63 | if not bitbake_env_lines: | ||
| 64 | msger.error("Couldn't get bitbake environment, exiting.") | ||
| 65 | |||
| 66 | image_rootfs_dir = misc.find_artifact(bitbake_env_lines, "IMAGE_ROOTFS") | ||
| 67 | if not os.path.isdir(image_rootfs_dir): | 63 | if not os.path.isdir(image_rootfs_dir): |
| 68 | msg = "No valid artifact IMAGE_ROOTFS from image named" | 64 | msg = "No valid artifact IMAGE_ROOTFS from image named" |
| 69 | msg += " %s has been found at %s, exiting.\n" % \ | 65 | msg += " %s has been found at %s, exiting.\n" % \ |
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py index 2f916ddf45..1de6f46a38 100644 --- a/scripts/lib/wic/utils/oe/misc.py +++ b/scripts/lib/wic/utils/oe/misc.py | |||
| @@ -25,6 +25,8 @@ | |||
| 25 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | 25 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> |
| 26 | # | 26 | # |
| 27 | 27 | ||
| 28 | from collections import defaultdict | ||
| 29 | |||
| 28 | from wic import msger | 30 | from wic import msger |
| 29 | from wic.utils import runner | 31 | from wic.utils import runner |
| 30 | 32 | ||
| @@ -108,62 +110,38 @@ def add_wks_var(key, val): | |||
| 108 | 110 | ||
| 109 | BOOTDD_EXTRA_SPACE = 16384 | 111 | BOOTDD_EXTRA_SPACE = 16384 |
| 110 | 112 | ||
| 111 | __bitbake_env_lines = "" | 113 | _BITBAKE_VARS = defaultdict(dict) |
| 112 | |||
| 113 | def set_bitbake_env_lines(bitbake_env_lines): | ||
| 114 | global __bitbake_env_lines | ||
| 115 | __bitbake_env_lines = bitbake_env_lines | ||
| 116 | 114 | ||
| 117 | def get_bitbake_env_lines(): | 115 | def get_bitbake_var(var, image=None): |
| 118 | return __bitbake_env_lines | ||
| 119 | |||
| 120 | def find_bitbake_env_lines(image_name): | ||
| 121 | """ | ||
| 122 | If image_name is empty, plugins might still be able to use the | ||
| 123 | environment, so set it regardless. | ||
| 124 | """ | 116 | """ |
| 125 | if image_name: | 117 | Get bitbake variable value lazy way, i.e. run |
| 126 | bitbake_env_cmd = "bitbake -e %s" % image_name | 118 | 'bitbake -e' only when variable is requested. |
| 127 | else: | ||
| 128 | bitbake_env_cmd = "bitbake -e" | ||
| 129 | rc, bitbake_env_lines = __exec_cmd(bitbake_env_cmd) | ||
| 130 | if rc != 0: | ||
| 131 | print "Couldn't get '%s' output." % bitbake_env_cmd | ||
| 132 | print "Bitbake failed with error:\n%s\n" % bitbake_env_lines | ||
| 133 | return None | ||
| 134 | |||
| 135 | return bitbake_env_lines | ||
| 136 | |||
| 137 | def find_artifact(bitbake_env_lines, variable): | ||
| 138 | """ | 119 | """ |
| 139 | Gather the build artifact for the current image (the image_name | 120 | if image not in _BITBAKE_VARS: |
| 140 | e.g. core-image-minimal) for the current MACHINE set in local.conf | 121 | # Get bitbake -e output |
| 141 | """ | 122 | cmd = "bitbake -e" |
| 142 | retval = "" | 123 | if image: |
| 143 | 124 | cmd += " %s" % image | |
| 144 | for line in bitbake_env_lines.split('\n'): | 125 | rc, lines = __exec_cmd(cmd) |
| 145 | if get_line_val(line, variable): | 126 | if rc: |
| 146 | retval = get_line_val(line, variable) | 127 | print "Couldn't get '%s' output." % cmd |
| 147 | break | 128 | print "Bitbake failed with error:\n%s\n" % lines |
| 148 | 129 | return | |
| 149 | return retval | 130 | |
| 131 | # Parse bitbake -e output | ||
| 132 | for line in lines.split('\n'): | ||
| 133 | if "=" not in line: | ||
| 134 | continue | ||
| 135 | try: | ||
| 136 | key, val = line.split("=") | ||
| 137 | except ValueError: | ||
| 138 | continue | ||
| 139 | key = key.strip() | ||
| 140 | val = val.strip() | ||
| 141 | if key.replace('_', '').isalnum(): | ||
| 142 | _BITBAKE_VARS[image][key] = val.strip('"') | ||
| 150 | 143 | ||
| 151 | def get_line_val(line, key): | 144 | return _BITBAKE_VARS[image].get(var) |
| 152 | """ | ||
| 153 | Extract the value from the VAR="val" string | ||
| 154 | """ | ||
| 155 | if line.startswith(key + "="): | ||
| 156 | stripped_line = line.split('=')[1] | ||
| 157 | stripped_line = stripped_line.replace('\"', '') | ||
| 158 | return stripped_line | ||
| 159 | return None | ||
| 160 | |||
| 161 | def get_bitbake_var(key): | ||
| 162 | for line in __bitbake_env_lines.split('\n'): | ||
| 163 | if get_line_val(line, key): | ||
| 164 | val = get_line_val(line, key) | ||
| 165 | return val | ||
| 166 | return None | ||
| 167 | 145 | ||
| 168 | def parse_sourceparams(sourceparams): | 146 | def parse_sourceparams(sourceparams): |
| 169 | """ | 147 | """ |
