summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/devtool32
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
10import dataclasses
10import sys 11import sys
11import os 12import os
12import argparse 13import argparse
@@ -15,8 +16,10 @@ import re
15import configparser 16import configparser
16import logging 17import 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
20from typing import List
21
18config = None 22config = None
19context = None
20 23
21 24
22scripts_path = os.path.dirname(os.path.realpath(__file__)) 25scripts_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
83class Context: 88class 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
88def read_workspace(basepath): 94def 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
211def main(): 217def 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):