summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/upgrade.py
diff options
context:
space:
mode:
authorChang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>2017-08-21 17:39:44 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-23 08:47:02 +0100
commitb47a7b848b43c3c7d76016d2868fd5360c34dc86 (patch)
treed97415cbdbdc6ca686ae5f49920796fb0357fb37 /scripts/lib/devtool/upgrade.py
parent439a6f1d68db56381e6f445e5cb1d5b6756aa1b8 (diff)
downloadpoky-b47a7b848b43c3c7d76016d2868fd5360c34dc86.tar.gz
devtool: upgrade: enable branch checking when revision is provided
When devtool upgrade is run on a recipe with revision specified that is not on master branch, and branch isn't set by --srcbranch or -B, then we should get the correct branch and append the branch to the URL. If the revision was found on multiple branches, we will display error to inform user to provide a correct branch and exit. [YOCTO #11484] (From OE-Core rev: 29ced7387a92aed17b7fe93b1654790a981734c1) Signed-off-by: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool/upgrade.py')
-rw-r--r--scripts/lib/devtool/upgrade.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/scripts/lib/devtool/upgrade.py b/scripts/lib/devtool/upgrade.py
index f077f37726..1f11d47e5a 100644
--- a/scripts/lib/devtool/upgrade.py
+++ b/scripts/lib/devtool/upgrade.py
@@ -180,7 +180,7 @@ def _get_uri(rd):
180 srcuri = rev_re.sub('', srcuri) 180 srcuri = rev_re.sub('', srcuri)
181 return srcuri, srcrev 181 return srcuri, srcrev
182 182
183def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tinfoil, rd): 183def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, keep_temp, tinfoil, rd):
184 """Extract sources of a recipe with a new version""" 184 """Extract sources of a recipe with a new version"""
185 185
186 def __run(cmd): 186 def __run(cmd):
@@ -202,6 +202,23 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tin
202 __run('git tag -f devtool-base-new') 202 __run('git tag -f devtool-base-new')
203 md5 = None 203 md5 = None
204 sha256 = None 204 sha256 = None
205 if not srcbranch:
206 check_branch, check_branch_err = __run('git branch -r --contains %s' % srcrev)
207 get_branch = [x.strip() for x in check_branch.splitlines()]
208 # Remove HEAD reference point and drop remote prefix
209 get_branch = [x.split('/', 1)[1] for x in get_branch if not x.startswith('origin/HEAD')]
210 if 'master' in get_branch:
211 # If it is master, we do not need to append 'branch=master' as this is default.
212 # Even with the case where get_branch has multiple objects, if 'master' is one
213 # of them, we should default take from 'master'
214 srcbranch = ''
215 elif len(get_branch) == 1:
216 # If 'master' isn't in get_branch and get_branch contains only ONE object, then store result into 'srcbranch'
217 srcbranch = get_branch[0]
218 else:
219 # If get_branch contains more than one objects, then display error and exit.
220 mbrch = '\n ' + '\n '.join(get_branch)
221 raise DevtoolError('Revision %s was found on multiple branches: %s\nPlease provide the correct branch in the devtool command with "--srcbranch" or "-B" option.' % (srcrev, mbrch))
205 else: 222 else:
206 __run('git checkout devtool-base -b devtool-%s' % newpv) 223 __run('git checkout devtool-base -b devtool-%s' % newpv)
207 224
@@ -275,7 +292,7 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tin
275 else: 292 else:
276 shutil.rmtree(tmpsrctree) 293 shutil.rmtree(tmpsrctree)
277 294
278 return (rev, md5, sha256) 295 return (rev, md5, sha256, srcbranch)
279 296
280def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, workspace, tinfoil, rd): 297def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, workspace, tinfoil, rd):
281 """Creates the new recipe under workspace""" 298 """Creates the new recipe under workspace"""
@@ -374,10 +391,10 @@ def upgrade(args, config, basepath, workspace):
374 rf = None 391 rf = None
375 try: 392 try:
376 rev1 = standard._extract_source(srctree, False, 'devtool-orig', False, rd, tinfoil) 393 rev1 = standard._extract_source(srctree, False, 'devtool-orig', False, rd, tinfoil)
377 rev2, md5, sha256 = _extract_new_source(args.version, srctree, args.no_patch, 394 rev2, md5, sha256, srcbranch = _extract_new_source(args.version, srctree, args.no_patch,
378 args.srcrev, args.branch, args.keep_temp, 395 args.srcrev, args.srcbranch, args.branch, args.keep_temp,
379 tinfoil, rd) 396 tinfoil, rd)
380 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, args.srcbranch, config.workspace_path, tinfoil, rd) 397 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, config.workspace_path, tinfoil, rd)
381 except bb.process.CmdError as e: 398 except bb.process.CmdError as e:
382 _upgrade_error(e, rf, srctree) 399 _upgrade_error(e, rf, srctree)
383 except DevtoolError as e: 400 except DevtoolError as e: