[yocto] [PATCH V4 01/10] update.py: update actual branch for layer and bitbake

Paul Eggleton paul.eggleton at linux.intel.com
Wed Jun 21 02:01:12 PDT 2017


Hi Robert,

Apologies for the delay on reviewing these patches. Some comments below.

On Tuesday, 13 June 2017 4:36:42 AM CEST Robert Yang wrote:
> Add an option "-a" to update actual branch for layer and bitbake, it is
> useful when there are many layers and need update actual branches
> frequantly. We only can update them via website without this patch,
> which is not funny and easy to make mistakes.

frequantly -> frequently
funny -> fun


> * It works with "-l", and "-l bitbake" means update bitbake branch.
> * It requires "-b" to work, and only one branch is supported in a run.
> 
> For example:
> $ update.py -b master -a branch_20170526
> All the layers which have branch master and actual_branch branch_20170526
> will be updated to branch_20170526.
> 
> $ update.py -b master -l meta-oe -a branch_20170526
> Only meta-oe layer will be updated.
> 
> $ update.py -b master -l bitbake -a branch_20170526
> The bitbake's bitbake_branch will be updated.
> 
> Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
> ---
>  layerindex/update.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++------
>  layerindex/utils.py  | 11 +++++++
>  2 files changed, 83 insertions(+), 9 deletions(-)
> 
> diff --git a/layerindex/update.py b/layerindex/update.py
> index d5c56cd..7d2e367 100755
> --- a/layerindex/update.py
> +++ b/layerindex/update.py
> @@ -85,6 +85,43 @@ def prepare_update_layer_command(options, branch, layer, updatedeps=False):
>          cmd += ' -q'
>      return cmd
>  
> +def update_actual_branch(layerquery, fetchdir, branch, options, update_bitbake, bitbakepath):
> +    """Update actual branch for layers and bitbake in database"""
> +    to_save = set()
> +    actual_branch = options.actual_branch
> +    if update_bitbake:
> +        branchobj = utils.get_branch(branch)
> +        if actual_branch != branchobj.bitbake_branch:
> +            if utils.is_branch_valid(bitbakepath, actual_branch):
> +                logger.info("bitbake: %s.bitbake_branch: %s -> %s" % (branch, branchobj.bitbake_branch, actual_branch))
> +                branchobj.bitbake_branch = actual_branch
> +                to_save.add(branchobj)
> +            else:
> +                logger.info("Skipping update bitbake_branch for bitbake - branch %s doens't exist" % actual_branch)

doens't -> doesn't (there are several of these)


> +        else:
> +            logger.info("bitbake: %s.bitbake_branch is already %s, so no change" % (branch, actual_branch))
> +
> +    for layer in layerquery:
> +        urldir = layer.get_fetch_dir()
> +        repodir = os.path.join(fetchdir, urldir)
> +        if not utils.is_branch_valid(repodir, actual_branch):
> +            logger.info("Skipping update actual_branch for %s - branch %s doens't exist" % (layer.name, actual_branch))
> +            continue
> +        layerbranch = layer.get_layerbranch(branch)
> +        if not layerbranch:
> +            logger.info("Skipping update actual_branch for %s - layerbranch %s doens't exist" % (layer.name, branch))
> +            continue
> +        if actual_branch != layerbranch.actual_branch:
> +            logger.info("%s: %s.actual_branch: %s -> %s" % (layer.name, branch, layerbranch.actual_branch, actual_branch))
> +            layerbranch.actual_branch = actual_branch
> +            to_save.add(layerbranch)
> +        else:
> +            logger.info("%s: %s.actual_branch is already %s, so no change" % (layer.name, branch, actual_branch))
> +
> +    # At last, do the save
> +    if not options.dryrun:
> +        for s in to_save:
> +            s.save()
>  
>  def main():
>      if LooseVersion(git.__version__) < '0.3.1':
> @@ -102,6 +139,9 @@ def main():
>      parser.add_option("-l", "--layer",
>              help = "Specify layers to update (use commas to separate multiple). Default is all published layers.",
>              action="store", dest="layers")
> +    parser.add_option("-a", "--actual-branch",
> +            help = "Update actual branch for layer and bitbake",

We should add "only" to the end of this since this option will suppress
the normal layer update since it returns afterwards, correct?


> +            action="store", dest="actual_branch", default='')
>      parser.add_option("-r", "--reload",
>              help = "Reload recipe data instead of updating since last update",
>              action="store_true", dest="reload")
> @@ -151,16 +191,35 @@ def main():
>          logger.error("Please set LAYER_FETCH_DIR in settings.py")
>          sys.exit(1)
>  
> +    # We deliberately exclude status == 'X' ("no update") here
> +    layerquery_all = LayerItem.objects.filter(classic=False).filter(status='P')
> +    if layerquery_all.count() == 0:
> +        logger.info("No published layers to update")
> +        sys.exit(1)

So near as I can tell this change isn't required as part of the other
changes here, it's just to tell you up front that no layers are published
if you've specified layers instead of seeing an error. I don't have an
issue with that but this change should be mentioned in the commit
message ("additionally ..."), or split out as a separate patch.


> +    # For -a option to update bitbake branch
> +    update_bitbake = False
>      if options.layers:
> -        layerquery = LayerItem.objects.filter(classic=False).filter(name__in=options.layers.split(','))
> -        if layerquery.count() == 0:
> -            logger.error('No layers matching specified query "%s"' % options.layers)
> -            sys.exit(1)
> +        layers = options.layers.split(',')
> +        if 'bitbake' in layers:
> +            update_bitbake = True
> +            layers.remove('bitbake')

So since this means 'bitbake' is a reserved name for layers we should add
validation upon layer submission to ensure you can't create a layer with this
name. I can take care of that if you like.


> +        for layer in layers:
> +            layerquery = LayerItem.objects.filter(classic=False).filter(name=layer)
> +            if layerquery.count() == 0:
> +                logger.error('No layers matching specified query "%s"' % layer)
> +                sys.exit(1)
> +        layerquery = LayerItem.objects.filter(classic=False).filter(name__in=layers)
>      else:
> -        # We deliberately exclude status == 'X' ("no update") here
> -        layerquery = LayerItem.objects.filter(classic=False).filter(status='P')
> -        if layerquery.count() == 0:
> -            logger.info("No published layers to update")
> +        update_bitbake = True
> +        layerquery = layerquery_all
> +
> +    if options.actual_branch:
> +        if not options.branch:
> +            logger.error("-a option requires -b")
> +            sys.exit(1)
> +        elif len(branches) != 1:
> +            logger.error("Only one branch should be used with -a")
>              sys.exit(1)
>  
>      if not os.path.exists(fetchdir):
> @@ -209,7 +268,7 @@ def main():
>                              continue
>                          fetchedrepos.append(layer.vcs_url)
>  
> -                if not fetchedrepos:
> +                if not (fetchedrepos or update_bitbake):
>                      logger.error("No repositories could be fetched, exiting")
>                      sys.exit(1)
>  
> @@ -219,6 +278,10 @@ def main():
>                  else:
>                      out = utils.runcmd("git fetch", bitbakepath, logger=logger)
>  
> +            if options.actual_branch:
> +                update_actual_branch(layerquery, fetchdir, branches[0], options, update_bitbake, bitbakepath)
> +                return
> +
>              # Process and extract data from each layer
>              # We now do this by calling out to a separate script; doing otherwise turned out to be
>              # unreliable due to leaking memory (we're using bitbake internals in a manner in which
> diff --git a/layerindex/utils.py b/layerindex/utils.py
> index 3b45b07..442b121 100644
> --- a/layerindex/utils.py
> +++ b/layerindex/utils.py
> @@ -160,6 +160,17 @@ def is_layer_valid(layerdir):
>          return False
>      return True
>  
> +def is_branch_valid(layerdir, branch):
> +    import git
> +
> +    g = git.cmd.Git(layerdir)
> +    assert g.rev_parse('--is-bare-repository') == 'false'
> +    try:
> +        g.rev_parse('--verify', 'origin/%s' % branch)
> +    except Exception:
> +        return False

Is there a more specific exception class we can respond to here instead of
Exception in case something unexpected happens?

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre



More information about the yocto mailing list