diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2017-01-26 13:52:24 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-31 14:38:32 +0000 |
commit | 02dafba6ed8ebc718a4f513455fc034444543301 (patch) | |
tree | 0893fcb932e1a2a4d27d1c2b6bf80f79a3a369d7 /meta | |
parent | de23b7bb2f53149c9778fde55e5b3c710c51932d (diff) | |
download | poky-02dafba6ed8ebc718a4f513455fc034444543301.tar.gz |
image-wic: move wic code to image-wic.bbclass
There is a lot of wic code in image.bbclass and image_types.bbclass
Having all code separated in one file should make it more readable
and easier to maintain.
(From OE-Core rev: 786368568a9525212e69f5cbf6da236f0a6be013)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/image-wic.bbclass | 120 | ||||
-rw-r--r-- | meta/classes/image.bbclass | 25 | ||||
-rw-r--r-- | meta/classes/image_types.bbclass | 95 |
3 files changed, 122 insertions, 118 deletions
diff --git a/meta/classes/image-wic.bbclass b/meta/classes/image-wic.bbclass new file mode 100644 index 0000000000..2acfd659f1 --- /dev/null +++ b/meta/classes/image-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 | ||
3 | WICVARS ?= "\ | ||
4 | BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD HDDDIR IMAGE_BASENAME IMAGE_BOOT_FILES \ | ||
5 | IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD ISODIR MACHINE_ARCH RECIPE_SYSROOT_NATIVE \ | ||
6 | ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS" | ||
7 | |||
8 | WKS_FILE ??= "${IMAGE_BASENAME}.${MACHINE}.wks" | ||
9 | WKS_FILES ?= "${WKS_FILE} ${IMAGE_BASENAME}.wks" | ||
10 | WKS_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(':'))}" | ||
11 | WKS_FULL_PATH = "${@wks_search('${WKS_FILES}'.split(), '${WKS_SEARCH_PATH}') or ''}" | ||
12 | |||
13 | def 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 | |||
23 | WIC_CREATE_EXTRA_ARGS ?= "" | ||
24 | |||
25 | IMAGE_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 | } | ||
36 | IMAGE_CMD_wic[vardepsexclude] = "WKS_FULL_PATH WKS_FILES" | ||
37 | |||
38 | # Rebuild when the wks file or vars in WICVARS change | ||
39 | USING_WIC = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic ' + ' '.join('wic.%s' % c for c in '${CONVERSIONTYPES}'.split()), '1', '', d)}" | ||
40 | WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}" | ||
41 | do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}" | ||
42 | do_image_wic[depends] += "wic-tools:do_build" | ||
43 | |||
44 | python () { | ||
45 | if d.getVar('USING_WIC') and 'do_bootimg' in d: | ||
46 | bb.build.addtask('do_image_wic', '', 'do_bootimg', d) | ||
47 | } | ||
48 | |||
49 | python 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 | |||
70 | python () { | ||
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 | # | ||
103 | python 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 | } | ||
118 | addtask do_rootfs_wicenv after do_image before do_image_wic | ||
119 | do_rootfs_wicenv[vardeps] += "${WICVARS}" | ||
120 | do_rootfs_wicenv[prefuncs] = 'set_image_size' | ||
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass index e20e447680..613cd92600 100644 --- a/meta/classes/image.bbclass +++ b/meta/classes/image.bbclass | |||
@@ -187,6 +187,8 @@ python () { | |||
187 | IMAGE_CLASSES += "image_types" | 187 | IMAGE_CLASSES += "image_types" |
188 | inherit ${IMAGE_CLASSES} | 188 | inherit ${IMAGE_CLASSES} |
189 | 189 | ||
190 | inherit image-wic | ||
191 | |||
190 | IMAGE_POSTPROCESS_COMMAND ?= "" | 192 | IMAGE_POSTPROCESS_COMMAND ?= "" |
191 | 193 | ||
192 | # some default locales | 194 | # some default locales |
@@ -327,29 +329,6 @@ fakeroot python do_image_qa () { | |||
327 | } | 329 | } |
328 | addtask do_image_qa after do_image_complete before do_build | 330 | addtask do_image_qa after do_image_complete before do_build |
329 | 331 | ||
330 | # | ||
331 | # Write environment variables used by wic | ||
332 | # to tmp/sysroots/<machine>/imgdata/<image>.env | ||
333 | # | ||
334 | python do_rootfs_wicenv () { | ||
335 | wicvars = d.getVar('WICVARS') | ||
336 | if not wicvars: | ||
337 | return | ||
338 | |||
339 | stdir = d.getVar('STAGING_DIR') | ||
340 | outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata') | ||
341 | bb.utils.mkdirhier(outdir) | ||
342 | basename = d.getVar('IMAGE_BASENAME') | ||
343 | with open(os.path.join(outdir, basename) + '.env', 'w') as envf: | ||
344 | for var in wicvars.split(): | ||
345 | value = d.getVar(var) | ||
346 | if value: | ||
347 | envf.write('%s="%s"\n' % (var, value.strip())) | ||
348 | } | ||
349 | addtask do_rootfs_wicenv after do_image before do_image_wic | ||
350 | do_rootfs_wicenv[vardeps] += "${WICVARS}" | ||
351 | do_rootfs_wicenv[prefuncs] = 'set_image_size' | ||
352 | |||
353 | def setup_debugfs_variables(d): | 332 | def setup_debugfs_variables(d): |
354 | d.appendVar('IMAGE_ROOTFS', '-dbg') | 333 | d.appendVar('IMAGE_ROOTFS', '-dbg') |
355 | d.appendVar('IMAGE_LINK_NAME', '-dbg') | 334 | d.appendVar('IMAGE_LINK_NAME', '-dbg') |
diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass index 0e5f38a8b9..0adb6e4811 100644 --- a/meta/classes/image_types.bbclass +++ b/meta/classes/image_types.bbclass | |||
@@ -192,97 +192,6 @@ IMAGE_CMD_ubi () { | |||
192 | 192 | ||
193 | IMAGE_CMD_ubifs = "mkfs.ubifs -r ${IMAGE_ROOTFS} -o ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ubifs ${MKUBIFS_ARGS}" | 193 | IMAGE_CMD_ubifs = "mkfs.ubifs -r ${IMAGE_ROOTFS} -o ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ubifs ${MKUBIFS_ARGS}" |
194 | 194 | ||
195 | WKS_FILE ??= "${IMAGE_BASENAME}.${MACHINE}.wks" | ||
196 | WKS_FILES ?= "${WKS_FILE} ${IMAGE_BASENAME}.wks" | ||
197 | WKS_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(':'))}" | ||
198 | WKS_FULL_PATH = "${@wks_search('${WKS_FILES}'.split(), '${WKS_SEARCH_PATH}') or ''}" | ||
199 | |||
200 | def wks_search(files, search_path): | ||
201 | for f in files: | ||
202 | if os.path.isabs(f): | ||
203 | if os.path.exists(f): | ||
204 | return f | ||
205 | else: | ||
206 | searched = bb.utils.which(search_path, f) | ||
207 | if searched: | ||
208 | return searched | ||
209 | |||
210 | WIC_CREATE_EXTRA_ARGS ?= "" | ||
211 | |||
212 | IMAGE_CMD_wic () { | ||
213 | out="${IMGDEPLOYDIR}/${IMAGE_NAME}" | ||
214 | wks="${WKS_FULL_PATH}" | ||
215 | if [ -z "$wks" ]; then | ||
216 | bbfatal "No kickstart files from WKS_FILES were found: ${WKS_FILES}. Please set WKS_FILE or WKS_FILES appropriately." | ||
217 | fi | ||
218 | |||
219 | BUILDDIR="${TOPDIR}" wic create "$wks" --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -e "${IMAGE_BASENAME}" -o "$out/" ${WIC_CREATE_EXTRA_ARGS} | ||
220 | mv "$out/$(basename "${wks%.wks}")"*.direct "$out${IMAGE_NAME_SUFFIX}.wic" | ||
221 | rm -rf "$out/" | ||
222 | } | ||
223 | IMAGE_CMD_wic[vardepsexclude] = "WKS_FULL_PATH WKS_FILES" | ||
224 | |||
225 | # Rebuild when the wks file or vars in WICVARS change | ||
226 | USING_WIC = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic ' + ' '.join('wic.%s' % c for c in '${CONVERSIONTYPES}'.split()), '1', '', d)}" | ||
227 | WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}" | ||
228 | do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}" | ||
229 | do_image_wic[depends] += "wic-tools:do_build" | ||
230 | |||
231 | python () { | ||
232 | if d.getVar('USING_WIC') and 'do_bootimg' in d: | ||
233 | bb.build.addtask('do_image_wic', '', 'do_bootimg', d) | ||
234 | } | ||
235 | |||
236 | python do_write_wks_template () { | ||
237 | """Write out expanded template contents to WKS_FULL_PATH.""" | ||
238 | import re | ||
239 | |||
240 | template_body = d.getVar('_WKS_TEMPLATE') | ||
241 | |||
242 | # Remove any remnant variable references left behind by the expansion | ||
243 | # due to undefined variables | ||
244 | expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}") | ||
245 | while True: | ||
246 | new_body = re.sub(expand_var_regexp, '', template_body) | ||
247 | if new_body == template_body: | ||
248 | break | ||
249 | else: | ||
250 | template_body = new_body | ||
251 | |||
252 | wks_file = d.getVar('WKS_FULL_PATH') | ||
253 | with open(wks_file, 'w') as f: | ||
254 | f.write(template_body) | ||
255 | } | ||
256 | |||
257 | python () { | ||
258 | if d.getVar('USING_WIC'): | ||
259 | wks_file_u = d.getVar('WKS_FULL_PATH', False) | ||
260 | wks_file = d.expand(wks_file_u) | ||
261 | base, ext = os.path.splitext(wks_file) | ||
262 | if ext == '.in' and os.path.exists(wks_file): | ||
263 | wks_out_file = os.path.join(d.getVar('WORKDIR'), os.path.basename(base)) | ||
264 | d.setVar('WKS_FULL_PATH', wks_out_file) | ||
265 | d.setVar('WKS_TEMPLATE_PATH', wks_file_u) | ||
266 | d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True') | ||
267 | |||
268 | # We need to re-parse each time the file changes, and bitbake | ||
269 | # needs to be told about that explicitly. | ||
270 | bb.parse.mark_dependency(d, wks_file) | ||
271 | |||
272 | try: | ||
273 | with open(wks_file, 'r') as f: | ||
274 | body = f.read() | ||
275 | except (IOError, OSError) as exc: | ||
276 | pass | ||
277 | else: | ||
278 | # Previously, I used expandWithRefs to get the dependency list | ||
279 | # and add it to WICVARS, but there's no point re-parsing the | ||
280 | # file in process_wks_template as well, so just put it in | ||
281 | # a variable and let the metadata deal with the deps. | ||
282 | d.setVar('_WKS_TEMPLATE', body) | ||
283 | bb.build.addtask('do_write_wks_template', 'do_image_wic', None, d) | ||
284 | } | ||
285 | |||
286 | EXTRA_IMAGECMD = "" | 195 | EXTRA_IMAGECMD = "" |
287 | 196 | ||
288 | inherit siteinfo | 197 | inherit siteinfo |
@@ -379,7 +288,3 @@ IMAGE_EXTENSION_live = "hddimg iso" | |||
379 | # The IMAGE_TYPES_MASKED variable will be used to mask out from the IMAGE_FSTYPES, | 288 | # The IMAGE_TYPES_MASKED variable will be used to mask out from the IMAGE_FSTYPES, |
380 | # images that will not be built at do_rootfs time: vmdk, vdi, qcow2, hdddirect, hddimg, iso, etc. | 289 | # images that will not be built at do_rootfs time: vmdk, vdi, qcow2, hdddirect, hddimg, iso, etc. |
381 | IMAGE_TYPES_MASKED ?= "" | 290 | IMAGE_TYPES_MASKED ?= "" |
382 | |||
383 | # The WICVARS variable is used to define list of bitbake variables used in wic code | ||
384 | # variables from this list is written to <image>.env file | ||
385 | WICVARS ?= "BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD HDDDIR IMAGE_BASENAME IMAGE_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD ISODIR MACHINE_ARCH RECIPE_SYSROOT_NATIVE ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS" | ||