aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool
diff options
context:
space:
mode:
authorChang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>2017-08-21 17:39:41 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-21 08:30:32 +0100
commitecca596b75cfda2f798a0bdde75f4f774e23a95b (patch)
treead20dfceeb1dbb6e9c25c0158fc56d499c78edc6 /scripts/lib/recipetool
parent091cee2bdc2378a3425a4ef8558d03e6f9c021ff (diff)
downloadopenembedded-core-contrib-ecca596b75cfda2f798a0bdde75f4f774e23a95b.tar.gz
recipetool: create: being able to set branch when revision is provided
This change is to improve the buildability of the recipe created by recipetool and devtool. When recipetool create is run on a git URL and a revision specified that is not on master, and "branch=" isn't already in the URL, then we should get the correct branch and append the branch to the URL. If the revision was found on multiple branches and 'master' is not in the list, we will display error to inform user to provide a correct branch and exit. [YOCTO #11389] 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/recipetool')
-rw-r--r--scripts/lib/recipetool/create.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 2c3a58a143..8d59e65a8f 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -422,6 +422,7 @@ def create_recipe(args):
source = args.source
srcsubdir = ''
srcrev = '${AUTOREV}'
+ srcbranch = ''
if os.path.isfile(source):
source = 'file://%s' % os.path.abspath(source)
@@ -440,6 +441,19 @@ def create_recipe(args):
srcrev = res.group(1)
srcuri = rev_re.sub('', srcuri)
+ # Check whether users provides any branch info in fetchuri.
+ # If true, we will skip all branch checking process to honor all user's input.
+ scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(fetchuri)
+ srcbranch = params.get('branch')
+ nobranch = params.get('nobranch')
+ if not srcbranch and not nobranch and srcrev != '${AUTOREV}':
+ # Append nobranch=1 in the following conditions:
+ # 1. User did not set 'branch=' in srcuri, and
+ # 2. User did not set 'nobranch=1' in srcuri, and
+ # 3. Source revision is not '${AUTOREV}'
+ params['nobranch'] = '1'
+ fetchuri = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params))
+
tmpparent = tinfoil.config_data.getVar('BASE_WORKDIR')
bb.utils.mkdirhier(tmpparent)
tempsrc = tempfile.mkdtemp(prefix='recipetool-', dir=tmpparent)
@@ -475,6 +489,40 @@ def create_recipe(args):
logger.error('URL %s resulted in an empty source tree' % fetchuri)
sys.exit(1)
+ # We need this checking mechanism to improve the recipe created by recipetool and devtool
+ # is able to parse and build by bitbake.
+ # If there is no input for branch name, then check for branch name with SRCREV provided.
+ if not srcbranch and not nobranch and srcrev and (srcrev != '${AUTOREV}'):
+ try:
+ cmd = 'git branch -r --contains'
+ check_branch, check_branch_err = bb.process.run('%s %s' % (cmd, srcrev), cwd=srctree)
+ except bb.process.ExecutionError as err:
+ logger.error(str(err))
+ sys.exit(1)
+ get_branch = [x.strip() for x in check_branch.splitlines()]
+ # Remove HEAD reference point and drop remote prefix
+ get_branch = [x.split('/', 1)[1] for x in get_branch if not x.startswith('origin/HEAD')]
+ if 'master' in get_branch:
+ # If it is master, we do not need to append 'branch=master' as this is default.
+ # Even with the case where get_branch has multiple objects, if 'master' is one
+ # of them, we should default take from 'master'
+ srcbranch = ''
+ elif len(get_branch) == 1:
+ # If 'master' isn't in get_branch and get_branch contains only ONE object, then store result into 'srcbranch'
+ srcbranch = get_branch[0]
+ else:
+ # If get_branch contains more than one objects, then display error and exit.
+ mbrch = '\n ' + '\n '.join(get_branch)
+ logger.error('Revision %s was found on multiple branches: %s\nPlease provide the correct branch in the source URL with ;branch=<branch> (and ensure you use quotes around the URL to avoid the shell interpreting the ";")' % (srcrev, mbrch))
+ sys.exit(1)
+
+ # Since we might have a value in srcbranch, we need to
+ # recontruct the srcuri to include 'branch' in params.
+ if srcbranch:
+ scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(srcuri)
+ params['branch'] = srcbranch
+ srcuri = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params))
+
if os.path.exists(os.path.join(srctree, '.gitmodules')) and srcuri.startswith('git://'):
srcuri = 'gitsm://' + srcuri[6:]
logger.info('Fetching submodules...')