diff options
author | Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com> | 2017-08-21 17:39:41 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-08-23 08:47:02 +0100 |
commit | 62d5035ffca049e1c817b53be3074b2d13a6d2d7 (patch) | |
tree | 408d4aa786265cc9c30ab3d485ce4f724819eac1 | |
parent | e09b9d4543c6f0cba9215a0ed3cfb97fc7153471 (diff) | |
download | poky-62d5035ffca049e1c817b53be3074b2d13a6d2d7.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]
(From OE-Core rev: ecca596b75cfda2f798a0bdde75f4f774e23a95b)
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>
-rw-r--r-- | scripts/lib/recipetool/create.py | 48 |
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): | |||
422 | source = args.source | 422 | source = args.source |
423 | srcsubdir = '' | 423 | srcsubdir = '' |
424 | srcrev = '${AUTOREV}' | 424 | srcrev = '${AUTOREV}' |
425 | srcbranch = '' | ||
425 | 426 | ||
426 | if os.path.isfile(source): | 427 | if os.path.isfile(source): |
427 | source = 'file://%s' % os.path.abspath(source) | 428 | source = 'file://%s' % os.path.abspath(source) |
@@ -440,6 +441,19 @@ def create_recipe(args): | |||
440 | srcrev = res.group(1) | 441 | srcrev = res.group(1) |
441 | srcuri = rev_re.sub('', srcuri) | 442 | srcuri = rev_re.sub('', srcuri) |
442 | 443 | ||
444 | # Check whether users provides any branch info in fetchuri. | ||
445 | # If true, we will skip all branch checking process to honor all user's input. | ||
446 | scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(fetchuri) | ||
447 | srcbranch = params.get('branch') | ||
448 | nobranch = params.get('nobranch') | ||
449 | if not srcbranch and not nobranch and srcrev != '${AUTOREV}': | ||
450 | # Append nobranch=1 in the following conditions: | ||
451 | # 1. User did not set 'branch=' in srcuri, and | ||
452 | # 2. User did not set 'nobranch=1' in srcuri, and | ||
453 | # 3. Source revision is not '${AUTOREV}' | ||
454 | params['nobranch'] = '1' | ||
455 | fetchuri = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params)) | ||
456 | |||
443 | tmpparent = tinfoil.config_data.getVar('BASE_WORKDIR') | 457 | tmpparent = tinfoil.config_data.getVar('BASE_WORKDIR') |
444 | bb.utils.mkdirhier(tmpparent) | 458 | bb.utils.mkdirhier(tmpparent) |
445 | tempsrc = tempfile.mkdtemp(prefix='recipetool-', dir=tmpparent) | 459 | tempsrc = tempfile.mkdtemp(prefix='recipetool-', dir=tmpparent) |
@@ -475,6 +489,40 @@ def create_recipe(args): | |||
475 | logger.error('URL %s resulted in an empty source tree' % fetchuri) | 489 | logger.error('URL %s resulted in an empty source tree' % fetchuri) |
476 | sys.exit(1) | 490 | sys.exit(1) |
477 | 491 | ||
492 | # We need this checking mechanism to improve the recipe created by recipetool and devtool | ||
493 | # is able to parse and build by bitbake. | ||
494 | # If there is no input for branch name, then check for branch name with SRCREV provided. | ||
495 | if not srcbranch and not nobranch and srcrev and (srcrev != '${AUTOREV}'): | ||
496 | try: | ||
497 | cmd = 'git branch -r --contains' | ||
498 | check_branch, check_branch_err = bb.process.run('%s %s' % (cmd, srcrev), cwd=srctree) | ||
499 | except bb.process.ExecutionError as err: | ||
500 | logger.error(str(err)) | ||
501 | sys.exit(1) | ||
502 | get_branch = [x.strip() for x in check_branch.splitlines()] | ||
503 | # Remove HEAD reference point and drop remote prefix | ||
504 | get_branch = [x.split('/', 1)[1] for x in get_branch if not x.startswith('origin/HEAD')] | ||
505 | if 'master' in get_branch: | ||
506 | # If it is master, we do not need to append 'branch=master' as this is default. | ||
507 | # Even with the case where get_branch has multiple objects, if 'master' is one | ||
508 | # of them, we should default take from 'master' | ||
509 | srcbranch = '' | ||
510 | elif len(get_branch) == 1: | ||
511 | # If 'master' isn't in get_branch and get_branch contains only ONE object, then store result into 'srcbranch' | ||
512 | srcbranch = get_branch[0] | ||
513 | else: | ||
514 | # If get_branch contains more than one objects, then display error and exit. | ||
515 | mbrch = '\n ' + '\n '.join(get_branch) | ||
516 | 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)) | ||
517 | sys.exit(1) | ||
518 | |||
519 | # Since we might have a value in srcbranch, we need to | ||
520 | # recontruct the srcuri to include 'branch' in params. | ||
521 | if srcbranch: | ||
522 | scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(srcuri) | ||
523 | params['branch'] = srcbranch | ||
524 | srcuri = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params)) | ||
525 | |||
478 | if os.path.exists(os.path.join(srctree, '.gitmodules')) and srcuri.startswith('git://'): | 526 | if os.path.exists(os.path.join(srctree, '.gitmodules')) and srcuri.startswith('git://'): |
479 | srcuri = 'gitsm://' + srcuri[6:] | 527 | srcuri = 'gitsm://' + srcuri[6:] |
480 | logger.info('Fetching submodules...') | 528 | logger.info('Fetching submodules...') |