summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-11-19 17:17:25 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-01 21:32:05 +0000
commitb381f804a541bb1d08e331c139a82e250f924c05 (patch)
tree5230624a355a67304840f9aa04acfad613a98d83 /scripts/lib
parent1fbd76093dadd990dcb6ef8bd35659c73950cf7e (diff)
downloadpoky-b381f804a541bb1d08e331c139a82e250f924c05.tar.gz
recipetool: add setvar subcommand
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]. (From OE-Core rev: 7c33ef77fa165182d24f0a9ae769e9e630e6bd47) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/recipetool/setvar.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/setvar.py b/scripts/lib/recipetool/setvar.py
new file mode 100644
index 0000000000..18e3281b0e
--- /dev/null
+++ b/scripts/lib/recipetool/setvar.py
@@ -0,0 +1,75 @@
1# Recipe creation tool - set variable plugin
2#
3# Copyright (C) 2015 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import sys
19import os
20import argparse
21import glob
22import fnmatch
23import re
24import logging
25import scriptutils
26
27logger = logging.getLogger('recipetool')
28
29tinfoil = None
30plugins = None
31
32def tinfoil_init(instance):
33 global tinfoil
34 tinfoil = instance
35
36def setvar(args):
37 import oe.recipeutils
38
39 if args.delete:
40 if args.value:
41 logger.error('-D/--delete and specifying a value are mutually exclusive')
42 return 1
43 value = None
44 else:
45 if args.value is None:
46 logger.error('You must specify a value if not using -D/--delete')
47 return 1
48 value = args.value
49 varvalues = {args.varname: value}
50
51 if args.recipe_only:
52 patches = [oe.recipeutils.patch_recipe_file(args.recipefile, varvalues, patch=args.patch)]
53 else:
54 rd = oe.recipeutils.parse_recipe(args.recipefile, None, tinfoil.config_data)
55 if not rd:
56 return 1
57 patches = oe.recipeutils.patch_recipe(rd, args.recipefile, varvalues, patch=args.patch)
58 if args.patch:
59 for patch in patches:
60 for line in patch:
61 sys.stdout.write(line)
62 return 0
63
64
65def register_command(subparsers):
66 parser_setvar = subparsers.add_parser('setvar',
67 help='Set a variable within a recipe',
68 description='Adds/updates the value a variable is set to in a recipe')
69 parser_setvar.add_argument('recipefile', help='Recipe file to update')
70 parser_setvar.add_argument('varname', help='Variable name to set')
71 parser_setvar.add_argument('value', nargs='?', help='New value to set the variable to')
72 parser_setvar.add_argument('--recipe-only', '-r', help='Do not set variable in any include file if present', action='store_true')
73 parser_setvar.add_argument('--patch', '-p', help='Create a patch to make the change instead of modifying the recipe', action='store_true')
74 parser_setvar.add_argument('--delete', '-D', help='Delete the specified value instead of setting it', action='store_true')
75 parser_setvar.set_defaults(func=setvar)