summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2020-05-07 09:44:24 +0000
committerMax Krummenacher <max.krummenacher@toradex.com>2020-09-16 17:06:39 +0200
commitb178f25788f568f4ff311c9660a76c62bab38eb9 (patch)
tree50f9818ee9b9dd7cf49b8a515529f1c682364d3d
parentd84f3ee332e6e14fad9d1af9aa374d993f068036 (diff)
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 <path-to-recipe> Related-to: AUT-354 Signed-off-by: Stefan Agner <stefan.agner@toradex.com> (cherry picked from commit f80b1846113635ec84177f0020efab02f6679d1a)
-rw-r--r--lib/recipetool/__init__.py0
-rw-r--r--lib/recipetool/updatesrcrev.py78
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/recipetool/__init__.py b/lib/recipetool/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/recipetool/__init__.py
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)