diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2023-09-27 19:16:16 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-27 23:34:14 +0100 |
commit | 136b8dda4e8b6f4d7e45a552c2d2e278b3ae1b7d (patch) | |
tree | 50554633cbfb40c1b2f9f1e9f9a0f7f77d5c948a | |
parent | 05c15162de90c41dad67e37a95ec9fdb440a7864 (diff) | |
download | bitbake-contrib-136b8dda4e8b6f4d7e45a552c2d2e278b3ae1b7d.tar.gz |
bitbake-getvar: Add a (suppressable) error for undefined variables
If an undefined variable or variable flag is specified, bitbake-getvar
will now fail with an error message indicating this.
The error can be supressed with --ignore-undefined, which matches the
previous behavior.
This also changes the errors related to specifying --flag or --unexpand
without --value so that they are sent to stderr rather than stdout.
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | bin/bitbake-getvar | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/bin/bitbake-getvar b/bin/bitbake-getvar index afd284984..53ab90069 100755 --- a/bin/bitbake-getvar +++ b/bin/bitbake-getvar @@ -26,15 +26,15 @@ if __name__ == "__main__": parser.add_argument('-f', '--flag', help='Specify a variable flag to query (with --value)', default=None) parser.add_argument('--value', help='Only report the value, no history and no variable name', action="store_true") parser.add_argument('-q', '--quiet', help='Silence bitbake server logging', action="store_true") + parser.add_argument('--ignore-undefined', help='Suppress any errors related to undefined variables', action="store_true") args = parser.parse_args() - if args.unexpand and not args.value: - print("--unexpand only makes sense with --value") - sys.exit(1) + if not args.value: + if args.unexpand: + sys.exit("--unexpand only makes sense with --value") - if args.flag and not args.value: - print("--flag only makes sense with --value") - sys.exit(1) + if args.flag: + sys.exit("--flag only makes sense with --value") quiet = args.quiet or args.value with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not quiet) as tinfoil: @@ -44,9 +44,17 @@ if __name__ == "__main__": else: tinfoil.prepare(quiet=2, config_only=True) d = tinfoil.config_data + + value = None if args.flag: - print(str(d.getVarFlag(args.variable, args.flag, expand=(not args.unexpand)))) - elif args.value: - print(str(d.getVar(args.variable, expand=(not args.unexpand)))) + value = d.getVarFlag(args.variable, args.flag, expand=not args.unexpand) + if value is None and not args.ignore_undefined: + sys.exit(f"The flag '{args.flag}' is not defined for variable '{args.variable}'") + else: + value = d.getVar(args.variable, expand=not args.unexpand) + if value is None and not args.ignore_undefined: + sys.exit(f"The variable '{args.variable}' is not defined") + if args.value: + print(str(value)) else: bb.data.emit_var(args.variable, d=d, all=True) |