public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Felix Moessbauer <felix.moessbauer@siemens.com>
To: isar-users@googlegroups.com
Cc: henning.schild@siemens.com, adriaan.schmidt@siemens.com,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: [PATCH v4 1/2] always invoke ISAR_RELEASE_CMD to invalidate downstream tasks on change
Date: Thu,  4 Nov 2021 12:05:06 +0100	[thread overview]
Message-ID: <20211104110507.2358692-2-felix.moessbauer@siemens.com> (raw)
In-Reply-To: <20211104110507.2358692-1-felix.moessbauer@siemens.com>

The command in ISAR_RELEASE_CMD is used to add version information
of the image under /etc/os-release. As we cannot predict the
output of the command, we cannot cache it.
Prior to this patch, this situation was just accepted resulting
in misleading build-ids on incremental builds.

When caching artifacts across builds (e.g. using sstate),
this also affects fresh builds.

The patch ensures that ISAR_RELEASE_CMD is always invoked
and the output is stored in the variable IMAGE_BUILD_ID.
This variable is added as a vardep in the rootfs_postprocess
task, so changes invalidate all downstream tasks.

By that, we ensure that images always contain correct release
information.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 RECIPE-API-CHANGELOG.md                       | 13 ++++++++
 meta/classes/image-postproc-extension.bbclass |  4 +--
 meta/classes/image.bbclass                    | 32 ++++++++++---------
 meta/classes/rootfs.bbclass                   |  2 +-
 4 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 7312d4d..48458a5 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -301,3 +301,16 @@ Kernel update with "apt-get" will not work since bootloader configuration will
 not be updated. It used to "kind of work" for grub and efi, that hack is gone.
 
 When using the plugins it is advised to name the partition "/boot" and to exclude boot from the follwing rootfs to not waste space.
+
+### ISAR_RELEASE_CMD is executed on every build
+
+The `ISAR_RELEASE_CMD` used to be only executed when changes to the target rootfs where made.
+This lead to outdated data in `/etc/os-release` on incremental builds.
+
+The command is now executed on every build.
+Downstream tasks are invalidated in case the output of the command changes.
+
+When using a custom command it is advised to stick to the following rules:
+
+- no visible side effects (the command is executed multiple times during a build)
+- idempotence (always emit the same output for a single build, i.e. no timestamp)
diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
index 3f00c21..6e6b257 100644
--- a/meta/classes/image-postproc-extension.bbclass
+++ b/meta/classes/image-postproc-extension.bbclass
@@ -46,11 +46,11 @@ image_postprocess_configure() {
 }
 
 ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_mark"
+ROOTFS_POSTPROCESS_VARDEPS =+ "IMAGE_BUILD_ID"
 
 image_postprocess_mark() {
-    BUILD_ID=$(get_build_id)
     update_etc_os_release \
-        --build-id "${BUILD_ID}" --variant "${DESCRIPTION}" --version "${PV}"
+        --build-id "${IMAGE_BUILD_ID}" --variant "${DESCRIPTION}" --version "${PV}"
 }
 
 ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_machine_id"
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 5a0f32e..36883a8 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -92,21 +92,23 @@ def get_rootfs_size(d):
 
     return base_size + rootfs_extra * 1024
 
-# here we call a command that should describe your whole build system,
-# this could be "git describe" or something similar.
-# set ISAR_RELEASE_CMD to customize, or override do_mark_rootfs to do something
-# completely different
-get_build_id() {
-	if [ $(echo ${BBLAYERS} | wc -w) -ne 2 ] &&
-	   [ "${ISAR_RELEASE_CMD}" = "${ISAR_RELEASE_CMD_DEFAULT}" ]; then
-		bbwarn "You are using external layers that will not be" \
-		       "considered in the build_id. Consider changing" \
-		       "ISAR_RELEASE_CMD."
-	fi
-	if ! ( ${ISAR_RELEASE_CMD} ) 2>/dev/null; then
-		bbwarn "\"${ISAR_RELEASE_CMD}\" failed, returning empty build_id."
-		echo ""
-	fi
+# the IMAGE_BUILD_ID depends on external conditions injected via
+# ISAR_RELEASE_CMD. By that, we have to compute the value
+# on each invocation
+python() {
+    bblayers = d.getVar('BBLAYERS', True)
+    release_cmd = d.getVar('ISAR_RELEASE_CMD', True)
+    if len(bblayers.split()) != 2:
+        if release_cmd == d.getVar('ISAR_RELEASE_CMD_DEFAULT', True):
+            bb.warn('You are using external layers that will not be '
+                    'considered in the build_id. Consider changing '
+                    'ISAR_RELEASE_CMD.')
+    try:
+        out,err = bb.process.run(release_cmd)
+        d.setVar('IMAGE_BUILD_ID', out.replace('\n', ''))
+    except(bb.process.ExecutionError):
+        bb.warn(f'"{release_cmd}" failed, returning empty build_id.')
+        d.setVar('IMAGE_BUILD_ID', '')
 }
 
 python set_image_size () {
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 20ccb00..e8c7fa0 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -239,7 +239,7 @@ rootfs_export_dpkg_status() {
        '${ROOTFS_DPKGSTATUS_DEPLOY_DIR}'/'${PF}'.dpkg_status
 }
 
-do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
+do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND} ${ROOTFS_POSTPROCESS_VARDEPS}"
 python do_rootfs_postprocess() {
     # Take care that its correctly mounted:
     bb.build.exec_func('rootfs_do_mounts', d)
-- 
2.30.2


  reply	other threads:[~2021-11-04 11:05 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 11:05 [PATCH v4 0/2] Improve handling of ISAR_RELEASE_CMD Felix Moessbauer
2021-11-04 11:05 ` Felix Moessbauer [this message]
2021-11-04 11:05 ` [PATCH v4 2/2] Ensure generation of /etc/os-release is idempotent Felix Moessbauer
2021-11-04 13:12 ` [PATCH v4 0/2] Improve handling of ISAR_RELEASE_CMD Henning Schild
2021-11-16 18:09 ` Anton Mikanovich
2021-11-17 10:45   ` Moessbauer, Felix
2021-11-17 13:05     ` Anton Mikanovich
2021-11-17 15:57       ` Moessbauer, Felix
2021-11-17 16:39         ` Baurzhan Ismagulov
2021-11-22 15:28         ` Anton Mikanovich
2021-11-24  9:30           ` Schmidt, Adriaan
2021-11-24 10:15             ` Moessbauer, Felix
2021-11-24 11:25               ` Jan Kiszka
2021-11-24 11:54                 ` Anton Mikanovich
2021-11-24 12:11               ` Henning Schild
2021-11-29  9:09                 ` Anton Mikanovich
2021-11-29  9:50                   ` Henning Schild
2021-11-29  9:55                     ` Anton Mikanovich
2021-11-29 13:04                   ` Anton Mikanovich
2021-11-29 13:18                     ` Henning Schild
2021-11-29 14:20                       ` Anton Mikanovich
2021-11-30 10:03                         ` Moessbauer, Felix
2021-12-01 10:39                           ` Anton Mikanovich
2021-12-02 14:55                           ` Anton Mikanovich
2021-12-03  9:51                             ` Moessbauer, Felix
2021-11-24 11:53             ` Anton Mikanovich
2021-11-24 12:35             ` Henning Schild
2021-11-24 12:52               ` Anton Mikanovich
2021-11-17 16:54       ` Henning Schild
2021-11-18  8:36         ` Moessbauer, Felix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211104110507.2358692-2-felix.moessbauer@siemens.com \
    --to=felix.moessbauer@siemens.com \
    --cc=adriaan.schmidt@siemens.com \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox