Refactor repo checkout

If a kas-file inside a repo includes another kas-file form a repo
which is not checked-out, and this 2nd repo can only be checked-out
with an SSH-key, kas fails. This is, because the constructor of
the Config class used to fetch missing repos already before the
SSH-Agent was setup.

This patch refactors the way in which kas checks-out repositories. This
also required the Config class to be split into Context and Config,
where the new Context is the build-Context, i.e. containing the
environment of commands executed by kas and the new Config is the Config
of kas itself, i.e. containing the repo dictionary.

This way it is possible to initialize the context needed for SSH setup
independently of the kas configuration.

The commands ReposFetch and ReposCheckout are refactored into a
SetupRepos command. This command parses the include files and
successively checks-out needed repos and updates the config as long
as repos are missing. The logic is taken directly from the constructor
of the former Config class (with minor adaptations).

Further refactoring will be needed to clean up the conceptual
programming patterns (i.e. to keep the Macro-Style consistent),
and to re-add the macro pattern regarding the above ReposFetch.

Signed-off-by: Andreas Reichel <andreas.reichel.ext@siemens.com>
This commit is contained in:
Andreas Reichel
2018-08-13 14:11:22 +02:00
committed by Daniel Wagner
parent 3bada55d30
commit 7b18e5ec3b
7 changed files with 258 additions and 197 deletions

View File

@@ -24,12 +24,11 @@
"""
import os
from .config import Config
from .context import Context
from .libkas import find_program, run_cmd, kasplugin
from .libcmds import (Macro, Command, SetupDir, SetupProxy,
CleanupSSHAgent, SetupSSHAgent, SetupEnviron,
WriteConfig, SetupHome, ReposFetch,
ReposApplyPatches, ReposCheckout)
from .libcmds import (Macro, Command, SetupDir, CleanupSSHAgent,
SetupSSHAgent, SetupEnviron, SetupRepos,
WriteBBConfig, SetupHome, ReposApplyPatches)
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017'
@@ -72,24 +71,22 @@ class Build:
if args.cmd != 'build':
return False
cfg = Config(args.config, args.target, args.task)
ctx = Context(args.config, args.target, args.task)
macro = Macro()
# Prepare
macro.add(SetupDir())
macro.add(SetupProxy())
if 'SSH_PRIVATE_KEY' in os.environ:
macro.add(SetupSSHAgent())
macro.add(ReposFetch())
macro.add(ReposCheckout())
macro.add(SetupRepos())
macro.add(SetupEnviron())
macro.add(SetupHome())
macro.add(ReposApplyPatches())
macro.add(WriteConfig())
macro.add(WriteBBConfig())
# Build
macro.add(BuildCommand(args.task))
@@ -97,7 +94,7 @@ class Build:
if 'SSH_PRIVATE_KEY' in os.environ:
macro.add(CleanupSSHAgent())
macro.run(cfg, args.skip)
macro.run(ctx, args.skip)
return True
@@ -114,12 +111,12 @@ class BuildCommand(Command):
def __str__(self):
return 'build'
def execute(self, config):
def execute(self, ctx):
"""
Executes the bitbake build command.
"""
# Start bitbake build of image
bitbake = find_program(config.environ['PATH'], 'bitbake')
run_cmd(([bitbake, '-k', '-c', config.get_bitbake_task()]
+ config.get_bitbake_targets()),
env=config.environ, cwd=config.build_dir)
bitbake = find_program(ctx.environ['PATH'], 'bitbake')
run_cmd(([bitbake, '-k', '-c', ctx.config.get_bitbake_task()]
+ ctx.config.get_bitbake_targets()),
env=ctx.environ, cwd=ctx.build_dir)