From f80b1846113635ec84177f0020efab02f6679d1a Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 7 May 2020 09:44:24 +0000 Subject: recipetool: add updatesrcrev sub-command Use the recipetool plugin mechanism to add a updatesrcrev command. This allows to update the SRCREV variable to point to the current git hash the references git branch is pointing to. A OpenEmbedded build environment needs to be initialized. Then use the following command to update SRCREV of a particular recipe: recipetool updatesrcrev Related-to: AUT-354 Signed-off-by: Stefan Agner --- lib/recipetool/__init__.py | 0 lib/recipetool/updatesrcrev.py | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 lib/recipetool/__init__.py create mode 100644 lib/recipetool/updatesrcrev.py diff --git a/lib/recipetool/__init__.py b/lib/recipetool/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/recipetool/updatesrcrev.py b/lib/recipetool/updatesrcrev.py new file mode 100644 index 0000000..d15afe5 --- /dev/null +++ b/lib/recipetool/updatesrcrev.py @@ -0,0 +1,78 @@ +# Recipe creation tool - update SRCREV +# +# Copyright (C) 2015 Intel Corporation +# Copyright (C) 2020 Toradex +# +# SPDX-License-Identifier: GPL-2.0-only +# +# Script which reads git hash from local BB_URI_HEADREVS cache and updates +# recipe files with it. +# +# Use export BB_SRCREV_POLICY="cache" before launching this tool to reuse git +# hashes from cache. +# + +import sys +import os +import argparse +import glob +import fnmatch +import re +import logging +import scriptutils + +logger = logging.getLogger('recipetool') + +tinfoil = None +plugins = None + +def tinfoil_init(instance): + global tinfoil + tinfoil = instance + +def updatesrcrev(args): + import oe.recipeutils + + rd = tinfoil.parse_recipe_file(args.recipefile, False) + if not rd: + return 1 + + src_uris = rd.getVar('SRC_URI').split() + revision = {} + for src_uri in src_uris: + # Support git only + if not src_uri.startswith(('git://', 'gitsm://')): + continue + + ud = bb.fetch2.FetchData(src_uri, rd) + # Allow multiple "named" git repos + for name in ud.names: + revision[name] = ud.method.latest_revision(ud, rd, name) + + # Update SRC_URI variable by default + varvalues = {} + for name in revision.keys(): + var = 'SRCREV' if name == 'default' else 'SRCREV_{}'.format(name) + logger.info('Update {} to {}.'.format(var, revision[name])) + varvalues[var] = revision[name] + + if len(varvalues) == 0: + logger.error('No updatable revision found.') + return 1 + + patches = oe.recipeutils.patch_recipe(rd, args.recipefile, varvalues, patch=args.patch) + if args.patch: + for patch in patches: + for line in patch: + sys.stdout.write(line) + + return 0 + + +def register_commands(subparsers): + parser_updatesrcrev = subparsers.add_parser('updatesrcrev', + help='Update SRCREV variable with the latest revision', + description='Adds/updates the value a variable is set to in a recipe') + parser_updatesrcrev.add_argument('recipefile', help='Recipe file to update') + parser_updatesrcrev.add_argument('--patch', '-p', help='Create a patch to make the change instead of modifying the recipe', action='store_true') + parser_updatesrcrev.set_defaults(func=updatesrcrev) -- cgit v1.2.3