| Message ID | 20260213-improve-bbsetup-readability-v1-1-41cec3b06992@bootlin.com |
|---|---|
| State | New |
| Headers | show |
| Series | bitbake-setup: Improve readability | expand |
On Fri, 13 Feb 2026 at 14:50, Antonin Godard via lists.openembedded.org <antonin.godard=bootlin.com@lists.openembedded.org> wrote: > + global BBSETUP_COLOR > + if args.color == 'always' or (args.color == 'auto' and sys.stdout.isatty() and os.environ.get('NO_COLOR', '') == ''): > + BBSETUP_COLOR = True > + Global variables are evil. They easily enable unwanted side effects, when a function call doesn't just 'return something', it also changes the global program state, which makes it harder to reason about program behavior, especially when the program is multi-threaded. Which is to say, can you change this into a function please? Alex
diff --git a/bin/bitbake-setup b/bin/bitbake-setup index 927c03a1033..547d3f36bff 100755 --- a/bin/bitbake-setup +++ b/bin/bitbake-setup @@ -29,6 +29,8 @@ import bb.process logger = bb.msg.logger_create('bitbake-setup', sys.stdout) +BBSETUP_COLOR = False + # These settings can only be set in the global context GLOBAL_ONLY_SETTINGS = ( "top-dir-prefix", @@ -1095,6 +1097,10 @@ def main(): elif args.quiet: logger.setLevel(logging.ERROR) + global BBSETUP_COLOR + if args.color == 'always' or (args.color == 'auto' and sys.stdout.isatty() and os.environ.get('NO_COLOR', '') == ''): + BBSETUP_COLOR = True + # Need to re-run logger_create with color argument # (will be the same logger since it has the same name) bb.msg.logger_create('bitbake-setup', output=sys.stdout,
Define a BBSETUP_COLOR global variable that holds the color choice optionally passed from the command-line. This will be re-used in the next commits to force subprocess commands to color their outputs, as passing --color=auto in them always render without coloring. Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> --- bin/bitbake-setup | 6 ++++++ 1 file changed, 6 insertions(+)