From 6ee67c2402e6f114dbe9bf2e24daa83d6c5d19ce Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Sun, 20 Oct 2024 08:53:14 +0000 Subject: [PATCH] bitbake-listflags: add new script to list all bitbake flags of a variable, potentially including values Signed-off-by: Konrad Weihmann --- README.md | 13 ++++---- docs/scripts-bitbake-listflags.md | 11 +++++++ scripts/bitbake-listflags | 54 +++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 docs/scripts-bitbake-listflags.md create mode 100755 scripts/bitbake-listflags diff --git a/README.md b/README.md index 27b9d55..bb0cd07 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,10 @@ A collection of build utils to be used with YOCTO ## Available scripts -| script | summary | documentation | -| ---------------- | ------------------------------------------------------------------- | --------------------------------------- | -| bitbake-listvars | list all defined bitbake variable | [docu](docs/scripts-bitbakelistvars.md) | -| dot2tree | create filterable trees from recipe info | [docu](docs/scripts-dot2tree.md) | -| newlayercheck | check a layer for possible corruptions/changes of an existing stack | [docu](docs/scripts-newlayercheck.md) | -| unused | identify unused recipes in a layer | [docu](docs/scripts-unused.md) | +| script | summary | documentation | +| ----------------- | ------------------------------------------------------------------- | ---------------------------------------- | +| bitbake-listflags | list all defined flgas of a bitbake variable | [docu](docs/scripts-bitbakelistflags.md) | +| bitbake-listvars | list all defined bitbake variable | [docu](docs/scripts-bitbakelistvars.md) | +| dot2tree | create filterable trees from recipe info | [docu](docs/scripts-dot2tree.md) | +| newlayercheck | check a layer for possible corruptions/changes of an existing stack | [docu](docs/scripts-newlayercheck.md) | +| unused | identify unused recipes in a layer | [docu](docs/scripts-unused.md) | diff --git a/docs/scripts-bitbake-listflags.md b/docs/scripts-bitbake-listflags.md new file mode 100644 index 0000000..61805d6 --- /dev/null +++ b/docs/scripts-bitbake-listflags.md @@ -0,0 +1,11 @@ +# bitbake-listflags + +List all defined variable flags + +## Usage + +From a setup OE/Yocto build + +```shell +/scripts/bitbake-listflags $(which bitbake) +``` diff --git a/scripts/bitbake-listflags b/scripts/bitbake-listflags new file mode 100755 index 0000000..5c4b47b --- /dev/null +++ b/scripts/bitbake-listflags @@ -0,0 +1,54 @@ +#! /usr/bin/env python3 +# Copyright (C) 2021 Richard Purdie +# Copyright (c) 2024, Konrad Weihmann +# SPDX-License-Identifier: GPL-2.0-only + +# Based on bitbake-getvar +# Lists all defined flags of a variable + +import argparse +import os +import sys +import warnings + + +def main(args=None): + parser = argparse.ArgumentParser(description="Bitbake List Flags") + parser.add_argument( + '-q', '--quiet', help='Silence bitbake server logging', action="store_true") + parser.add_argument('-v', '--value', action='store_true', + help='Print with value') + parser.add_argument('bitbake', help='Path to bitbake binary') + parser.add_argument('var', help='Variable to poll for') + args = parser.parse_args() + + bindir = os.path.dirname(args.bitbake) + topdir = os.path.dirname(bindir) + sys.path[0:0] = [os.path.join(topdir, 'lib')] + + import bb.tinfoil + + quiet = args.quiet + with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not quiet) as tinfoil: + tinfoil.prepare(quiet=2, config_only=True) + d = tinfoil.config_data + + for k, v in d.getVarFlags(args.var).items(): + if ':' in k: + continue + if k.startswith('_'): + continue + if args.value: + yield (k, v) + else: + yield k + + +if __name__ == "__main__": + warnings.simplefilter("default") + result = main() + for item in result: + if isinstance(item, tuple): + print(f'{item[0]}:{item[1]}') + else: + print(item)