summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJermain Horsman <jermain.horsman@nedap.com>2024-03-25 13:50:38 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-03-30 22:25:43 +0000
commit9b839a835cc0746c59f9d74ef0e66c79280f8f13 (patch)
tree65ae9b380e03c0fe0bc9e817cfd0f3cd8a7c2c8e
parent861a703c1afc9b8fad0226dd5408eb200a0085c1 (diff)
downloadpoky-9b839a835cc0746c59f9d74ef0e66c79280f8f13.tar.gz
bblayers/makesetup.py: Move git utility functions to oe.buildcfg module
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. (From OE-Core rev: a04a084b6e513d15cb57ee103c6d6215ce1c75b9) Signed-off-by: Jermain Horsman <jermain.horsman@nedap.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/bblayers/makesetup.py33
-rw-r--r--meta/lib/oe/buildcfg.py29
2 files changed, 39 insertions, 23 deletions
diff --git a/meta/lib/bblayers/makesetup.py b/meta/lib/bblayers/makesetup.py
index 4f27c565ee..99d5973760 100644
--- a/meta/lib/bblayers/makesetup.py
+++ b/meta/lib/bblayers/makesetup.py
@@ -9,7 +9,6 @@ import os
9import sys 9import sys
10 10
11import bb.utils 11import bb.utils
12import bb.process
13 12
14from bblayers.common import LayerPlugin 13from bblayers.common import LayerPlugin
15 14
@@ -24,25 +23,12 @@ def plugin_init(plugins):
24 23
25class MakeSetupPlugin(LayerPlugin): 24class MakeSetupPlugin(LayerPlugin):
26 25
27 def _get_repo_path(self, layer_path): 26 def _get_remotes_with_url(self, repo_path):
28 repo_path, _ = bb.process.run('git rev-parse --show-toplevel', cwd=layer_path)
29 return repo_path.strip()
30
31 def _get_remotes(self, repo_path):
32 remotes = {} 27 remotes = {}
33 remotes_list,_ = bb.process.run('git remote', cwd=repo_path) 28 for r in oe.buildcfg.get_metadata_git_remotes(repo_path):
34 for r in remotes_list.split(): 29 remotes[r] = {'uri':oe.buildcfg.get_metadata_git_remote_url(repo_path, r)}
35 uri,_ = bb.process.run('git remote get-url {r}'.format(r=r), cwd=repo_path)
36 remotes[r] = {'uri':uri.strip()}
37 return remotes 30 return remotes
38 31
39 def _get_describe(self, repo_path):
40 try:
41 describe,_ = bb.process.run('git describe --tags', cwd=repo_path)
42 except bb.process.ExecutionError:
43 return ""
44 return describe.strip()
45
46 def _is_submodule(self, repo_path): 32 def _is_submodule(self, repo_path):
47 # This is slightly brittle: git does not offer a way to tell whether 33 # This is slightly brittle: git does not offer a way to tell whether
48 # a given repo dir is a submodule checkout, so we need to rely on .git 34 # a given repo dir is a submodule checkout, so we need to rely on .git
@@ -56,10 +42,7 @@ class MakeSetupPlugin(LayerPlugin):
56 available here. """ 42 available here. """
57 repos = {} 43 repos = {}
58 layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data) 44 layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data)
59 try: 45 destdir_repo = oe.buildcfg.get_metadata_git_toplevel(destdir)
60 destdir_repo = self._get_repo_path(destdir)
61 except bb.process.ExecutionError:
62 destdir_repo = None
63 46
64 for (l_path, l_name, l_branch, l_rev, l_ismodified) in layers: 47 for (l_path, l_name, l_branch, l_rev, l_ismodified) in layers:
65 if l_name == 'workspace': 48 if l_name == 'workspace':
@@ -67,12 +50,16 @@ class MakeSetupPlugin(LayerPlugin):
67 if l_ismodified: 50 if l_ismodified:
68 logger.error("Layer {name} in {path} has uncommitted modifications or is not in a git repository.".format(name=l_name,path=l_path)) 51 logger.error("Layer {name} in {path} has uncommitted modifications or is not in a git repository.".format(name=l_name,path=l_path))
69 return 52 return
70 repo_path = self._get_repo_path(l_path) 53 repo_path = oe.buildcfg.get_metadata_git_toplevel(l_path)
71 54
72 if self._is_submodule(repo_path): 55 if self._is_submodule(repo_path):
73 continue 56 continue
74 if repo_path not in repos.keys(): 57 if repo_path not in repos.keys():
75 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)}} 58 repos[repo_path] = {'path':os.path.basename(repo_path),'git-remote':{
59 'rev':l_rev,
60 'branch':l_branch,
61 'remotes':self._get_remotes_with_url(repo_path),
62 'describe':oe.buildcfg.get_metadata_git_describe(repo_path)}}
76 if repo_path == destdir_repo: 63 if repo_path == destdir_repo:
77 repos[repo_path]['contains_this_file'] = True 64 repos[repo_path]['contains_this_file'] = True
78 if not repos[repo_path]['git-remote']['remotes'] and not repos[repo_path]['contains_this_file']: 65 if not repos[repo_path]['git-remote']['remotes'] and not repos[repo_path]['contains_this_file']:
diff --git a/meta/lib/oe/buildcfg.py b/meta/lib/oe/buildcfg.py
index b3fe510309..27b059b834 100644
--- a/meta/lib/oe/buildcfg.py
+++ b/meta/lib/oe/buildcfg.py
@@ -28,6 +28,35 @@ def get_metadata_git_revision(path):
28 rev = '<unknown>' 28 rev = '<unknown>'
29 return rev.strip() 29 return rev.strip()
30 30
31def get_metadata_git_toplevel(path):
32 try:
33 toplevel, _ = bb.process.run('git rev-parse --show-toplevel', cwd=path)
34 except bb.process.ExecutionError:
35 return ""
36 return toplevel.strip()
37
38def get_metadata_git_remotes(path):
39 try:
40 remotes_list, _ = bb.process.run('git remote', cwd=path)
41 remotes = remotes_list.split()
42 except bb.process.ExecutionError:
43 remotes = []
44 return remotes
45
46def get_metadata_git_remote_url(path, remote):
47 try:
48 uri, _ = bb.process.run('git remote get-url {remote}'.format(remote=remote), cwd=path)
49 except bb.process.ExecutionError:
50 return ""
51 return uri.strip()
52
53def get_metadata_git_describe(path):
54 try:
55 describe, _ = bb.process.run('git describe --tags', cwd=path)
56 except bb.process.ExecutionError:
57 return ""
58 return describe.strip()
59
31def is_layer_modified(path): 60def is_layer_modified(path):
32 try: 61 try:
33 subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; 62 subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e;