macros: Use new macro loop for repo setup

Divide the SetupRepos command into three parts: init, step and finish
Build a macro-based loop with the step part of the function.

Rewrite this in build.py and shell.py

Signed-off-by: Andreas Reichel <andreas.reichel.ext@siemens.com>
This commit is contained in:
Andreas Reichel 2018-09-05 11:13:01 +02:00 committed by Daniel Wagner
parent fc9ebf1104
commit 6349f7ab73
3 changed files with 71 additions and 29 deletions

View File

@ -31,8 +31,10 @@ from .context import create_global_context
from .config import Config
from .libkas import find_program, run_cmd, kasplugin
from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent,
SetupSSHAgent, SetupEnviron, SetupRepos,
WriteBBConfig, SetupHome, ReposApplyPatches)
SetupSSHAgent, SetupEnviron,
WriteBBConfig, SetupHome, ReposApplyPatches,
Loop, InitSetupRepos, FinishSetupRepos,
SetupReposStep)
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017'
@ -86,7 +88,14 @@ class Build:
if 'SSH_PRIVATE_KEY' in os.environ:
macro.add(SetupSSHAgent())
macro.add(SetupRepos())
macro.add(InitSetupRepos())
repo_loop = Loop('repo_setup_loop')
repo_loop.add(SetupReposStep())
macro.add(repo_loop)
macro.add(FinishSetupRepos())
macro.add(SetupEnviron())
macro.add(SetupHome())
macro.add(ReposApplyPatches())

View File

@ -257,50 +257,74 @@ class ReposCheckout(Command):
repo.checkout()
class SetupRepos(Command):
class InitSetupRepos(Command):
"""
Setup repos including the include logic
"""
def __str__(self):
return 'setup_repos'
return 'init_setup_repos'
def execute(self, ctx):
missing_repo_names = ctx.config.find_missing_repos()
missing_repo_names_old = None
ctx.missing_repo_names = ctx.config.find_missing_repos()
ctx.missing_repo_names_old = None
# pylint: disable=pointless-string-statement
"""XXX This will be refactored"""
class SetupReposStep(Command):
"""
Single step of the checkout repos loop
"""
def __str__(self):
return 'setup_repos_step'
def execute(self, ctx):
""" TODO refactor protected-access """
# pylint: disable=protected-access
if not ctx.missing_repo_names:
return False
while missing_repo_names:
if missing_repo_names == missing_repo_names_old:
raise IncludeException('Could not fetch all repos needed by '
'includes.')
if ctx.missing_repo_names == ctx.missing_repo_names_old:
raise IncludeException('Could not fetch all repos needed by '
'includes.')
logging.debug('Missing repos for complete config:\n%s',
pprint.pformat(missing_repo_names))
logging.debug('Missing repos for complete config:\n%s',
pprint.pformat(ctx.missing_repo_names))
ctx.config.repo_dict = ctx.config._get_repo_dict()
ctx.config.repo_dict = ctx.config._get_repo_dict()
missing_repos = [ctx.config.repo_dict[repo_name]
for repo_name in missing_repo_names
ctx.missing_repos = [ctx.config.repo_dict[repo_name]
for repo_name in ctx.missing_repo_names
if repo_name in ctx.config.repo_dict]
repos_fetch(missing_repos)
repos_fetch(ctx.missing_repos)
for repo in missing_repos:
repo.checkout()
for repo in ctx.missing_repos:
repo.checkout()
ctx.config.repo_dict = ctx.config._get_repo_dict()
ctx.config.repo_dict = ctx.config._get_repo_dict()
repo_paths = {r: ctx.config.repo_dict[r].path for r
in ctx.config.repo_dict}
missing_repo_names_old = missing_repo_names
repo_paths = {r: ctx.config.repo_dict[r].path for r
in ctx.config.repo_dict}
ctx.missing_repo_names_old = ctx.missing_repo_names
(ctx.config._config, missing_repo_names) = \
ctx.config.handler.get_config(repos=repo_paths)
(ctx.config._config, ctx.missing_repo_names) = \
ctx.config.handler.get_config(repos=repo_paths)
return ctx.missing_repo_names
class FinishSetupRepos(Command):
"""
Command to finalize the repo setup loop
"""
def __str__(self):
return 'finish_setup_repos'
def execute(self, ctx):
""" TODO refactor protected-access """
# pylint: disable=protected-access
# now fetch everything with complete config and check out layers
# except if keep_config is set
if not ctx.keep_config:

View File

@ -31,7 +31,9 @@ from .context import create_global_context
from .config import Config
from .libcmds import (Macro, Command, SetupDir, SetupEnviron,
WriteBBConfig, SetupHome, ReposApplyPatches,
CleanupSSHAgent, SetupSSHAgent, SetupRepos)
CleanupSSHAgent, SetupSSHAgent,
Loop, InitSetupRepos, FinishSetupRepos,
SetupReposStep)
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017'
@ -89,7 +91,14 @@ class Shell:
macro.add(SetupSSHAgent())
ctx.keep_config = args.keep_config_unchanged
macro.add(SetupRepos())
macro.add(InitSetupRepos())
repo_loop = Loop('repo_setup_loop')
repo_loop.add(SetupReposStep())
macro.add(repo_loop)
macro.add(FinishSetupRepos())
macro.add(SetupEnviron())
macro.add(SetupHome())