Re: [PATCH 2/2] git-describe.bbclass: add new class for "git describe --tags --allways --dirty"


Martin Jansa
 

It would be nice to somehow consolidate this new bbclass with

and at least move the various git "wrapper" functions to lib/oe for better reuse.

On Thu, Sep 22, 2022 at 2:24 PM Mikko Rapeli <mikko.rapeli@...> wrote:
Output from git_describe() function can then be used in various places
and from various git trees to create a user friend(lier) name to builds.
Examples where this could be used is BUILD_ID, SDK_VERSION and
IMAGE_VERSION_SUFFIX.

Signed-off-by: Mikko Rapeli <mikko.rapeli@...>
---
 meta/classes/git-describe.bbclass | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 meta/classes/git-describe.bbclass

diff --git a/meta/classes/git-describe.bbclass b/meta/classes/git-describe.bbclass
new file mode 100644
index 0000000000..3a2b06b3fd
--- /dev/null
+++ b/meta/classes/git-describe.bbclass
@@ -0,0 +1,24 @@
+# Defines a simple function which calls 'git describe --tags --always --dirty'
+# on specified directory and returns the string.
+#
+# Can be used for example to easily generate a BUILD_ID in local.conf if
+# TOPDIR build directory is under the main git tree for the project:
+# INHERIT += "git-describe"
+# BUILD_ID = "${@git_describe("${TOPDIR}/../meta-mylayer", d)}"
+# # BUILD_ID to /etc/os-release
+# OS_RELEASE_FIELDS:append:pn-os-release = " BUILD_ID"
+# # Add os-release to all images
+# IMAGE_INSTALL:append = " os-release"
+# # BUILD_ID to image file name
+# IMAGE_VERSION_SUFFIX = "-${BUILD_ID}"
+# # BUILD_ID to SDK file names and paths
+# SDK_VERSION = "${BUILD_ID}"
+
+def git_describe(p, d):
+    import bb.process
+    try:
+        describe, _ = bb.process.run('git describe --tags --always --dirty', cwd=p)
+    except bb.process.ExecutionError:
+        describe = ''
+    return describe.strip()
+
--
2.17.1




Join openembedded-core@lists.openembedded.org to automatically receive all group messages.