Skip to content

Commit

Permalink
genimage.bbclass: support compressing the generated image
Browse files Browse the repository at this point in the history
Allow the recipe to set GENIMAGE_COMPRESSION to "gzip" or "xz". Other
types are trivial to add support for if desired. Even if the class
doesn't yet support a given scheme, the recipe itself can just define
the proper GENIMAGE_COMPRESS_DEPENDS[foo] and
GENIMAGE_COMPRESS_CMD[foo].

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
  • Loading branch information
Rasmus Villemoes authored and Emantor committed May 8, 2024
1 parent e733426 commit 20ed637
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions classes-recipe/genimage.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
# GENIMAGE_ROOTFS_IMAGE_FSTYPE - input roofs FSTYPE to use (default: 'tar.bz2')
# GENIMAGE_ROOTFS_IMAGE_SUFFIX - IMAGE_NAME_SUFFIX to use (default: '${IMAGE_NAME_SUFFIX}')
# GENIMAGE_VARIABLES[VAR] - replace @VAR@ in config with variable flag value
# GENIMAGE_COMPRESSION - compress the generated image. Allowed values
# are 'none' for no compression (the default), 'gzip' and 'xz'.

inherit image-artifact-names deploy

Expand Down Expand Up @@ -112,6 +114,18 @@ do_genimage[depends] += "${@'${GENIMAGE_ROOTFS_IMAGE}:do_image_complete' if '${G
GENIMAGE_CREATE_BMAP ?= "0"
do_genimage[depends] += "${@'bmaptool-native:do_populate_sysroot' if d.getVar('GENIMAGE_CREATE_BMAP') == '1' else ''}"

GENIMAGE_COMPRESSION ??= "none"

GENIMAGE_COMPRESS_DEPENDS[none] = ""
GENIMAGE_COMPRESS_DEPENDS[gzip] = "pigz-native:do_populate_sysroot"
GENIMAGE_COMPRESS_DEPENDS[xz] = "xz-native:do_populate_sysroot"
do_genimage[depends] += "${@d.getVarFlag('GENIMAGE_COMPRESS_DEPENDS', '${GENIMAGE_COMPRESSION}')}"

GENIMAGE_COMPRESS_CMD[none] = ":"
GENIMAGE_COMPRESS_CMD[gzip] = "gzip -f -9 -n"
GENIMAGE_COMPRESS_CMD[xz] = "xz -f"
GENIMAGE_COMPRESS_CMD = "${@d.getVarFlag('GENIMAGE_COMPRESS_CMD', '${GENIMAGE_COMPRESSION}')}"

GENIMAGE_TMPDIR = "${WORKDIR}/genimage-tmp"
GENIMAGE_ROOTDIR = "${WORKDIR}/root"
GENIMAGE_OPTS ??= ""
Expand Down Expand Up @@ -165,6 +179,8 @@ fakeroot do_genimage () {
bmaptool create -o ${B}/${GENIMAGE_IMAGE_FULLNAME}.bmap ${B}/${GENIMAGE_IMAGE_FULLNAME}
fi

${GENIMAGE_COMPRESS_CMD} ${B}/${GENIMAGE_IMAGE_FULLNAME}

rm ${B}/.config
}
do_genimage[depends] += "virtual/fakeroot-native:do_populate_sysroot"
Expand Down

0 comments on commit 20ed637

Please sign in to comment.