]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bblayers/makesetup.py: Move git utility functions to oe.buildcfg module
authorJermain Horsman <jermain.horsman@nedap.com>
Mon, 25 Mar 2024 12:50:38 +0000 (13:50 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 30 Mar 2024 22:23:54 +0000 (22:23 +0000)
This allows other classes to make use of these as well.

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>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/bblayers/makesetup.py
meta/lib/oe/buildcfg.py

index 4f27c565eeb41c91a6182b6fa9f255097963a2e3..99d59737602c304888316537d60edf65aa2949ad 100644 (file)
@@ -9,7 +9,6 @@ import os
 import sys
 
 import bb.utils
-import bb.process
 
 from bblayers.common import LayerPlugin
 
@@ -24,25 +23,12 @@ def plugin_init(plugins):
 
 class MakeSetupPlugin(LayerPlugin):
 
-    def _get_repo_path(self, layer_path):
-        repo_path, _ = bb.process.run('git rev-parse --show-toplevel', cwd=layer_path)
-        return repo_path.strip()
-
-    def _get_remotes(self, repo_path):
+    def _get_remotes_with_url(self, repo_path):
         remotes = {}
-        remotes_list,_ = bb.process.run('git remote', cwd=repo_path)
-        for r in remotes_list.split():
-            uri,_ = bb.process.run('git remote get-url {r}'.format(r=r), cwd=repo_path)
-            remotes[r] = {'uri':uri.strip()}
+        for r in oe.buildcfg.get_metadata_git_remotes(repo_path):
+            remotes[r] = {'uri':oe.buildcfg.get_metadata_git_remote_url(repo_path, r)}
         return remotes
 
-    def _get_describe(self, repo_path):
-        try:
-            describe,_ = bb.process.run('git describe --tags', cwd=repo_path)
-        except bb.process.ExecutionError:
-            return ""
-        return describe.strip()
-
     def _is_submodule(self, repo_path):
         # This is slightly brittle: git does not offer a way to tell whether
         # a given repo dir is a submodule checkout, so we need to rely on .git
@@ -56,10 +42,7 @@ class MakeSetupPlugin(LayerPlugin):
         available here. """
         repos = {}
         layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data)
-        try:
-            destdir_repo = self._get_repo_path(destdir)
-        except bb.process.ExecutionError:
-            destdir_repo = None
+        destdir_repo = oe.buildcfg.get_metadata_git_toplevel(destdir)
 
         for (l_path, l_name, l_branch, l_rev, l_ismodified) in layers:
             if l_name == 'workspace':
@@ -67,12 +50,16 @@ class MakeSetupPlugin(LayerPlugin):
             if l_ismodified:
                 logger.error("Layer {name} in {path} has uncommitted modifications or is not in a git repository.".format(name=l_name,path=l_path))
                 return
-            repo_path = self._get_repo_path(l_path)
+            repo_path = oe.buildcfg.get_metadata_git_toplevel(l_path)
 
             if self._is_submodule(repo_path):
                 continue
             if repo_path not in repos.keys():
-                repos[repo_path] = {'path':os.path.basename(repo_path),'git-remote':{'rev':l_rev, 'branch':l_branch, 'remotes':self._get_remotes(repo_path), 'describe':self._get_describe(repo_path)}}
+                repos[repo_path] = {'path':os.path.basename(repo_path),'git-remote':{
+                        'rev':l_rev,
+                        'branch':l_branch,
+                        'remotes':self._get_remotes_with_url(repo_path),
+                        'describe':oe.buildcfg.get_metadata_git_describe(repo_path)}}
                 if repo_path == destdir_repo:
                     repos[repo_path]['contains_this_file'] = True
                 if not repos[repo_path]['git-remote']['remotes'] and not repos[repo_path]['contains_this_file']:
index b3fe510309c21fa3096d15793a3e171bd2b035a3..27b059b8343142c019f1360eab8fb2153f1463d3 100644 (file)
@@ -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 ""
+    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:
+        return ""
+    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;