diff options
| author | Chris Laplante <chris.laplante@agilent.com> | 2025-01-12 09:53:55 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-01-20 13:38:59 +0000 |
| commit | d466af6e92ee67e85c4d932e49f372e21a16bcab (patch) | |
| tree | ffc7e9691beb38bd1c350b1f453b2e2d86358413 /scripts/devtool | |
| parent | bc2403dcdbeaef0abc52d0c24a9f3e849fd34ab8 (diff) | |
| download | poky-d466af6e92ee67e85c4d932e49f372e21a16bcab.tar.gz | |
devtool: un-globalize 'context' variable and convert it to a dataclass
Please excuse the usage of 'typing' slipping in here - it's just how
dataclasses work :/.
(From OE-Core rev: 207cdead039383780bd39adbaf2a17b679889c63)
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/devtool')
| -rwxr-xr-x | scripts/devtool | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/scripts/devtool b/scripts/devtool index d7a5903c9f..750365c1c9 100755 --- a/scripts/devtool +++ b/scripts/devtool | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | # SPDX-License-Identifier: GPL-2.0-only | 7 | # SPDX-License-Identifier: GPL-2.0-only |
| 8 | # | 8 | # |
| 9 | 9 | ||
| 10 | import dataclasses | ||
| 10 | import sys | 11 | import sys |
| 11 | import os | 12 | import os |
| 12 | import argparse | 13 | import argparse |
| @@ -15,8 +16,10 @@ import re | |||
| 15 | import configparser | 16 | import configparser |
| 16 | import logging | 17 | import logging |
| 17 | 18 | ||
| 19 | # This can be removed once our minimum is Python 3.9: https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections | ||
| 20 | from typing import List | ||
| 21 | |||
| 18 | config = None | 22 | config = None |
| 19 | context = None | ||
| 20 | 23 | ||
| 21 | 24 | ||
| 22 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | 25 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
| @@ -80,12 +83,15 @@ class ConfigHandler: | |||
| 80 | self.config_obj.add_section(section) | 83 | self.config_obj.add_section(section) |
| 81 | self.config_obj.set(section, option, value) | 84 | self.config_obj.set(section, option, value) |
| 82 | 85 | ||
| 86 | |||
| 87 | @dataclasses.dataclass | ||
| 83 | class Context: | 88 | class Context: |
| 84 | def __init__(self, **kwargs): | 89 | fixed_setup: bool |
| 85 | self.__dict__.update(kwargs) | 90 | config: ConfigHandler |
| 91 | pluginpaths: List[str] | ||
| 86 | 92 | ||
| 87 | 93 | ||
| 88 | def read_workspace(basepath): | 94 | def read_workspace(basepath, context): |
| 89 | workspace = {} | 95 | workspace = {} |
| 90 | if not os.path.exists(os.path.join(config.workspace_path, 'conf', 'layer.conf')): | 96 | if not os.path.exists(os.path.join(config.workspace_path, 'conf', 'layer.conf')): |
| 91 | if context.fixed_setup: | 97 | if context.fixed_setup: |
| @@ -210,13 +216,10 @@ def _enable_workspace_layer(workspacedir, config, basepath): | |||
| 210 | 216 | ||
| 211 | def main(): | 217 | def main(): |
| 212 | global config | 218 | global config |
| 213 | global context | ||
| 214 | 219 | ||
| 215 | if sys.getfilesystemencoding() != "utf-8": | 220 | if sys.getfilesystemencoding() != "utf-8": |
| 216 | sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") | 221 | sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") |
| 217 | 222 | ||
| 218 | context = Context(fixed_setup=False) | ||
| 219 | |||
| 220 | # Default basepath | 223 | # Default basepath |
| 221 | basepath = os.path.dirname(os.path.abspath(__file__)) | 224 | basepath = os.path.dirname(os.path.abspath(__file__)) |
| 222 | 225 | ||
| @@ -241,21 +244,23 @@ def main(): | |||
| 241 | elif global_args.quiet: | 244 | elif global_args.quiet: |
| 242 | logger.setLevel(logging.ERROR) | 245 | logger.setLevel(logging.ERROR) |
| 243 | 246 | ||
| 247 | is_fixed_setup = False | ||
| 248 | |||
| 244 | if global_args.basepath: | 249 | if global_args.basepath: |
| 245 | # Override | 250 | # Override |
| 246 | basepath = global_args.basepath | 251 | basepath = global_args.basepath |
| 247 | if os.path.exists(os.path.join(basepath, '.devtoolbase')): | 252 | if os.path.exists(os.path.join(basepath, '.devtoolbase')): |
| 248 | context.fixed_setup = True | 253 | is_fixed_setup = True |
| 249 | else: | 254 | else: |
| 250 | pth = basepath | 255 | pth = basepath |
| 251 | while pth != '' and pth != os.sep: | 256 | while pth != '' and pth != os.sep: |
| 252 | if os.path.exists(os.path.join(pth, '.devtoolbase')): | 257 | if os.path.exists(os.path.join(pth, '.devtoolbase')): |
| 253 | context.fixed_setup = True | 258 | is_fixed_setup = True |
| 254 | basepath = pth | 259 | basepath = pth |
| 255 | break | 260 | break |
| 256 | pth = os.path.dirname(pth) | 261 | pth = os.path.dirname(pth) |
| 257 | 262 | ||
| 258 | if not context.fixed_setup: | 263 | if not is_fixed_setup: |
| 259 | basepath = os.environ.get('BUILDDIR') | 264 | basepath = os.environ.get('BUILDDIR') |
| 260 | if not basepath: | 265 | if not basepath: |
| 261 | logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)") | 266 | logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)") |
| @@ -266,7 +271,6 @@ def main(): | |||
| 266 | config = ConfigHandler(basepath, os.path.join(basepath, 'conf', 'devtool.conf')) | 271 | config = ConfigHandler(basepath, os.path.join(basepath, 'conf', 'devtool.conf')) |
| 267 | if not config.read(): | 272 | if not config.read(): |
| 268 | return -1 | 273 | return -1 |
| 269 | context.config = config | ||
| 270 | 274 | ||
| 271 | bitbake_subdir = config.get('General', 'bitbake_subdir', '') | 275 | bitbake_subdir = config.get('General', 'bitbake_subdir', '') |
| 272 | if bitbake_subdir: | 276 | if bitbake_subdir: |
| @@ -299,7 +303,9 @@ def main(): | |||
| 299 | 303 | ||
| 300 | # Search BBPATH first to allow layers to override plugins in scripts_path | 304 | # Search BBPATH first to allow layers to override plugins in scripts_path |
| 301 | pluginpaths = [os.path.join(path, 'lib', 'devtool') for path in global_args.bbpath.split(':') + [scripts_path]] | 305 | pluginpaths = [os.path.join(path, 'lib', 'devtool') for path in global_args.bbpath.split(':') + [scripts_path]] |
| 302 | context.pluginpaths = pluginpaths | 306 | |
| 307 | context = Context(fixed_setup=is_fixed_setup, config=config, pluginpaths=pluginpaths) | ||
| 308 | |||
| 303 | for pluginpath in pluginpaths: | 309 | for pluginpath in pluginpaths: |
| 304 | scriptutils.load_plugins(logger, plugins, pluginpath) | 310 | scriptutils.load_plugins(logger, plugins, pluginpath) |
| 305 | 311 | ||
| @@ -332,7 +338,7 @@ def main(): | |||
| 332 | try: | 338 | try: |
| 333 | workspace = {} | 339 | workspace = {} |
| 334 | if not getattr(args, 'no_workspace', False): | 340 | if not getattr(args, 'no_workspace', False): |
| 335 | workspace = read_workspace(basepath) | 341 | workspace = read_workspace(basepath, context) |
| 336 | ret = args.func(args, config, basepath, workspace) | 342 | ret = args.func(args, config, basepath, workspace) |
| 337 | except DevtoolError as err: | 343 | except DevtoolError as err: |
| 338 | if str(err): | 344 | if str(err): |
