diff mbox series

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

Message ID 20220922122402.32710-2-mikko.rapeli@linaro.org
State New
Headers show
Series [1/2] poky.conf: allow changes to DISTRO_VERSION, SDK_VERSION and MAINTAINER | expand

Commit Message

Mikko Rapeli Sept. 22, 2022, 12:24 p.m. UTC
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@linaro.org>
---
 meta/classes/git-describe.bbclass | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 meta/classes/git-describe.bbclass

Comments

Ross Burton Sept. 22, 2022, 12:43 p.m. UTC | #1
On 22 Sep 2022, at 13:24, Mikko Rapeli via lists.openembedded.org <mikko.rapeli=linaro.org@lists.openembedded.org> 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.

I do think this should be part of lib/oe/buildcfg.py.

Ross
Martin Jansa Sept. 22, 2022, 1:16 p.m. UTC | #2
It would be nice to somehow consolidate this new bbclass with
https://git.openembedded.org/meta-openembedded/tree/meta-oe/classes/gitpkgv.bbclass
https://git.openembedded.org/meta-openembedded/tree/meta-oe/classes/gitver.bbclass

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@linaro.org>
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@linaro.org>
> ---
>  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
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#170970):
> https://lists.openembedded.org/g/openembedded-core/message/170970
> Mute This Topic: https://lists.openembedded.org/mt/93847068/3617156
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> Martin.Jansa@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
diff mbox series

Patch

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()
+