Skip to contentSkip to conversation

classes: image-buildinfo: allow deploying the buildinfo file

PATCH Superseded Daniel Wagenknecht 3 participants 6 messages Apr 20 – Sep 28 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 classes: image-buildinfo: allow deploying the buildinfo file

The buildinfo file generated by the image-buildinfo class contains useful information to identify an image. Having it in the rootfs of the image as well as deployed alongside the image artifact can be useful. Allow to deploy it alongside the image by setting 'IMAGE_BUILDINFO_DEPLOY' to '1'.

I use this in an automated testing workflow with unreliable deploy step to ensure the deployment succeeded. With
IMAGE_BUILDINFO_VARS += "IMAGE_NAME" IMAGE_BUILDINFO_DEPLOY = "1"
the generated buidinfo file is unique and the deploy step can be verified by comparing (the hash of) the file on the booted system and in IMAGE_DEPLOY_DIR.

---

I have prepared a patch for yocto-docs to add the variable to the glossary. I did not find guidance on how to do simultanious changes to OE-Core and yocto-docs so I'll send them once this has been merged.

 meta/classes/image-buildinfo.bbclass | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
meta/classes/image-buildinfo.bbclass +12 -1
index b83ce650ad..1dce50b376 100644
@@ -16,6 +16,9 @@ IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
 IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo"
 SDK_BUILDINFO_FILE ??= "/buildinfo"
 
+# Deploy the file alongside the images.
+IMAGE_BUILDINFO_DEPLOY ??= "0"
+
 # From buildhistory.bbclass
 def image_buildinfo_outputvars(vars, d):
     vars = vars.split()
@@ -70,12 +73,20 @@ python buildinfo_image () {
     bb.build.exec_func("buildinfo", d)
 }
 
+python buildinfo_deploy() {
+    d.setVar("BUILDINFODEST", "${IMGDEPLOYDIR}/")
+    d.setVar("IMAGE_BUILDINFO_FILE", "${IMAGE_NAME}.buildinfo")
+    bb.build.exec_func("buildinfo", d)
+}
+do_image[postfuncs] += "create_symlinks"
+do_image[subimages] += "buildinfo"
+
 python buildinfo_sdk () {
     d.setVar("BUILDINFODEST", "${SDK_OUTPUT}/${SDKPATH}")
     d.setVar("IMAGE_BUILDINFO_FILE", d.getVar("SDK_BUILDINFO_FILE"))
     bb.build.exec_func("buildinfo", d)
 }
 
-IMAGE_PREPROCESS_COMMAND += "buildinfo_image"
+IMAGE_PREPROCESS_COMMAND += "buildinfo_image ${@oe.utils.vartrue('IMAGE_BUILDINFO_DEPLOY', 'buildinfo_deploy', '', d)}"
 POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk"
 
Signature · 1 line
2.51.2
#1 lore raw
Quoted 14 lines · Daniel Wagenknecht via lists.openembedded.org

The buildinfo file generated by the image-buildinfo class contains useful information to identify an image. Having it in the rootfs of the image as well as deployed alongside the image artifact can be useful. Allow to deploy it alongside the image by setting 'IMAGE_BUILDINFO_DEPLOY' to '1'.

I use this in an automated testing workflow with unreliable deploy step to ensure the deployment succeeded. With
IMAGE_BUILDINFO_VARS += "IMAGE_NAME" IMAGE_BUILDINFO_DEPLOY = "1"
the generated buidinfo file is unique and the deploy step can be verified by comparing (the hash of) the file on the booted system and in IMAGE_DEPLOY_DIR.

Quoted 6 lines

---

I have prepared a patch for yocto-docs to add the variable to the glossary. I did not find guidance on how to do simultanious changes to OE-Core and yocto-docs so I'll send them once this has been merged.

Hi Daniel,

Thanks for the patch. Sending patches separately for openembedded-core and yocto-docs is correct.

Quoted 18 lines
 meta/classes/image-buildinfo.bbclass | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
meta/classes/image-buildinfo.bbclass +3 -0
index b83ce650ad..1dce50b376 100644
@@ -16,6 +16,9 @@ IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
 IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo"
 SDK_BUILDINFO_FILE ??= "/buildinfo"
 
+# Deploy the file alongside the images.
+IMAGE_BUILDINFO_DEPLOY ??= "0"
+
 # From buildhistory.bbclass
 def image_buildinfo_outputvars(vars, d):
     vars = vars.split()

meta/classes/image-buildinfo.bbclass python buildinfo_image () { · line 80

Quoted 8 lines
meta/classes/image-buildinfo.bbclass +5 -0
@@ -70,12 +73,20 @@ python buildinfo_image () {
     bb.build.exec_func("buildinfo", d)
 }
 
+python buildinfo_deploy() {
+    d.setVar("BUILDINFODEST", "${IMGDEPLOYDIR}/")
+    d.setVar("IMAGE_BUILDINFO_FILE", "${IMAGE_NAME}.buildinfo")
+    bb.build.exec_func("buildinfo", d)
+}

Rather than conditionally adding a new pre-process command which re-runs the buildinfo function, can we conditionally copy the file to ${IMGDEPLOYDIR} after it is created in buildinfo_image?

meta/classes/image-buildinfo.bbclass python buildinfo_image () { · line 82

Quoted 2 lines
meta/classes/image-buildinfo.bbclass +2 -0
+do_image[postfuncs] += "create_symlinks"
+do_image[subimages] += "buildinfo"

These two shouldn't be unconditionally added.

Best regards,

Signature · 1 line
Paul Barker
#2 lore raw

PATCH v2 1/1 classes: image-buildinfo: allow deploying the buildinfo file

The buildinfo file generated by the image-buildinfo class contains useful information to identify an image. Having it in the rootfs of the image as well as deployed alongside the image artifact can be useful. Allow to deploy it alongside the image by setting 'IMAGE_BUILDINFO_DEPLOY' to '1'.

I use this in an automated testing workflow with unreliable deploy step to ensure the deployment succeeded. With
IMAGE_BUILDINFO_VARS += "IMAGE_NAME" IMAGE_BUILDINFO_DEPLOY = "1"
the generated buidinfo file is unique and the deploy step can be verified by comparing (the hash of) the file on the booted system and in IMAGE_DEPLOY_DIR.

---

@Paul Barker:
I missed your reply, sorry! Adapted the patches according to your comments now.

v2:
* rebased
* copy generated file instead of regenerating it
* add varflags only if needed

 meta/classes/image-buildinfo.bbclass | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
meta/classes/image-buildinfo.bbclass +16 -0
index 01636dac65f..8fddcba3ee3 100644
@@ -16,6 +16,9 @@ IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION"
 IMAGE_BUILDINFO_FILE ??= "${sysconfdir}/buildinfo"
 SDK_BUILDINFO_FILE ??= "/buildinfo"
 
+# Deploy the file alongside the images.
+IMAGE_BUILDINFO_DEPLOY ??= "0"
+
 # From buildhistory.bbclass
 def image_buildinfo_outputvars(vars, d):
     vars = vars.split()
@@ -70,6 +73,12 @@ python buildinfo_image () {
     bb.build.exec_func("buildinfo", d)
 }
 
+python buildinfo_deploy() {
+    src = d.expand("${IMAGE_ROOTFS}/${IMAGE_BUILDINFO_FILE}")
+    dst = d.expand("${IMGDEPLOYDIR}/${IMAGE_NAME}.buildinfo")
+    oe.path.copyhardlink(src, dst)
+}
+
 python buildinfo_sdk () {
     d.setVar("BUILDINFODEST", "${SDK_OUTPUT}/${SDKPATH}")
     d.setVar("IMAGE_BUILDINFO_FILE", d.getVar("SDK_BUILDINFO_FILE"))
@@ -79,3 +88,10 @@ python buildinfo_sdk () {
 IMAGE_PREPROCESS_COMMAND += "buildinfo_image"
 POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk"
 
+python () {
+   if oe.utils.vartrue('IMAGE_BUILDINFO_DEPLOY', True, False, d):
+     d.appendVar("IMAGE_PREPROCESS_COMMAND", " buildinfo_deploy")
+     d.appendVarFlag("do_image", "postfuncs", " create_symlinks")
+     d.appendVarFlag("do_image", "subimages", " buildinfo")
+}
+
Signature · 1 line
2.54.0
#3 lore raw

meta/classes/image-buildinfo.bbclass IMAGE_BUILDINFO_VARS ?= "DISTRO DISTRO_VERSION" · line 20

Quoted 2 lines · Daniel Wagenknecht via lists.openembedded.org
meta/classes/image-buildinfo.bbclass +2 -0
+# Deploy the file alongside the images.
+IMAGE_BUILDINFO_DEPLOY ??= "0"

Do we need yet another variable and yet more conditional code paths that are never tested? Why not just always deploy it?

Alex

#4 lore raw

Hello,

Quoted 4 lines · Alexander Kanavin
Quoted 1 line

+IMAGE_BUILDINFO_DEPLOY ??= "0"

Do we need yet another variable and yet more conditional code paths that are never tested? Why not just always deploy it?

I'd be fine with adding it unconditionally. Waiting for further opinions on this before changing that.

Daniel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

PATCH v3 1/1 classes: image-buildinfo: deploy the buildinfo file

The buildinfo file generated by the image-buildinfo class contains useful information to identify an image. Having it in the rootfs of the image as well as deployed alongside the image artifact can be useful.

I use this in an automated testing workflow with unreliable deploy step to ensure the deployment succeeded. With
IMAGE_BUILDINFO_VARS += "IMAGE_NAME" IMAGE_BUILDINFO_DEPLOY = "1"
the generated buidinfo file is unique and the deploy step can be verified by comparing (the hash of) the file on the booted system and in IMAGE_DEPLOY_DIR.

---
v2:
* rebased
* copy generated file instead of regenerating it
* add varflags only if needed

v3:
* rebased
* deploy unconditionally as suggested by [email protected]

 meta/classes/image-buildinfo.bbclass | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
meta/classes/image-buildinfo.bbclass +10 -1
index 01636dac6..d44e15443 100644
@@ -70,12 +70,21 @@ python buildinfo_image () {
     bb.build.exec_func("buildinfo", d)
 }
 
+python buildinfo_deploy() {
+    src = d.expand("${IMAGE_ROOTFS}/${IMAGE_BUILDINFO_FILE}")
+    dst = d.expand("${IMGDEPLOYDIR}/${IMAGE_NAME}.buildinfo")
+    oe.path.copyhardlink(src, dst)
+}
+do_image[postfuncs] += "create_symlinks"
+do_image[subimages] += "buildinfo"
+
+
 python buildinfo_sdk () {
     d.setVar("BUILDINFODEST", "${SDK_OUTPUT}/${SDKPATH}")
     d.setVar("IMAGE_BUILDINFO_FILE", d.getVar("SDK_BUILDINFO_FILE"))
     bb.build.exec_func("buildinfo", d)
 }
 
-IMAGE_PREPROCESS_COMMAND += "buildinfo_image"
+IMAGE_PREPROCESS_COMMAND += "buildinfo_image buildinfo_deploy"
 POPULATE_SDK_PRE_TARGET_COMMAND += "buildinfo_sdk"
 
Signature · 1 line
2.54.0