summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bblayers/layerindex.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bblayers/layerindex.py')
-rw-r--r--bitbake/lib/bblayers/layerindex.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/bitbake/lib/bblayers/layerindex.py b/bitbake/lib/bblayers/layerindex.py
index b2f27b21ee..ba91fac669 100644
--- a/bitbake/lib/bblayers/layerindex.py
+++ b/bitbake/lib/bblayers/layerindex.py
@@ -1,4 +1,6 @@
1# 1#
2# Copyright BitBake Contributors
3#
2# SPDX-License-Identifier: GPL-2.0-only 4# SPDX-License-Identifier: GPL-2.0-only
3# 5#
4 6
@@ -47,6 +49,31 @@ class LayerIndexPlugin(ActionPlugin):
47 else: 49 else:
48 logger.plain("Repository %s needs to be fetched" % url) 50 logger.plain("Repository %s needs to be fetched" % url)
49 return subdir, layername, layerdir 51 return subdir, layername, layerdir
52 elif os.path.exists(repodir) and branch:
53 """
54 If the repo is already cloned, ensure it is on the correct branch,
55 switching branches if necessary and possible.
56 """
57 base_cmd = ['git', '--git-dir=%s/.git' % repodir, '--work-tree=%s' % repodir]
58 cmd = base_cmd + ['branch']
59 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
60 if completed_proc.returncode:
61 logger.error("Unable to validate repo %s (%s)" % (repodir, stderr))
62 return None, None, None
63 else:
64 if branch != completed_proc.stdout[2:-1]:
65 cmd = base_cmd + ['status', '--short']
66 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
67 if completed_proc.stdout.count('\n') != 0:
68 logger.warning("There are uncommitted changes in repo %s" % repodir)
69 cmd = base_cmd + ['checkout', branch]
70 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
71 if completed_proc.returncode:
72 # Could be due to original shallow clone on a different branch for example
73 logger.error("Unable to automatically switch %s to desired branch '%s' (%s)"
74 % (repodir, branch, completed_proc.stderr))
75 return None, None, None
76 return subdir, layername, layerdir
50 elif os.path.exists(layerdir): 77 elif os.path.exists(layerdir):
51 return subdir, layername, layerdir 78 return subdir, layername, layerdir
52 else: 79 else:
@@ -159,12 +186,17 @@ class LayerIndexPlugin(ActionPlugin):
159 logger.plain(' recommended by: %s' % ' '.join(recommendedby)) 186 logger.plain(' recommended by: %s' % ' '.join(recommendedby))
160 187
161 if dependencies: 188 if dependencies:
162 fetchdir = self.tinfoil.config_data.getVar('BBLAYERS_FETCH_DIR') 189 if args.fetchdir:
163 if not fetchdir: 190 fetchdir = args.fetchdir
164 logger.error("Cannot get BBLAYERS_FETCH_DIR") 191 else:
165 return 1 192 fetchdir = self.tinfoil.config_data.getVar('BBLAYERS_FETCH_DIR')
193 if not fetchdir:
194 logger.error("Cannot get BBLAYERS_FETCH_DIR")
195 return 1
196
166 if not os.path.exists(fetchdir): 197 if not os.path.exists(fetchdir):
167 os.makedirs(fetchdir) 198 os.makedirs(fetchdir)
199
168 addlayers = [] 200 addlayers = []
169 201
170 for deplayerbranch in dependencies: 202 for deplayerbranch in dependencies:
@@ -206,6 +238,8 @@ class LayerIndexPlugin(ActionPlugin):
206""" 238"""
207 args.show_only = True 239 args.show_only = True
208 args.ignore = [] 240 args.ignore = []
241 args.fetchdir = ""
242 args.shallow = True
209 self.do_layerindex_fetch(args) 243 self.do_layerindex_fetch(args)
210 244
211 def register_commands(self, sp): 245 def register_commands(self, sp):
@@ -214,6 +248,7 @@ class LayerIndexPlugin(ActionPlugin):
214 parser_layerindex_fetch.add_argument('-b', '--branch', help='branch name to fetch') 248 parser_layerindex_fetch.add_argument('-b', '--branch', help='branch name to fetch')
215 parser_layerindex_fetch.add_argument('-s', '--shallow', help='do only shallow clones (--depth=1)', action='store_true') 249 parser_layerindex_fetch.add_argument('-s', '--shallow', help='do only shallow clones (--depth=1)', action='store_true')
216 parser_layerindex_fetch.add_argument('-i', '--ignore', help='assume the specified layers do not need to be fetched/added (separate multiple layers with commas, no spaces)', metavar='LAYER') 250 parser_layerindex_fetch.add_argument('-i', '--ignore', help='assume the specified layers do not need to be fetched/added (separate multiple layers with commas, no spaces)', metavar='LAYER')
251 parser_layerindex_fetch.add_argument('-f', '--fetchdir', help='directory to fetch the layer(s) into (will be created if it does not exist)')
217 parser_layerindex_fetch.add_argument('layername', nargs='+', help='layer to fetch') 252 parser_layerindex_fetch.add_argument('layername', nargs='+', help='layer to fetch')
218 253
219 parser_layerindex_show_depends = self.add_command(sp, 'layerindex-show-depends', self.do_layerindex_show_depends, parserecipes=False) 254 parser_layerindex_show_depends = self.add_command(sp, 'layerindex-show-depends', self.do_layerindex_show_depends, parserecipes=False)