Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | # Recipe creation tool - set variable plugin |
| 2 | # |
| 3 | # Copyright (C) 2015 Intel Corporation |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7 | |
| 8 | import sys |
| 9 | import os |
| 10 | import argparse |
| 11 | import glob |
| 12 | import fnmatch |
| 13 | import re |
| 14 | import logging |
| 15 | import scriptutils |
| 16 | |
| 17 | logger = logging.getLogger('recipetool') |
| 18 | |
| 19 | tinfoil = None |
| 20 | plugins = None |
| 21 | |
| 22 | def tinfoil_init(instance): |
| 23 | global tinfoil |
| 24 | tinfoil = instance |
| 25 | |
| 26 | def 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | rd = tinfoil.parse_recipe_file(args.recipefile, False) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 45 | 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 | |
| 55 | def 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) |