diff options
Diffstat (limited to 'scripts/lib/wic/utils/oe')
| -rw-r--r-- | scripts/lib/wic/utils/oe/__init__.py | 22 | ||||
| -rw-r--r-- | scripts/lib/wic/utils/oe/misc.py | 181 |
2 files changed, 203 insertions, 0 deletions
diff --git a/scripts/lib/wic/utils/oe/__init__.py b/scripts/lib/wic/utils/oe/__init__.py new file mode 100644 index 0000000000..0a81575a74 --- /dev/null +++ b/scripts/lib/wic/utils/oe/__init__.py | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # | ||
| 2 | # OpenEmbedded wic utils library | ||
| 3 | # | ||
| 4 | # Copyright (c) 2013, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # AUTHORS | ||
| 21 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 22 | # | ||
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py new file mode 100644 index 0000000000..87e30411b0 --- /dev/null +++ b/scripts/lib/wic/utils/oe/misc.py | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | # | ||
| 4 | # Copyright (c) 2013, Intel Corporation. | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | # DESCRIPTION | ||
| 21 | # This module provides a place to collect various wic-related utils | ||
| 22 | # for the OpenEmbedded Image Tools. | ||
| 23 | # | ||
| 24 | # AUTHORS | ||
| 25 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 26 | # | ||
| 27 | |||
| 28 | from wic import msger | ||
| 29 | from wic.utils import runner | ||
| 30 | |||
| 31 | def __exec_cmd(cmd_and_args, as_shell = False, catch = 3): | ||
| 32 | """ | ||
| 33 | Execute command, catching stderr, stdout | ||
| 34 | |||
| 35 | Need to execute as_shell if the command uses wildcards | ||
| 36 | """ | ||
| 37 | msger.debug("__exec_cmd: %s" % cmd_and_args) | ||
| 38 | args = cmd_and_args.split() | ||
| 39 | msger.debug(args) | ||
| 40 | |||
| 41 | if (as_shell): | ||
| 42 | rc, out = runner.runtool(cmd_and_args, catch) | ||
| 43 | else: | ||
| 44 | rc, out = runner.runtool(args, catch) | ||
| 45 | out = out.strip() | ||
| 46 | msger.debug("__exec_cmd: output for %s (rc = %d): %s" % \ | ||
| 47 | (cmd_and_args, rc, out)) | ||
| 48 | |||
| 49 | return (rc, out) | ||
| 50 | |||
| 51 | |||
| 52 | def exec_cmd(cmd_and_args, as_shell = False, catch = 3): | ||
| 53 | """ | ||
| 54 | Execute command, catching stderr, stdout | ||
| 55 | |||
| 56 | Exits if rc non-zero | ||
| 57 | """ | ||
| 58 | rc, out = __exec_cmd(cmd_and_args, as_shell, catch) | ||
| 59 | |||
| 60 | if rc != 0: | ||
| 61 | msger.error("exec_cmd: %s returned '%s' instead of 0" % (cmd_and_args, rc)) | ||
| 62 | |||
| 63 | return out | ||
| 64 | |||
| 65 | |||
| 66 | def exec_cmd_quiet(cmd_and_args, as_shell = False): | ||
| 67 | """ | ||
| 68 | Execute command, catching nothing in the output | ||
| 69 | |||
| 70 | Exits if rc non-zero | ||
| 71 | """ | ||
| 72 | return exec_cmd(cmd_and_args, as_shell, 0) | ||
| 73 | |||
| 74 | |||
| 75 | def exec_native_cmd(cmd_and_args, native_sysroot, catch = 3): | ||
| 76 | """ | ||
| 77 | Execute native command, catching stderr, stdout | ||
| 78 | |||
| 79 | Need to execute as_shell if the command uses wildcards | ||
| 80 | |||
| 81 | Always need to execute native commands as_shell | ||
| 82 | """ | ||
| 83 | native_paths = \ | ||
| 84 | "export PATH=%s/sbin:%s/usr/sbin:%s/usr/bin:$PATH" % \ | ||
| 85 | (native_sysroot, native_sysroot, native_sysroot) | ||
| 86 | native_cmd_and_args = "%s;%s" % (native_paths, cmd_and_args) | ||
| 87 | msger.debug("exec_native_cmd: %s" % cmd_and_args) | ||
| 88 | |||
| 89 | args = cmd_and_args.split() | ||
| 90 | msger.debug(args) | ||
| 91 | |||
| 92 | rc, out = __exec_cmd(native_cmd_and_args, True, catch) | ||
| 93 | |||
| 94 | if rc == 127: # shell command-not-found | ||
| 95 | msger.error("A native (host) program required to build the image " | ||
| 96 | "was not found (see details above). Please make sure " | ||
| 97 | "it's installed and try again.") | ||
| 98 | |||
| 99 | return (rc, out) | ||
| 100 | |||
| 101 | |||
| 102 | def exec_native_cmd_quiet(cmd_and_args, native_sysroot): | ||
| 103 | """ | ||
| 104 | Execute native command, catching nothing in the output | ||
| 105 | |||
| 106 | Need to execute as_shell if the command uses wildcards | ||
| 107 | |||
| 108 | Always need to execute native commands as_shell | ||
| 109 | """ | ||
| 110 | return exec_native_cmd(cmd_and_args, native_sysroot, 0) | ||
| 111 | |||
| 112 | |||
| 113 | # kickstart doesn't support variable substution in commands, so this | ||
| 114 | # is our current simplistic scheme for supporting that | ||
| 115 | |||
| 116 | wks_vars = dict() | ||
| 117 | |||
| 118 | def get_wks_var(key): | ||
| 119 | return wks_vars[key] | ||
| 120 | |||
| 121 | def add_wks_var(key, val): | ||
| 122 | wks_vars[key] = val | ||
| 123 | |||
| 124 | BOOTDD_EXTRA_SPACE = 16384 | ||
| 125 | IMAGE_EXTRA_SPACE = 10240 | ||
| 126 | |||
| 127 | __bitbake_env_lines = "" | ||
| 128 | |||
| 129 | def set_bitbake_env_lines(bitbake_env_lines): | ||
| 130 | global __bitbake_env_lines | ||
| 131 | __bitbake_env_lines = bitbake_env_lines | ||
| 132 | |||
| 133 | def get_bitbake_env_lines(): | ||
| 134 | return __bitbake_env_lines | ||
| 135 | |||
| 136 | def find_bitbake_env_lines(image_name): | ||
| 137 | """ | ||
| 138 | If image_name is empty, plugins might still be able to use the | ||
| 139 | environment, so set it regardless. | ||
| 140 | """ | ||
| 141 | if image_name: | ||
| 142 | bitbake_env_cmd = "bitbake -e %s" % image_name | ||
| 143 | else: | ||
| 144 | bitbake_env_cmd = "bitbake -e" | ||
| 145 | rc, bitbake_env_lines = __exec_cmd(bitbake_env_cmd) | ||
| 146 | if rc != 0: | ||
| 147 | print "Couldn't get '%s' output." % bitbake_env_cmd | ||
| 148 | return None | ||
| 149 | |||
| 150 | return bitbake_env_lines | ||
| 151 | |||
| 152 | def find_artifact(bitbake_env_lines, variable): | ||
| 153 | """ | ||
| 154 | Gather the build artifact for the current image (the image_name | ||
| 155 | e.g. core-image-minimal) for the current MACHINE set in local.conf | ||
| 156 | """ | ||
| 157 | retval = "" | ||
| 158 | |||
| 159 | for line in bitbake_env_lines.split('\n'): | ||
| 160 | if (get_line_val(line, variable)): | ||
| 161 | retval = get_line_val(line, variable) | ||
| 162 | break | ||
| 163 | |||
| 164 | return retval | ||
| 165 | |||
| 166 | def get_line_val(line, key): | ||
| 167 | """ | ||
| 168 | Extract the value from the VAR="val" string | ||
| 169 | """ | ||
| 170 | if line.startswith(key + "="): | ||
| 171 | stripped_line = line.split('=')[1] | ||
| 172 | stripped_line = stripped_line.replace('\"', '') | ||
| 173 | return stripped_line | ||
| 174 | return None | ||
| 175 | |||
| 176 | def get_bitbake_var(key): | ||
| 177 | for line in __bitbake_env_lines.split('\n'): | ||
| 178 | if (get_line_val(line, key)): | ||
| 179 | val = get_line_val(line, key) | ||
| 180 | return val | ||
| 181 | return None | ||
