]> code.ossystems Code Review - openembedded-core.git/commitdiff
recipetool: add setvar subcommand
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Thu, 19 Nov 2015 04:17:25 +0000 (17:17 +1300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 1 Dec 2015 21:30:55 +0000 (21:30 +0000)
Add a recipetool subcommand "setvar" to set a variable in a file. This
uses our existing logic such that it doesn't matter if the variable is
already set in the recipe, if it's set in the recipe or some inc file,
and if the variable is not currently set that the line setting the
variable gets inserted in the right place in the file.

Implements [YOCTO #7676].

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/lib/recipetool/setvar.py [new file with mode: 0644]
scripts/recipetool

diff --git a/scripts/lib/recipetool/setvar.py b/scripts/lib/recipetool/setvar.py
new file mode 100644 (file)
index 0000000..18e3281
--- /dev/null
@@ -0,0 +1,75 @@
+# Recipe creation tool - set variable plugin
+#
+# Copyright (C) 2015 Intel Corporation
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+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 setvar(args):
+    import oe.recipeutils
+
+    if args.delete:
+        if args.value:
+            logger.error('-D/--delete and specifying a value are mutually exclusive')
+            return 1
+        value = None
+    else:
+        if args.value is None:
+            logger.error('You must specify a value if not using -D/--delete')
+            return 1
+        value = args.value
+    varvalues = {args.varname: value}
+
+    if args.recipe_only:
+        patches = [oe.recipeutils.patch_recipe_file(args.recipefile, varvalues, patch=args.patch)]
+    else:
+        rd = oe.recipeutils.parse_recipe(args.recipefile, None, tinfoil.config_data)
+        if not rd:
+            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_command(subparsers):
+    parser_setvar = subparsers.add_parser('setvar',
+                                          help='Set a variable within a recipe',
+                                          description='Adds/updates the value a variable is set to in a recipe')
+    parser_setvar.add_argument('recipefile', help='Recipe file to update')
+    parser_setvar.add_argument('varname', help='Variable name to set')
+    parser_setvar.add_argument('value', nargs='?', help='New value to set the variable to')
+    parser_setvar.add_argument('--recipe-only', '-r', help='Do not set variable in any include file if present', action='store_true')
+    parser_setvar.add_argument('--patch', '-p', help='Create a patch to make the change instead of modifying the recipe', action='store_true')
+    parser_setvar.add_argument('--delete', '-D', help='Delete the specified value instead of setting it', action='store_true')
+    parser_setvar.set_defaults(func=setvar)
index 87fb35ed72abaedf5052988789cc807cac6b3f6b..4af0bfb686edc70a059dfe9ca907d31964131cd0 100755 (executable)
@@ -34,7 +34,7 @@ plugins = []
 def tinfoil_init(parserecipes):
     import bb.tinfoil
     import logging
-    tinfoil = bb.tinfoil.Tinfoil()
+    tinfoil = bb.tinfoil.Tinfoil(tracking=True)
     tinfoil.prepare(not parserecipes)
     tinfoil.logger.setLevel(logger.getEffectiveLevel())
     return tinfoil
@@ -96,7 +96,9 @@ def main():
 
     try:
         if getattr(args, 'parserecipes', False):
+            tinfoil.config_data.disableTracking()
             tinfoil.parseRecipes()
+            tinfoil.config_data.enableTracking()
         ret = args.func(args)
     except bb.BBHandledException:
         ret = 1