summaryrefslogtreecommitdiffstats
path: root/meta/classes/image_types_wic.bbclass
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-01 17:27:49 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-05 09:22:18 +0000
commitfaa2823801b77c3ba399deecc3068b2d2b7b6c7f (patch)
treeec68a48e8e47b97fcadf1fd30ccac56280d63c1f /meta/classes/image_types_wic.bbclass
parent67ed7f76dd5dc5a2920f1a824514dcbd996db7b5 (diff)
downloadpoky-faa2823801b77c3ba399deecc3068b2d2b7b6c7f.tar.gz
image: rename image-wic -> image_types_wic
Make name of the wic image type class consistent with existing naming scheme for image types. (From OE-Core rev: 4aab1b77d5f9403cbb3fae790069ef54821491fb) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/image_types_wic.bbclass')
-rw-r--r--meta/classes/image_types_wic.bbclass120
1 files changed, 120 insertions, 0 deletions
diff --git a/meta/classes/image_types_wic.bbclass b/meta/classes/image_types_wic.bbclass
new file mode 100644
index 0000000000..3e98959ed1
--- /dev/null
+++ b/meta/classes/image_types_wic.bbclass
@@ -0,0 +1,120 @@
1# The WICVARS variable is used to define list of bitbake variables used in wic code
2# variables from this list is written to <image>.env file
3WICVARS ?= "\
4 BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES \
5 IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \
6 ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH"
7
8WKS_FILE ??= "${IMAGE_BASENAME}.${MACHINE}.wks"
9WKS_FILES ?= "${WKS_FILE} ${IMAGE_BASENAME}.wks"
10WKS_SEARCH_PATH ?= "${THISDIR}:${@':'.join('%s/wic' % p for p in '${BBPATH}'.split(':'))}:${@':'.join('%s/scripts/lib/wic/canned-wks' % l for l in '${BBPATH}:${COREBASE}'.split(':'))}"
11WKS_FULL_PATH = "${@wks_search('${WKS_FILES}'.split(), '${WKS_SEARCH_PATH}') or ''}"
12
13def wks_search(files, search_path):
14 for f in files:
15 if os.path.isabs(f):
16 if os.path.exists(f):
17 return f
18 else:
19 searched = bb.utils.which(search_path, f)
20 if searched:
21 return searched
22
23WIC_CREATE_EXTRA_ARGS ?= ""
24
25IMAGE_CMD_wic () {
26 out="${IMGDEPLOYDIR}/${IMAGE_NAME}"
27 wks="${WKS_FULL_PATH}"
28 if [ -z "$wks" ]; then
29 bbfatal "No kickstart files from WKS_FILES were found: ${WKS_FILES}. Please set WKS_FILE or WKS_FILES appropriately."
30 fi
31
32 BUILDDIR="${TOPDIR}" wic create "$wks" --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" -o "$out/" ${WIC_CREATE_EXTRA_ARGS}
33 mv "$out/$(basename "${wks%.wks}")"*.direct "$out${IMAGE_NAME_SUFFIX}.wic"
34 rm -rf "$out/"
35}
36IMAGE_CMD_wic[vardepsexclude] = "WKS_FULL_PATH WKS_FILES"
37
38# Rebuild when the wks file or vars in WICVARS change
39USING_WIC = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic ' + ' '.join('wic.%s' % c for c in '${CONVERSIONTYPES}'.split()), '1', '', d)}"
40WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}"
41do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}"
42do_image_wic[depends] += "wic-tools:do_build"
43
44python () {
45 if d.getVar('USING_WIC') and 'do_bootimg' in d:
46 bb.build.addtask('do_image_wic', '', 'do_bootimg', d)
47}
48
49python do_write_wks_template () {
50 """Write out expanded template contents to WKS_FULL_PATH."""
51 import re
52
53 template_body = d.getVar('_WKS_TEMPLATE')
54
55 # Remove any remnant variable references left behind by the expansion
56 # due to undefined variables
57 expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
58 while True:
59 new_body = re.sub(expand_var_regexp, '', template_body)
60 if new_body == template_body:
61 break
62 else:
63 template_body = new_body
64
65 wks_file = d.getVar('WKS_FULL_PATH')
66 with open(wks_file, 'w') as f:
67 f.write(template_body)
68}
69
70python () {
71 if d.getVar('USING_WIC'):
72 wks_file_u = d.getVar('WKS_FULL_PATH', False)
73 wks_file = d.expand(wks_file_u)
74 base, ext = os.path.splitext(wks_file)
75 if ext == '.in' and os.path.exists(wks_file):
76 wks_out_file = os.path.join(d.getVar('WORKDIR'), os.path.basename(base))
77 d.setVar('WKS_FULL_PATH', wks_out_file)
78 d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
79 d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
80
81 # We need to re-parse each time the file changes, and bitbake
82 # needs to be told about that explicitly.
83 bb.parse.mark_dependency(d, wks_file)
84
85 try:
86 with open(wks_file, 'r') as f:
87 body = f.read()
88 except (IOError, OSError) as exc:
89 pass
90 else:
91 # Previously, I used expandWithRefs to get the dependency list
92 # and add it to WICVARS, but there's no point re-parsing the
93 # file in process_wks_template as well, so just put it in
94 # a variable and let the metadata deal with the deps.
95 d.setVar('_WKS_TEMPLATE', body)
96 bb.build.addtask('do_write_wks_template', 'do_image_wic', None, d)
97}
98
99#
100# Write environment variables used by wic
101# to tmp/sysroots/<machine>/imgdata/<image>.env
102#
103python do_rootfs_wicenv () {
104 wicvars = d.getVar('WICVARS')
105 if not wicvars:
106 return
107
108 stdir = d.getVar('STAGING_DIR')
109 outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
110 bb.utils.mkdirhier(outdir)
111 basename = d.getVar('IMAGE_BASENAME')
112 with open(os.path.join(outdir, basename) + '.env', 'w') as envf:
113 for var in wicvars.split():
114 value = d.getVar(var)
115 if value:
116 envf.write('%s="%s"\n' % (var, value.strip()))
117}
118addtask do_rootfs_wicenv after do_image before do_image_wic
119do_rootfs_wicenv[vardeps] += "${WICVARS}"
120do_rootfs_wicenv[prefuncs] = 'set_image_size'