Move Config creation out of Context constructor

This helps to avoid circular dependencies. It also allows the Config
constructor to make use of the global context.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2018-08-24 19:17:59 +02:00 committed by Daniel Wagner
parent 594fa97692
commit f5cea27269
3 changed files with 13 additions and 10 deletions

View File

@ -25,6 +25,7 @@
import os import os
from .context import create_global_context from .context import create_global_context
from .config import Config
from .libkas import find_program, run_cmd, kasplugin from .libkas import find_program, run_cmd, kasplugin
from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent, from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent,
SetupSSHAgent, SetupEnviron, SetupRepos, SetupSSHAgent, SetupEnviron, SetupRepos,
@ -71,7 +72,9 @@ class Build:
if args.cmd != 'build': if args.cmd != 'build':
return False return False
ctx = create_global_context(args.config, args.target, args.task) ctx = create_global_context()
ctx.config = Config(args.config, args.target, args.task)
ctx.config.set_context(ctx)
macro = Macro() macro = Macro()

View File

@ -25,7 +25,6 @@
import os import os
import logging import logging
from .config import Config
try: try:
import distro import distro
@ -48,16 +47,17 @@ except ImportError:
# pylint: disable=deprecated-method # pylint: disable=deprecated-method
return platform.dist()[0] return platform.dist()[0]
__context__ = None __context__ = None
def create_global_context(config_filename, bitbake_target, bitbake_task): def create_global_context():
""" """
Create global context as singleton. Create global context as singleton.
""" """
# pylint: disable=global-statement # pylint: disable=global-statement
global __context__ global __context__
__context__ = Context(config_filename, bitbake_target, bitbake_task) __context__ = Context()
return __context__ return __context__
@ -73,15 +73,12 @@ class Context:
""" """
Implements the kas build context. Implements the kas build context.
""" """
def __init__(self, config_filename, bitbake_target, bitbake_task): def __init__(self):
self.__kas_work_dir = os.environ.get('KAS_WORK_DIR', os.getcwd()) self.__kas_work_dir = os.environ.get('KAS_WORK_DIR', os.getcwd())
self.__kas_repo_ref_dir = os.environ.get('KAS_REPO_REF_DIR', None) self.__kas_repo_ref_dir = os.environ.get('KAS_REPO_REF_DIR', None)
self.setup_initial_environ() self.setup_initial_environ()
self.keep_config = False self.keep_config = False
self.config = None
self.config = Config(config_filename, bitbake_target, bitbake_task)
self.config.set_context(self)
def setup_initial_environ(self): def setup_initial_environ(self):
""" """

View File

@ -28,6 +28,7 @@ import subprocess
import os import os
from .libkas import kasplugin from .libkas import kasplugin
from .context import create_global_context from .context import create_global_context
from .config import Config
from .libcmds import (Macro, Command, SetupDir, SetupEnviron, from .libcmds import (Macro, Command, SetupDir, SetupEnviron,
WriteBBConfig, SetupHome, ReposApplyPatches, WriteBBConfig, SetupHome, ReposApplyPatches,
CleanupSSHAgent, SetupSSHAgent, SetupRepos) CleanupSSHAgent, SetupSSHAgent, SetupRepos)
@ -75,7 +76,9 @@ class Shell:
if args.cmd != 'shell': if args.cmd != 'shell':
return False return False
ctx = create_global_context(args.config, args.target, None) ctx = create_global_context()
ctx.config = Config(args.config, args.target, None)
ctx.config.set_context(ctx)
macro = Macro() macro = Macro()