* [PATCH 1/3] classes: add 'customization' package support
2025-03-11 21:09 [PATCH 0/3] Add 'customization' package support chris.larson via isar-users
@ 2025-03-11 21:09 ` chris.larson via isar-users
2025-03-11 21:09 ` [PATCH 2/3] hostname-customization: add initial customization package chris.larson via isar-users
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: chris.larson via isar-users @ 2025-03-11 21:09 UTC (permalink / raw)
To: isar-users; +Cc: Cedric Hombourger, Christopher Larson
From: Christopher Larson <chris.larson@siemens.com>
A number of downstream layers have customization dpkg-raw recipes making use of
template variables to support build-time settings: add the infrastructure to
Isar to help uniformization of such recipes. Settings are often specific to a
DISTRO, MACHINE or IMAGE: provide a mechanism to decorate (prefix or suffix)
packages being constructed and pulled into the image. This helps use of
customization packages in multiconfig builds but also with the deployment of
binary package feeds for projects supporting multiple variants.
To create a customization package, a recipe must inherit the
`dpkg-customization` bbclass. By default, images will inherit the
`image-customizations` class, which will install the package for any
customizations listed in `CUSTOMIZATIONS`.
To add variables to the customization package names, beyond the default DISTRO
and MACHINE, add them to `CUSTOMIZATION_VARS` as variable references
(`${DISTRO}`, `${MACHINE}`). By default, these variables are appended to the
package name, but if they should be prefixed, add them to
`CUSTOMIZATION_VARS_PREFIXED`. By default, the `DISTRO` and `MACHINE` variables
are used, and the `DISTRO` is prefixed, while the `MACHINE` is suffixed.
To enable support for per-image changes, and per-image customization packages,
add the image name to `CUSTOMIZATION_FOR_IMAGES`. In the customization package
recipe, the `IMAGE` variable will be set to the image name, and the package name
will be decorated with the image name. The `IMAGE` will also be added to the
`OVERRIDES`, allowing for variable definitions like this in the customization
recipe:
HOSTNAME:isar-image-ci = "isar-ci"
When `CUSTOMIZATION_FOR_IMAGES` is defined, `${IMAGE}` will be implicitly added
to `CUSTOMIZATION_VARS`, and the package will be decorated with the image name.
Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
meta/classes/customization-base.bbclass | 21 +++++++++++++
meta/classes/dpkg-customization.bbclass | 37 +++++++++++++++++++++++
meta/classes/image-customizations.bbclass | 30 ++++++++++++++++++
meta/classes/image.bbclass | 1 +
4 files changed, 89 insertions(+)
create mode 100644 meta/classes/customization-base.bbclass
create mode 100644 meta/classes/dpkg-customization.bbclass
create mode 100644 meta/classes/image-customizations.bbclass
diff --git a/meta/classes/customization-base.bbclass b/meta/classes/customization-base.bbclass
new file mode 100644
index 00000000..82cad67e
--- /dev/null
+++ b/meta/classes/customization-base.bbclass
@@ -0,0 +1,21 @@
+# Common class for customization packages, used by dpkg-customization.bbclass
+# and image-customizations.bbclass.
+
+LIST_VARIABLES += "CUSTOMIZATIONS CUSTOMIZATION_VARS CUSTOMIZATION_VARS_PREFIXED"
+
+CUSTOMIZATIONS ?= ""
+CUSTOMIZATIONS[doc] = "List of customization packages to be installed in images."
+
+CUSTOMIZATION_VARS ?= "${DISTRO} ${MACHINE}"
+CUSTOMIZATION_VARS[doc] = "List of variables that should be added to customization package names."
+CUSTOMIZATION_VARS_IMAGE ?= "${IMAGE}"
+CUSTOMIZATION_VARS:append = " ${@d.getVar('CUSTOMIZATION_VARS_IMAGE') if d.getVar('CUSTOMIZATION_FOR_IMAGES').strip() else ''}"
+
+CUSTOMIZATION_VARS_PREFIXED ?= "${DISTRO}"
+CUSTOMIZATION_VARS_PREFIXED[doc] = "List of variables from CUSTOMIZATION_VARS that should be prefixed rather than suffixed to customization package names."
+
+CUSTOMIZATION_FOR_IMAGES ?= ""
+CUSTOMIZATION_FOR_IMAGES[doc] = "List of images that should install the customizations in CUSTOMIZATIONS"
+
+CUSTOMIZATION_PREFIX ?= "${@'-'.join(var for var in d.getVar('CUSTOMIZATION_VARS').split() if var in d.getVar('CUSTOMIZATION_VARS_PREFIXED'))}"
+CUSTOMIZATION_SUFFIX ?= "${@'-'.join(var for var in d.getVar('CUSTOMIZATION_VARS').split() if var not in d.getVar('CUSTOMIZATION_VARS_PREFIXED'))}"
diff --git a/meta/classes/dpkg-customization.bbclass b/meta/classes/dpkg-customization.bbclass
new file mode 100644
index 00000000..7b8c586b
--- /dev/null
+++ b/meta/classes/dpkg-customization.bbclass
@@ -0,0 +1,37 @@
+inherit dpkg-raw customization-base
+
+PRE_CUSTOMIZATION_PN := "${PN}"
+FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
+PN =. "${@d.getVar('CUSTOMIZATION_PREFIX') + '-' if d.getVar('CUSTOMIZATION_PREFIX') else ''}"
+PN .= "${@'-' + d.getVar('CUSTOMIZATION_SUFFIX') if d.getVar('CUSTOMIZATION_SUFFIX') else ''}"
+
+BBCLASSEXTEND = "${@' '.join(f'dpkg-customization:{image}' for image in d.getVar('CUSTOMIZATION_FOR_IMAGES').split())}"
+
+python customization_virtclass_handler() {
+ orig_pn = d.getVar('PRE_CUSTOMIZATION_PN')
+
+ d = e.data
+ extend = d.getVar('BBEXTENDCURR') or ''
+ variant = d.getVar('BBEXTENDVARIANT') or ''
+ if extend != 'dpkg-customization' or variant == '':
+ d.appendVar('PROVIDES', f' {orig_pn}')
+ d.setVar('IMAGE', '')
+ return
+
+ vars = (d.getVar('CUSTOMIZATION_VARS', expand=False) or '').split()
+ if '${IMAGE}' not in vars:
+ return
+
+ images = (d.getVar('CUSTOMIZATION_FOR_IMAGES') or '').split()
+ if variant not in images:
+ return
+
+ d.setVar('IMAGE', variant)
+ if not d.getVar('BPN').endswith(f'-{variant}'):
+ d.appendVar('BPN', f'-{variant}')
+ d.appendVar('PROVIDES', f' {orig_pn}-{variant}')
+ d.appendVar('OVERRIDES', f':{variant}')
+}
+addhandler customization_virtclass_handler
+customization_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
+
diff --git a/meta/classes/image-customizations.bbclass b/meta/classes/image-customizations.bbclass
new file mode 100644
index 00000000..996f3fb8
--- /dev/null
+++ b/meta/classes/image-customizations.bbclass
@@ -0,0 +1,30 @@
+inherit customization-base
+
+def customization_packages(d):
+ customizations = d.getVar('CUSTOMIZATIONS').split()
+ if not customizations:
+ return ''
+
+ # Use image-specific customization if enabled for this image
+ images = (d.getVar('CUSTOMIZATION_FOR_IMAGES') or '').split()
+ image = d.getVar('BPN')
+ if not images or image not in images:
+ d.setVar('IMAGE', '')
+ else:
+ d.setVar('IMAGE', image)
+
+ prefix = d.getVar('CUSTOMIZATION_PREFIX')
+ if prefix:
+ prefix += '-'
+
+ suffix = d.getVar('CUSTOMIZATION_SUFFIX')
+ if suffix:
+ suffix = '-customization-' + suffix
+ else:
+ suffix = '-customization'
+
+ customizations = [ prefix + package + suffix for package in customizations ]
+ return ' '.join(customizations)
+
+CUSTOMIZATION_PACKAGES = "${@ customization_packages(d) }"
+IMAGE_INSTALL:append = " ${CUSTOMIZATION_PACKAGES}"
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 56eca202..d36bb816 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -80,6 +80,7 @@ inherit image-tools-extension
inherit image-postproc-extension
inherit image-locales-extension
inherit image-account-extension
+inherit image-customizations
# Extra space for rootfs in MB
ROOTFS_EXTRA ?= "64"
--
2.47.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250311210939.4090-2-chris.larson%40siemens.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] hostname-customization: add initial customization package
2025-03-11 21:09 [PATCH 0/3] Add 'customization' package support chris.larson via isar-users
2025-03-11 21:09 ` [PATCH 1/3] classes: add " chris.larson via isar-users
@ 2025-03-11 21:09 ` chris.larson via isar-users
2025-03-11 21:09 ` [PATCH 3/3] testsuite: add 'customizations' test chris.larson via isar-users
2025-03-25 16:55 ` [PATCH 0/3] Add 'customization' package support Uladzimir Bely
3 siblings, 0 replies; 5+ messages in thread
From: chris.larson via isar-users @ 2025-03-11 21:09 UTC (permalink / raw)
To: isar-users; +Cc: Cedric Hombourger, Christopher Larson
From: Christopher Larson <chris.larson@siemens.com>
This package provides a simple customization package that allows the hostname to
be set in the image. As this value is set from the `HOSTNAME` metadata variable,
it must be set in the metadata.
Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
.../customizations/hostname-customization.bb | 11 +++++++++++
.../hostname-customization/postinst.tmpl | 5 +++++
2 files changed, 16 insertions(+)
create mode 100644 meta/recipes-support/customizations/hostname-customization.bb
create mode 100644 meta/recipes-support/customizations/hostname-customization/postinst.tmpl
diff --git a/meta/recipes-support/customizations/hostname-customization.bb b/meta/recipes-support/customizations/hostname-customization.bb
new file mode 100644
index 00000000..ba37c973
--- /dev/null
+++ b/meta/recipes-support/customizations/hostname-customization.bb
@@ -0,0 +1,11 @@
+inherit dpkg-customization
+
+DESCRIPTION = "Amend the system hostname"
+LICENSE = "gpl-2.0"
+LIC_FILES_CHKSUM = "file://${LAYERDIR_core}/licenses/COPYING.GPLv2;md5=751419260aa954499f7abaabaa882bbe"
+MAINTAINER = "isar-users <isar-users@googlegroups.com>"
+DEBIAN_DEPENDS = "netbase"
+PV = "0.3"
+SRC_URI = "file://postinst.tmpl"
+TEMPLATE_FILES = "postinst.tmpl"
+TEMPLATE_VARS = "HOSTNAME"
diff --git a/meta/recipes-support/customizations/hostname-customization/postinst.tmpl b/meta/recipes-support/customizations/hostname-customization/postinst.tmpl
new file mode 100644
index 00000000..db9475df
--- /dev/null
+++ b/meta/recipes-support/customizations/hostname-customization/postinst.tmpl
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+echo "${HOSTNAME}" > /etc/hostname
+echo "127.0.1.1 ${HOSTNAME}" >> /etc/hosts
+sed -i -e 's/^127.0.0.1[[:space:]]\+localhost$/& localhost.localdomain/' /etc/hosts
--
2.47.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250311210939.4090-3-chris.larson%40siemens.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] testsuite: add 'customizations' test
2025-03-11 21:09 [PATCH 0/3] Add 'customization' package support chris.larson via isar-users
2025-03-11 21:09 ` [PATCH 1/3] classes: add " chris.larson via isar-users
2025-03-11 21:09 ` [PATCH 2/3] hostname-customization: add initial customization package chris.larson via isar-users
@ 2025-03-11 21:09 ` chris.larson via isar-users
2025-03-25 16:55 ` [PATCH 0/3] Add 'customization' package support Uladzimir Bely
3 siblings, 0 replies; 5+ messages in thread
From: chris.larson via isar-users @ 2025-03-11 21:09 UTC (permalink / raw)
To: isar-users; +Cc: Cedric Hombourger, Christopher Larson
From: Christopher Larson <chris.larson@siemens.com>
This test builds isar-image-ci with the hostname customization enabled, and
verifies that the customization applied correctly.
Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
testsuite/cibuilder.py | 9 +++++++++
testsuite/citest.py | 21 +++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index b5b6a093..1746171e 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -109,6 +109,7 @@ def configure(
source_date_epoch=None,
use_apt_snapshot=False,
image_install=None,
+ customizations=None,
**kwargs,
):
# write configuration file and set bitbake_args
@@ -155,6 +156,7 @@ def configure(
f" sstate_dir = {sstate_dir}\n"
f" ccache_dir = {ccache_dir}\n"
f" image_install = {image_install}\n"
+ f" customizations = {customizations}\n"
f"==================================================="
)
@@ -216,6 +218,13 @@ def configure(
f.write('IMAGE_INSTALL = "%s"\n' % image_install)
if fail_on_cleanup == '1':
f.write('ISAR_FAIL_ON_CLEANUP = "1"\n')
+ if customizations is not None:
+ if not isinstance(customizations, str):
+ customizations = ' '.join(customizations)
+ f.write('CUSTOMIZATIONS = "%s"\n' % customizations)
+ f.write('CUSTOMIZATION_VARS:append = " ${IMAGE}"\n')
+ f.write('CUSTOMIZATION_FOR_IMAGES:append = " isar-image-ci"\n')
+ f.write('HOSTNAME:isar-image-ci = "isar-ci"\n')
# include ci_build.conf in local.conf
with open(self.build_dir + '/conf/local.conf', 'r+') as f:
diff --git a/testsuite/citest.py b/testsuite/citest.py
index 47f49263..66b39334 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -345,6 +345,27 @@ def test_container_sdk(self):
)
+class CustomizationsTest(CIBaseTest):
+ """
+ Test image customizations using the hostname-customizations package.
+
+ :avocado: tags=customizations,single,full
+ """
+
+ def test_single_customization(self):
+ self.init()
+ machine = self.params.get("machine", default="qemuamd64")
+ distro = self.params.get("distro", default="bullseye")
+
+ self.perform_build_test("mc:%s-%s:%s" % (machine, distro, "isar-image-ci"), customizations="hostname", image_install="")
+ self.vm_start(
+ machine.removeprefix('qemu'),
+ distro,
+ image="isar-image-ci",
+ cmd="hostname | grep isar-ci"
+ )
+
+
class SignatureTest(CIBaseTest):
"""
--
2.47.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250311210939.4090-4-chris.larson%40siemens.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Add 'customization' package support
2025-03-11 21:09 [PATCH 0/3] Add 'customization' package support chris.larson via isar-users
` (2 preceding siblings ...)
2025-03-11 21:09 ` [PATCH 3/3] testsuite: add 'customizations' test chris.larson via isar-users
@ 2025-03-25 16:55 ` Uladzimir Bely
3 siblings, 0 replies; 5+ messages in thread
From: Uladzimir Bely @ 2025-03-25 16:55 UTC (permalink / raw)
To: chris.larson, isar-users; +Cc: Cedric Hombourger
On Tue, 2025-03-11 at 14:09 -0700, chris.larson via isar-users wrote:
> From: Christopher Larson <chris.larson@siemens.com>
>
> A number of downstream layers have customization dpkg-raw recipes
> making use of
> template variables to support build-time settings: add the
> infrastructure to
> Isar to help uniformization of such recipes. Settings are often
> specific to a
> DISTRO, MACHINE or IMAGE: provide a mechanism to decorate (prefix or
> suffix)
> packages being constructed and pulled into the image. This helps use
> of
> customization packages in multiconfig builds but also with the
> deployment of
> binary package feeds for projects supporting multiple variants.
>
> To create a customization package, a recipe must inherit the
> `dpkg-customization` bbclass. By default, images will inherit the
> `image-customizations` class, which will install the package for any
> customizations listed in `CUSTOMIZATIONS`.
>
> To add variables to the customization package names, beyond the
> default DISTRO
> and MACHINE, add them to `CUSTOMIZATION_VARS` as variable references
> (`${DISTRO}`, `${MACHINE}`). By default, these variables are appended
> to the
> package name, but if they should be prefixed, add them to
> `CUSTOMIZATION_VARS_PREFIXED`. By default, the `DISTRO` and `MACHINE`
> variables
> are used, and the `DISTRO` is prefixed, while the `MACHINE` is
> suffixed.
>
> To enable support for per-image changes, and per-image customization
> packages,
> add the image name to `CUSTOMIZATION_FOR_IMAGES`. In the
> customization package
> recipe, the `IMAGE` variable will be set to the image name, and the
> package name
> will be decorated with the image name. The `IMAGE` will also be added
> to the
> `OVERRIDES`, allowing for variable definitions like this in the
> customization
> recipe:
>
> HOSTNAME:isar-image-ci = "isar-ci"
>
> When `CUSTOMIZATION_FOR_IMAGES` is defined, `${IMAGE}` will be
> implicitly added
> to `CUSTOMIZATION_VARS`, and the package will be decorated with the
> image name.
>
> An example `hostname` customization recipe/package is provided, as is
> an
> initial unit test to verify the functionality of this customization.
>
> Christopher Larson (3):
> classes: add 'customization' package support
> hostname-customization: add initial customization package
> testsuite: add 'customizations' test
>
> meta/classes/customization-base.bbclass | 21 +++++++++++
> meta/classes/dpkg-customization.bbclass | 37
> +++++++++++++++++++
> meta/classes/image-customizations.bbclass | 30 +++++++++++++++
> meta/classes/image.bbclass | 1 +
> .../customizations/hostname-customization.bb | 11 ++++++
> .../hostname-customization/postinst.tmpl | 5 +++
> testsuite/cibuilder.py | 9 +++++
> testsuite/citest.py | 21 +++++++++++
> 8 files changed, 135 insertions(+)
> create mode 100644 meta/classes/customization-base.bbclass
> create mode 100644 meta/classes/dpkg-customization.bbclass
> create mode 100644 meta/classes/image-customizations.bbclass
> create mode 100644 meta/recipes-support/customizations/hostname-
> customization.bb
> create mode 100644 meta/recipes-support/customizations/hostname-
> customization/postinst.tmpl
>
> --
> 2.47.2
Applied to next, thanks.
--
Best regards,
Uladzimir.
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/c803fd2222c402dc168d6ca016f14692a1b8494f.camel%40ilbers.de.
^ permalink raw reply [flat|nested] 5+ messages in thread