blob: f8e2ee75fbecd8c0859674336391e3faf6c0525f [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001# Recipe creation tool - set variable plugin
2#
3# Copyright (C) 2015 Intel Corporation
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007
8import sys
9import os
10import argparse
11import glob
12import fnmatch
13import re
14import logging
15import scriptutils
16
17logger = logging.getLogger('recipetool')
18
19tinfoil = None
20plugins = None
21
22def tinfoil_init(instance):
23 global tinfoil
24 tinfoil = instance
25
26def setvar(args):
27 import oe.recipeutils
28
29 if args.delete:
30 if args.value:
31 logger.error('-D/--delete and specifying a value are mutually exclusive')
32 return 1
33 value = None
34 else:
35 if args.value is None:
36 logger.error('You must specify a value if not using -D/--delete')
37 return 1
38 value = args.value
39 varvalues = {args.varname: value}
40
41 if args.recipe_only:
42 patches = [oe.recipeutils.patch_recipe_file(args.recipefile, varvalues, patch=args.patch)]
43 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 rd = tinfoil.parse_recipe_file(args.recipefile, False)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 if not rd:
46 return 1
47 patches = oe.recipeutils.patch_recipe(rd, args.recipefile, varvalues, patch=args.patch)
48 if args.patch:
49 for patch in patches:
50 for line in patch:
51 sys.stdout.write(line)
52 return 0
53
54
55def register_commands(subparsers):
56 parser_setvar = subparsers.add_parser('setvar',
57 help='Set a variable within a recipe',
58 description='Adds/updates the value a variable is set to in a recipe')
59 parser_setvar.add_argument('recipefile', help='Recipe file to update')
60 parser_setvar.add_argument('varname', help='Variable name to set')
61 parser_setvar.add_argument('value', nargs='?', help='New value to set the variable to')
62 parser_setvar.add_argument('--recipe-only', '-r', help='Do not set variable in any include file if present', action='store_true')
63 parser_setvar.add_argument('--patch', '-p', help='Create a patch to make the change instead of modifying the recipe', action='store_true')
64 parser_setvar.add_argument('--delete', '-D', help='Delete the specified value instead of setting it', action='store_true')
65 parser_setvar.set_defaults(func=setvar)