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:
parent
fc9ebf1104
commit
6349f7ab73
15
kas/build.py
15
kas/build.py
@ -31,8 +31,10 @@ from .context import create_global_context
|
|||||||
from .config import Config
|
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,
|
||||||
WriteBBConfig, SetupHome, ReposApplyPatches)
|
WriteBBConfig, SetupHome, ReposApplyPatches,
|
||||||
|
Loop, InitSetupRepos, FinishSetupRepos,
|
||||||
|
SetupReposStep)
|
||||||
|
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
||||||
@ -86,7 +88,14 @@ class Build:
|
|||||||
if 'SSH_PRIVATE_KEY' in os.environ:
|
if 'SSH_PRIVATE_KEY' in os.environ:
|
||||||
macro.add(SetupSSHAgent())
|
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(SetupEnviron())
|
||||||
macro.add(SetupHome())
|
macro.add(SetupHome())
|
||||||
macro.add(ReposApplyPatches())
|
macro.add(ReposApplyPatches())
|
||||||
|
@ -257,50 +257,74 @@ class ReposCheckout(Command):
|
|||||||
repo.checkout()
|
repo.checkout()
|
||||||
|
|
||||||
|
|
||||||
class SetupRepos(Command):
|
class InitSetupRepos(Command):
|
||||||
"""
|
"""
|
||||||
Setup repos including the include logic
|
Setup repos including the include logic
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'setup_repos'
|
return 'init_setup_repos'
|
||||||
|
|
||||||
def execute(self, ctx):
|
def execute(self, ctx):
|
||||||
missing_repo_names = ctx.config.find_missing_repos()
|
ctx.missing_repo_names = ctx.config.find_missing_repos()
|
||||||
missing_repo_names_old = None
|
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
|
# pylint: disable=protected-access
|
||||||
|
if not ctx.missing_repo_names:
|
||||||
|
return False
|
||||||
|
|
||||||
while missing_repo_names:
|
if ctx.missing_repo_names == ctx.missing_repo_names_old:
|
||||||
if missing_repo_names == missing_repo_names_old:
|
raise IncludeException('Could not fetch all repos needed by '
|
||||||
raise IncludeException('Could not fetch all repos needed by '
|
'includes.')
|
||||||
'includes.')
|
|
||||||
|
|
||||||
logging.debug('Missing repos for complete config:\n%s',
|
logging.debug('Missing repos for complete config:\n%s',
|
||||||
pprint.pformat(missing_repo_names))
|
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]
|
ctx.missing_repos = [ctx.config.repo_dict[repo_name]
|
||||||
for repo_name in missing_repo_names
|
for repo_name in ctx.missing_repo_names
|
||||||
if repo_name in ctx.config.repo_dict]
|
if repo_name in ctx.config.repo_dict]
|
||||||
|
|
||||||
repos_fetch(missing_repos)
|
repos_fetch(ctx.missing_repos)
|
||||||
|
|
||||||
for repo in missing_repos:
|
for repo in ctx.missing_repos:
|
||||||
repo.checkout()
|
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
|
repo_paths = {r: ctx.config.repo_dict[r].path for r
|
||||||
in ctx.config.repo_dict}
|
in ctx.config.repo_dict}
|
||||||
missing_repo_names_old = missing_repo_names
|
ctx.missing_repo_names_old = ctx.missing_repo_names
|
||||||
|
|
||||||
(ctx.config._config, missing_repo_names) = \
|
(ctx.config._config, ctx.missing_repo_names) = \
|
||||||
ctx.config.handler.get_config(repos=repo_paths)
|
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
|
# now fetch everything with complete config and check out layers
|
||||||
# except if keep_config is set
|
# except if keep_config is set
|
||||||
if not ctx.keep_config:
|
if not ctx.keep_config:
|
||||||
|
13
kas/shell.py
13
kas/shell.py
@ -31,7 +31,9 @@ from .context import create_global_context
|
|||||||
from .config import Config
|
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,
|
||||||
|
Loop, InitSetupRepos, FinishSetupRepos,
|
||||||
|
SetupReposStep)
|
||||||
|
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
||||||
@ -89,7 +91,14 @@ class Shell:
|
|||||||
macro.add(SetupSSHAgent())
|
macro.add(SetupSSHAgent())
|
||||||
|
|
||||||
ctx.keep_config = args.keep_config_unchanged
|
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(SetupEnviron())
|
||||||
macro.add(SetupHome())
|
macro.add(SetupHome())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user