diff options
Diffstat (limited to 'bitbake/bin/bitbake-getvar')
-rwxr-xr-x | bitbake/bin/bitbake-getvar | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake-getvar b/bitbake/bin/bitbake-getvar new file mode 100755 index 0000000000..378fb13572 --- /dev/null +++ b/bitbake/bin/bitbake-getvar | |||
@@ -0,0 +1,71 @@ | |||
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 | ||
12 | import warnings | ||
13 | import logging | ||
14 | warnings.simplefilter("default") | ||
15 | |||
16 | bindir = os.path.dirname(__file__) | ||
17 | topdir = os.path.dirname(bindir) | ||
18 | sys.path[0:0] = [os.path.join(topdir, 'lib')] | ||
19 | |||
20 | import bb.providers | ||
21 | import bb.tinfoil | ||
22 | |||
23 | if __name__ == "__main__": | ||
24 | parser = argparse.ArgumentParser(description="Bitbake Query Variable") | ||
25 | parser.add_argument("variable", help="variable name to query") | ||
26 | parser.add_argument("-r", "--recipe", help="Recipe name to query", default=None, required=False) | ||
27 | parser.add_argument('-u', '--unexpand', help='Do not expand the value (with --value)', action="store_true") | ||
28 | parser.add_argument('-f', '--flag', help='Specify a variable flag to query (with --value)', default=None) | ||
29 | parser.add_argument('--value', help='Only report the value, no history and no variable name', action="store_true") | ||
30 | parser.add_argument('-q', '--quiet', help='Silence bitbake server logging', action="store_true") | ||
31 | parser.add_argument('--ignore-undefined', help='Suppress any errors related to undefined variables', action="store_true") | ||
32 | args = parser.parse_args() | ||
33 | |||
34 | if not args.value: | ||
35 | if args.unexpand: | ||
36 | sys.exit("--unexpand only makes sense with --value") | ||
37 | |||
38 | if args.flag: | ||
39 | sys.exit("--flag only makes sense with --value") | ||
40 | |||
41 | quiet = args.quiet or args.value | ||
42 | if quiet: | ||
43 | logger = logging.getLogger("BitBake") | ||
44 | logger.setLevel(logging.WARNING) | ||
45 | |||
46 | with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not quiet) as tinfoil: | ||
47 | if args.recipe: | ||
48 | tinfoil.prepare(quiet=3 if quiet else 2) | ||
49 | try: | ||
50 | d = tinfoil.parse_recipe(args.recipe) | ||
51 | except bb.providers.NoProvider as e: | ||
52 | sys.exit(str(e)) | ||
53 | else: | ||
54 | tinfoil.prepare(quiet=2, config_only=True) | ||
55 | # Expand keys and run anonymous functions to get identical result to | ||
56 | # "bitbake -e" | ||
57 | d = tinfoil.finalizeData() | ||
58 | |||
59 | value = None | ||
60 | if args.flag: | ||
61 | value = d.getVarFlag(args.variable, args.flag, expand=not args.unexpand) | ||
62 | if value is None and not args.ignore_undefined: | ||
63 | sys.exit(f"The flag '{args.flag}' is not defined for variable '{args.variable}'") | ||
64 | else: | ||
65 | value = d.getVar(args.variable, expand=not args.unexpand) | ||
66 | if value is None and not args.ignore_undefined: | ||
67 | sys.exit(f"The variable '{args.variable}' is not defined") | ||
68 | if args.value: | ||
69 | print(str(value if value is not None else "")) | ||
70 | else: | ||
71 | bb.data.emit_var(args.variable, d=d, all=True) | ||