Skip to content

Commit

Permalink
bitbake-listvars: add script
Browse files Browse the repository at this point in the history
which is a derived version of bitbake-getvar to
list all defined variables (optionally incuding the
paths where the variable is defined/touched)

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Oct 13, 2024
1 parent c851ab1 commit 8b367e0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ A collection of build utils to be used with YOCTO

## Available scripts

| script | summary | documentation |
| ------------- | ------------------------------------------------------------------- | ------------------------------------- |
| 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-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) |
11 changes: 11 additions & 0 deletions docs/scripts-bitbake-listvars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# bitbake-listvars

List all defined variables

## Usage

From a setup OE/Yocto build

```shell
<path to checkout>/scripts/bitbake-listvars
```
55 changes: 55 additions & 0 deletions scripts/bitbake-listvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /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 bitbake variables

import bb.tinfoil
import argparse
import os
import sys
import warnings


def main(args=None):
parser = argparse.ArgumentParser(description="Bitbake List Vars")
parser.add_argument(
'-q', '--quiet', help='Silence bitbake server logging', action="store_true")
parser.add_argument(
'-p', '--path', help='List the path(s) that define the variable', action="store_true")
args = parser.parse_args()

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 in sorted(d.keys()):
if ':' in k:
continue
if k.upper() != k:
continue
if k.startswith('_'):
continue
if args.path:
_paths = {x['file'] for x in d.varhistory.variable(k)}
yield (k, sorted(_paths))
else:
yield k


if __name__ == "__main__":
warnings.simplefilter("default")

bindir = os.path.dirname(__file__)
topdir = os.path.dirname(bindir)
sys.path[0:0] = [os.path.join(topdir, 'lib')]

result = main()
for item in result:
if isinstance(item, tuple):
print(f'{item[0]}:{",".join(item[1])}')
else:
print(item)

0 comments on commit 8b367e0

Please sign in to comment.