summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-04-16 18:05:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-06-26 12:14:22 +0100
commit9f20f682ffd27827a91c5d36c65676dfc23a0770 (patch)
treeecae882b299aa46bb22322976ad86aa9eaf06d92 /bitbake
parent6d1f8412becc907af7741ab547d233a10d66ee14 (diff)
downloadpoky-9f20f682ffd27827a91c5d36c65676dfc23a0770.tar.gz
bitbake: bin/bitbake-getvar: Add a new command to query a variable value (with history)
We've talked about having this for long enough. Add a command which queries a single variable value with history. This saves "bitbake -e | grep" and avoids the various pitfalls that has. It also provides a neat example of using tinfoil to make such a query. Parameters to limit the output to just the value, to limit to a variable flag and to not expand the output are provided. [YOCTO #10748] (Bitbake rev: 47ed06d441152f8b6d374cacfac2c668c354423e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 4c1881b620e885f55d7772f8626b8a76c2828333) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rwxr-xr-xbitbake/bin/bitbake-getvar48
1 files changed, 48 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake-getvar b/bitbake/bin/bitbake-getvar
new file mode 100755
index 0000000000..9423219253
--- /dev/null
+++ b/bitbake/bin/bitbake-getvar
@@ -0,0 +1,48 @@
1#! /usr/bin/env python3
2#
3# Copyright (C) 2021 Richard Purdie
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7
8import argparse
9import io
10import os
11import sys
12
13bindir = os.path.dirname(__file__)
14topdir = os.path.dirname(bindir)
15sys.path[0:0] = [os.path.join(topdir, 'lib')]
16
17import bb.tinfoil
18
19if __name__ == "__main__":
20 parser = argparse.ArgumentParser(description="Bitbake Query Variable")
21 parser.add_argument("variable", help="variable name to query")
22 parser.add_argument("-r", "--recipe", help="Recipe name to query", default=None, required=False)
23 parser.add_argument('-u', '--unexpand', help='Do not expand the value (with --value)', action="store_true")
24 parser.add_argument('-f', '--flag', help='Specify a variable flag to query (with --value)', default=None)
25 parser.add_argument('--value', help='Only report the value, no history and no variable name', action="store_true")
26 args = parser.parse_args()
27
28 if args.unexpand and not args.value:
29 print("--unexpand only makes sense with --value")
30 sys.exit(1)
31
32 if args.flag and not args.value:
33 print("--flag only makes sense with --value")
34 sys.exit(1)
35
36 with bb.tinfoil.Tinfoil(tracking=True) as tinfoil:
37 if args.recipe:
38 tinfoil.prepare(quiet=2)
39 d = tinfoil.parse_recipe(args.recipe)
40 else:
41 tinfoil.prepare(quiet=2, config_only=True)
42 d = tinfoil.config_data
43 if args.flag:
44 print(str(d.getVarFlag(args.variable, args.flag, expand=(not args.unexpand))))
45 elif args.value:
46 print(str(d.getVar(args.variable, expand=(not args.unexpand))))
47 else:
48 bb.data.emit_var(args.variable, d=d, all=True)