diff mbox series

[RFC,2/7] lib/oe/buildcfg.py: Add additional git functions

Message ID 20231107152641.1043-4-jermain.horsman@nedap.com
State New
Headers show
Series bitbake-layers: Add update-layers-setup | expand

Commit Message

jhatnedap@gmail.com Nov. 7, 2023, 3:26 p.m. UTC
From: Jermain Horsman <jermain.horsman@nedap.com>

Includes a git describe and git toplevel function and functions
to get info for git remotes.

Signed-off-by: Jermain Horsman <jermain.horsman@nedap.com>
---
 meta/lib/oe/buildcfg.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py
index b3fe510309..f9cb0cc74c 100644
--- a/meta/lib/oe/buildcfg.py
+++ b/meta/lib/oe/buildcfg.py
@@ -28,6 +28,35 @@  def get_metadata_git_revision(path):
         rev = '<unknown>'
     return rev.strip()
 
+def get_metadata_git_toplevel(path):
+    try:
+        toplevel, _ = bb.process.run('git rev-parse --show-toplevel', cwd=path)
+    except bb.process.ExecutionError:
+        return None
+    return toplevel.strip()
+
+def get_metadata_git_remotes(path):
+    try:
+        remotes_list, _ = bb.process.run('git remote', cwd=path)
+        remotes = remotes_list.split()
+    except bb.process.ExecutionError:
+        remotes = []
+    return remotes
+
+def get_metadata_git_remote_url(path, remote):
+    try:
+        uri, _ = bb.process.run('git remote get-url {remote}'.format(remote=remote), cwd=path)
+    except bb.process.ExecutionError:
+        uri = ''
+    return uri.strip()
+
+def get_metadata_git_describe(path):
+    try:
+        describe, _ = bb.process.run('git describe --tags', cwd=path)
+    except bb.process.ExecutionError:
+        return ""
+    return describe.strip()
+
 def is_layer_modified(path):
     try:
         subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e;