mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 21:09:03 +02:00
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>
This commit is contained in:
parent
bc2403dcdb
commit
d466af6e92
|
@ -7,6 +7,7 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0-only
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import dataclasses
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -15,8 +16,10 @@ import re
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
# 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
|
||||||
|
from typing import List
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
context = None
|
|
||||||
|
|
||||||
|
|
||||||
scripts_path = os.path.dirname(os.path.realpath(__file__))
|
scripts_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -80,12 +83,15 @@ class ConfigHandler:
|
||||||
self.config_obj.add_section(section)
|
self.config_obj.add_section(section)
|
||||||
self.config_obj.set(section, option, value)
|
self.config_obj.set(section, option, value)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
class Context:
|
class Context:
|
||||||
def __init__(self, **kwargs):
|
fixed_setup: bool
|
||||||
self.__dict__.update(kwargs)
|
config: ConfigHandler
|
||||||
|
pluginpaths: List[str]
|
||||||
|
|
||||||
|
|
||||||
def read_workspace(basepath):
|
def read_workspace(basepath, context):
|
||||||
workspace = {}
|
workspace = {}
|
||||||
if not os.path.exists(os.path.join(config.workspace_path, 'conf', 'layer.conf')):
|
if not os.path.exists(os.path.join(config.workspace_path, 'conf', 'layer.conf')):
|
||||||
if context.fixed_setup:
|
if context.fixed_setup:
|
||||||
|
@ -210,13 +216,10 @@ def _enable_workspace_layer(workspacedir, config, basepath):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global config
|
global config
|
||||||
global context
|
|
||||||
|
|
||||||
if sys.getfilesystemencoding() != "utf-8":
|
if sys.getfilesystemencoding() != "utf-8":
|
||||||
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.")
|
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.")
|
||||||
|
|
||||||
context = Context(fixed_setup=False)
|
|
||||||
|
|
||||||
# Default basepath
|
# Default basepath
|
||||||
basepath = os.path.dirname(os.path.abspath(__file__))
|
basepath = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
@ -241,21 +244,23 @@ def main():
|
||||||
elif global_args.quiet:
|
elif global_args.quiet:
|
||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
|
is_fixed_setup = False
|
||||||
|
|
||||||
if global_args.basepath:
|
if global_args.basepath:
|
||||||
# Override
|
# Override
|
||||||
basepath = global_args.basepath
|
basepath = global_args.basepath
|
||||||
if os.path.exists(os.path.join(basepath, '.devtoolbase')):
|
if os.path.exists(os.path.join(basepath, '.devtoolbase')):
|
||||||
context.fixed_setup = True
|
is_fixed_setup = True
|
||||||
else:
|
else:
|
||||||
pth = basepath
|
pth = basepath
|
||||||
while pth != '' and pth != os.sep:
|
while pth != '' and pth != os.sep:
|
||||||
if os.path.exists(os.path.join(pth, '.devtoolbase')):
|
if os.path.exists(os.path.join(pth, '.devtoolbase')):
|
||||||
context.fixed_setup = True
|
is_fixed_setup = True
|
||||||
basepath = pth
|
basepath = pth
|
||||||
break
|
break
|
||||||
pth = os.path.dirname(pth)
|
pth = os.path.dirname(pth)
|
||||||
|
|
||||||
if not context.fixed_setup:
|
if not is_fixed_setup:
|
||||||
basepath = os.environ.get('BUILDDIR')
|
basepath = os.environ.get('BUILDDIR')
|
||||||
if not basepath:
|
if not basepath:
|
||||||
logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
|
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():
|
||||||
config = ConfigHandler(basepath, os.path.join(basepath, 'conf', 'devtool.conf'))
|
config = ConfigHandler(basepath, os.path.join(basepath, 'conf', 'devtool.conf'))
|
||||||
if not config.read():
|
if not config.read():
|
||||||
return -1
|
return -1
|
||||||
context.config = config
|
|
||||||
|
|
||||||
bitbake_subdir = config.get('General', 'bitbake_subdir', '')
|
bitbake_subdir = config.get('General', 'bitbake_subdir', '')
|
||||||
if bitbake_subdir:
|
if bitbake_subdir:
|
||||||
|
@ -299,7 +303,9 @@ def main():
|
||||||
|
|
||||||
# Search BBPATH first to allow layers to override plugins in scripts_path
|
# Search BBPATH first to allow layers to override plugins in scripts_path
|
||||||
pluginpaths = [os.path.join(path, 'lib', 'devtool') for path in global_args.bbpath.split(':') + [scripts_path]]
|
pluginpaths = [os.path.join(path, 'lib', 'devtool') for path in global_args.bbpath.split(':') + [scripts_path]]
|
||||||
context.pluginpaths = pluginpaths
|
|
||||||
|
context = Context(fixed_setup=is_fixed_setup, config=config, pluginpaths=pluginpaths)
|
||||||
|
|
||||||
for pluginpath in pluginpaths:
|
for pluginpath in pluginpaths:
|
||||||
scriptutils.load_plugins(logger, plugins, pluginpath)
|
scriptutils.load_plugins(logger, plugins, pluginpath)
|
||||||
|
|
||||||
|
@ -332,7 +338,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
workspace = {}
|
workspace = {}
|
||||||
if not getattr(args, 'no_workspace', False):
|
if not getattr(args, 'no_workspace', False):
|
||||||
workspace = read_workspace(basepath)
|
workspace = read_workspace(basepath, context)
|
||||||
ret = args.func(args, config, basepath, workspace)
|
ret = args.func(args, config, basepath, workspace)
|
||||||
except DevtoolError as err:
|
except DevtoolError as err:
|
||||||
if str(err):
|
if str(err):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user