diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/recipetool/setvar.py | 75 | ||||
-rwxr-xr-x | scripts/recipetool | 4 |
2 files changed, 78 insertions, 1 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 | |||
18 | import sys | ||
19 | import os | ||
20 | import argparse | ||
21 | import glob | ||
22 | import fnmatch | ||
23 | import re | ||
24 | import logging | ||
25 | import scriptutils | ||
26 | |||
27 | logger = logging.getLogger('recipetool') | ||
28 | |||
29 | tinfoil = None | ||
30 | plugins = None | ||
31 | |||
32 | def tinfoil_init(instance): | ||
33 | global tinfoil | ||
34 | tinfoil = instance | ||
35 | |||
36 | def 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 | |||
65 | def 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) | ||
diff --git a/scripts/recipetool b/scripts/recipetool index 87fb35ed72..4af0bfb686 100755 --- a/scripts/recipetool +++ b/scripts/recipetool | |||
@@ -34,7 +34,7 @@ plugins = [] | |||
34 | def tinfoil_init(parserecipes): | 34 | def tinfoil_init(parserecipes): |
35 | import bb.tinfoil | 35 | import bb.tinfoil |
36 | import logging | 36 | import logging |
37 | tinfoil = bb.tinfoil.Tinfoil() | 37 | tinfoil = bb.tinfoil.Tinfoil(tracking=True) |
38 | tinfoil.prepare(not parserecipes) | 38 | tinfoil.prepare(not parserecipes) |
39 | tinfoil.logger.setLevel(logger.getEffectiveLevel()) | 39 | tinfoil.logger.setLevel(logger.getEffectiveLevel()) |
40 | return tinfoil | 40 | return tinfoil |
@@ -96,7 +96,9 @@ def main(): | |||
96 | 96 | ||
97 | try: | 97 | try: |
98 | if getattr(args, 'parserecipes', False): | 98 | if getattr(args, 'parserecipes', False): |
99 | tinfoil.config_data.disableTracking() | ||
99 | tinfoil.parseRecipes() | 100 | tinfoil.parseRecipes() |
101 | tinfoil.config_data.enableTracking() | ||
100 | ret = args.func(args) | 102 | ret = args.func(args) |
101 | except bb.BBHandledException: | 103 | except bb.BBHandledException: |
102 | ret = 1 | 104 | ret = 1 |