[OE-core] [PATCHv3 2/3] recipetool: create: being able to set branch when revision is provided
Chang Rebecca Swee Fun
rebecca.swee.fun.chang at intel.com
Mon Jul 24 08:25:02 UTC 2017
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, 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 at intel.com>
---
scripts/lib/recipetool/create.py | 41 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 3885017..5f60fc3 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -423,6 +423,8 @@ def create_recipe(args):
srcsubdir = ''
srcrev = '${AUTOREV}'
mirrors = args.mirrors
+ branch_re = re.compile(';branch=([^;]+)')
+ branch = ''
if os.path.isfile(source):
source = 'file://%s' % os.path.abspath(source)
@@ -449,6 +451,19 @@ def create_recipe(args):
tinfoil.config_data.setVar('PREMIRRORS', '')
tinfoil.config_data.setVar('MIRRORS', '')
+ # Check whether branch info is provided
+ branch = branch_re.search(srcuri)
+ nobranch_re = re.compile(';nobranch=1')
+ nobranch = nobranch_re.search(srcuri)
+ # Back up a copy of srcuri
+ srcuri_copy = srcuri
+ if not branch 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}'
+ srcuri = srcuri + ';nobranch=1'
+
tmpparent = tinfoil.config_data.getVar('BASE_WORKDIR')
bb.utils.mkdirhier(tmpparent)
tempsrc = tempfile.mkdtemp(prefix='recipetool-', dir=tmpparent)
@@ -484,6 +499,27 @@ def create_recipe(args):
logger.error('URL %s resulted in an empty source tree' % fetchuri)
sys.exit(1)
+ # Check for branch info with SRCREV provided
+ if not branch and not nobranch and srcrev and (srcrev != '${AUTOREV}'):
+ # Command to check branch using commit hash
+ cmd = 'git branch -r --contains'
+ try:
+ 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 len(get_branch) == 1:
+ # If get_branch contains only ONE object, then store result into 'branch'
+ branch = 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)
+
if os.path.exists(os.path.join(srctree, '.gitmodules')) and srcuri.startswith('git://'):
srcuri = 'gitsm://' + srcuri[6:]
logger.info('Fetching submodules...')
@@ -604,6 +640,11 @@ def create_recipe(args):
if not srcuri:
lines_before.append('# No information for SRC_URI yet (only an external source tree was specified)')
+ # Check if users has provide a branch
+ append_branch = branch_re.search(srcuri)
+ if branch and not append_branch:
+ # Append the correct branch into SRC_URI
+ srcuri = srcuri_copy + (';branch=%s' % str(branch))
lines_before.append('SRC_URI = "%s"' % srcuri)
for key, value in sorted(checksums.items()):
lines_before.append('SRC_URI[%s] = "%s"' % (key, value))
--
2.7.4
More information about the Openembedded-core
mailing list