blob: 5435a8d7978c1d1c9fb593ae10d8687e8098a818 [file] [log] [blame]
Andrew Geisslerc926e172021-05-07 16:11:35 -05001#! /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
Andrew Geissler5199d832021-09-24 16:47:35 -050012import warnings
13warnings.simplefilter("default")
Andrew Geisslerc926e172021-05-07 16:11:35 -050014
15bindir = os.path.dirname(__file__)
16topdir = os.path.dirname(bindir)
17sys.path[0:0] = [os.path.join(topdir, 'lib')]
18
19import bb.tinfoil
20
21if __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")
28 args = parser.parse_args()
29
30 if args.unexpand and not args.value:
31 print("--unexpand only makes sense with --value")
32 sys.exit(1)
33
34 if args.flag and not args.value:
35 print("--flag only makes sense with --value")
36 sys.exit(1)
37
38 with bb.tinfoil.Tinfoil(tracking=True) as tinfoil:
39 if args.recipe:
40 tinfoil.prepare(quiet=2)
41 d = tinfoil.parse_recipe(args.recipe)
42 else:
43 tinfoil.prepare(quiet=2, config_only=True)
44 d = tinfoil.config_data
45 if args.flag:
46 print(str(d.getVarFlag(args.variable, args.flag, expand=(not args.unexpand))))
47 elif args.value:
48 print(str(d.getVar(args.variable, expand=(not args.unexpand))))
49 else:
50 bb.data.emit_var(args.variable, d=d, all=True)