Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2021 Richard Purdie |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
| 7 | |
| 8 | import argparse |
| 9 | import io |
| 10 | import os |
| 11 | import sys |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 12 | import warnings |
| 13 | warnings.simplefilter("default") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 14 | |
| 15 | bindir = os.path.dirname(__file__) |
| 16 | topdir = os.path.dirname(bindir) |
| 17 | sys.path[0:0] = [os.path.join(topdir, 'lib')] |
| 18 | |
| 19 | import bb.tinfoil |
| 20 | |
| 21 | if __name__ == "__main__": |
| 22 | parser = argparse.ArgumentParser(description="Bitbake Query Variable") |
| 23 | parser.add_argument("variable", help="variable name to query") |
| 24 | parser.add_argument("-r", "--recipe", help="Recipe name to query", default=None, required=False) |
| 25 | parser.add_argument('-u', '--unexpand', help='Do not expand the value (with --value)', action="store_true") |
| 26 | parser.add_argument('-f', '--flag', help='Specify a variable flag to query (with --value)', default=None) |
| 27 | parser.add_argument('--value', help='Only report the value, no history and no variable name', action="store_true") |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame^] | 28 | parser.add_argument('-q', '--quiet', help='Silence bitbake server logging', action="store_true") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 29 | args = parser.parse_args() |
| 30 | |
| 31 | if args.unexpand and not args.value: |
| 32 | print("--unexpand only makes sense with --value") |
| 33 | sys.exit(1) |
| 34 | |
| 35 | if args.flag and not args.value: |
| 36 | print("--flag only makes sense with --value") |
| 37 | sys.exit(1) |
| 38 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame^] | 39 | with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not args.quiet) as tinfoil: |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 40 | if args.recipe: |
| 41 | tinfoil.prepare(quiet=2) |
| 42 | d = tinfoil.parse_recipe(args.recipe) |
| 43 | else: |
| 44 | tinfoil.prepare(quiet=2, config_only=True) |
| 45 | d = tinfoil.config_data |
| 46 | if args.flag: |
| 47 | print(str(d.getVarFlag(args.variable, args.flag, expand=(not args.unexpand)))) |
| 48 | elif args.value: |
| 49 | print(str(d.getVar(args.variable, expand=(not args.unexpand)))) |
| 50 | else: |
| 51 | bb.data.emit_var(args.variable, d=d, all=True) |