From 588f14370372a66329b54606071175519ce88f1e Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 7 Mar 2016 15:51:14 +0100 Subject: image.bbclass: support chaining compression (aka conversion) commands It makes sense to use the compression mechanism also for conversion, for example of a whole-disk image into .vdi (VirtualBox). That part already works, like this: COMPRESSIONTYPES_append = " vdi" COMPRESS_CMD_vdi = "qemu-img convert -O vdi ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.vdi" IMAGE_DEPENDS_vdi = "qemu-native" But then it also makes sense to allow compressing the resulting image, which only works after enhancing the image.bbclass. For example, suppose a custom image command produces "dsk" images. Then it becomes possible to set IMAGE_FSTYPES = " dsk.xz dsk.vdi.xz" and do_image_dsk will automatically produce the intermediate images, convert to dsk.xz resp. dsk.vdi -> dsk.vdi.xz and delete all intermediate images. Symlinks are also set correctly. Signed-off-by: Patrick Ohly Signed-off-by: Richard Purdie --- meta/classes/image.bbclass | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass index 8b6c30bce8..c61d8140c5 100644 --- a/meta/classes/image.bbclass +++ b/meta/classes/image.bbclass @@ -303,6 +303,10 @@ python () { basetype = type[:-len("." + ctype)] break + if basetype != type: + # New base type itself might be generated by a conversion command. + basetype = _image_base_type(basetype) + return basetype basetypes = {} @@ -379,18 +383,35 @@ python () { bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t) cmds.append(localdata.expand("\tcd ${DEPLOY_DIR_IMAGE}")) - for bt in basetypes[t]: + rm_tmp_images = set() + def gen_conversion_cmds(bt): for ctype in ctypes: if bt.endswith("." + ctype): + type = bt[0:-len(ctype) - 1] + # Create input image first. + gen_conversion_cmds(type) + localdata.setVar('type', type) cmds.append("\t" + localdata.getVar("COMPRESS_CMD_" + ctype, True)) vardeps.add('COMPRESS_CMD_' + ctype) - subimages.append(realt + "." + ctype) + subimages.append(type + "." + ctype) + if type not in alltypes: + rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) + + for bt in basetypes[t]: + gen_conversion_cmds(bt) + localdata.setVar('type', realt) if realt not in alltypes: - cmds.append(localdata.expand("\trm ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) + rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) else: subimages.append(realt) + # Clean up after applying all conversion commands. Some of them might + # use the same input, therefore we cannot delete sooner without applying + # some complex dependency analysis. + for image in rm_tmp_images: + cmds.append("\trm " + image) + after = 'do_image' for dep in typedeps[t]: after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_") -- cgit 1.2.3-korg