Allow to define task in config and environment
Based on original patch by Sascha Weisenberger. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
		
				
					committed by
					
						
						Daniel Wagner
					
				
			
			
				
	
			
			
			
						parent
						
							d06bdc4781
						
					
				
				
					commit
					13a87cb8c7
				
			@@ -74,6 +74,7 @@ Environment variables
 | 
				
			|||||||
| ``KAS_DISTRO``        | This overwrites the respective setting in the       |
 | 
					| ``KAS_DISTRO``        | This overwrites the respective setting in the       |
 | 
				
			||||||
| ``KAS_MACHINE``       | configuration file.                                 |
 | 
					| ``KAS_MACHINE``       | configuration file.                                 |
 | 
				
			||||||
| ``KAS_TARGET``        |                                                     |
 | 
					| ``KAS_TARGET``        |                                                     |
 | 
				
			||||||
 | 
					| ``KAS_TASK``          |                                                     |
 | 
				
			||||||
+-----------------------+-----------------------------------------------------+
 | 
					+-----------------------+-----------------------------------------------------+
 | 
				
			||||||
| ``SSH_PRIVATE_KEY``   | Path to the private key file that should be added   |
 | 
					| ``SSH_PRIVATE_KEY``   | Path to the private key file that should be added   |
 | 
				
			||||||
|                       | to an internal ssh-agent. This key cannot be        |
 | 
					|                       | to an internal ssh-agent. This key cannot be        |
 | 
				
			||||||
@@ -298,6 +299,10 @@ Static configuration reference
 | 
				
			|||||||
    Contains the target to build by bitbake. Can be overwritten by the
 | 
					    Contains the target to build by bitbake. Can be overwritten by the
 | 
				
			||||||
    ``KAS_TARGET`` environment variable and defaults to ``core-image-minimal``.
 | 
					    ``KAS_TARGET`` environment variable and defaults to ``core-image-minimal``.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* ``task``: string [optional]
 | 
				
			||||||
 | 
					    Contains the task to build by bitbake. Can be overwritten by the
 | 
				
			||||||
 | 
					    ``KAS_TASK`` environment variable and defaults to ``build``.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* ``repos``: dict [optional]
 | 
					* ``repos``: dict [optional]
 | 
				
			||||||
    Contains the definitions of all available repos and layers.
 | 
					    Contains the definitions of all available repos and layers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,8 +57,7 @@ class Build:
 | 
				
			|||||||
        bld_psr.add_argument('--target',
 | 
					        bld_psr.add_argument('--target',
 | 
				
			||||||
                             help='Select target to build')
 | 
					                             help='Select target to build')
 | 
				
			||||||
        bld_psr.add_argument('--task',
 | 
					        bld_psr.add_argument('--task',
 | 
				
			||||||
                             help='Select which task should be executed',
 | 
					                             help='Select which task should be executed')
 | 
				
			||||||
                             default='build')
 | 
					 | 
				
			||||||
        bld_psr.add_argument('--skip',
 | 
					        bld_psr.add_argument('--skip',
 | 
				
			||||||
                             help='Skip build steps',
 | 
					                             help='Skip build steps',
 | 
				
			||||||
                             default=[])
 | 
					                             default=[])
 | 
				
			||||||
@@ -72,7 +71,7 @@ class Build:
 | 
				
			|||||||
        if args.cmd != 'build':
 | 
					        if args.cmd != 'build':
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cfg = load_config(args.config, args.target)
 | 
					        cfg = load_config(args.config, args.target, args.task)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        macro = Macro()
 | 
					        macro = Macro()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,5 +118,6 @@ class BuildCommand(Command):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        # Start bitbake build of image
 | 
					        # Start bitbake build of image
 | 
				
			||||||
        bitbake = find_program(config.environ['PATH'], 'bitbake')
 | 
					        bitbake = find_program(config.environ['PATH'], 'bitbake')
 | 
				
			||||||
        run_cmd([bitbake, '-k', config.get_bitbake_target(), '-c', self.task],
 | 
					        run_cmd([bitbake, '-k', config.get_bitbake_target(),
 | 
				
			||||||
 | 
					                 '-c', config.get_bitbake_task()],
 | 
				
			||||||
                env=config.environ, cwd=config.build_dir)
 | 
					                env=config.environ, cwd=config.build_dir)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -149,6 +149,13 @@ class Config:
 | 
				
			|||||||
                              self._config.get('target',
 | 
					                              self._config.get('target',
 | 
				
			||||||
                                               'core-image-minimal'))
 | 
					                                               'core-image-minimal'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_bitbake_task(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					            Return the bitbake task
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        return os.environ.get('KAS_TASK',
 | 
				
			||||||
 | 
					                              self._config.get('task', 'build'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_conf_header(self, header_name):
 | 
					    def _get_conf_header(self, header_name):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
            Returns the local.conf header
 | 
					            Returns the local.conf header
 | 
				
			||||||
@@ -195,7 +202,7 @@ class ConfigPython(Config):
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
        Implementation of a configuration that uses a Python script.
 | 
					        Implementation of a configuration that uses a Python script.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    def __init__(self, filename, target):
 | 
					    def __init__(self, filename, target, task):
 | 
				
			||||||
        # pylint: disable=exec-used
 | 
					        # pylint: disable=exec-used
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
@@ -210,11 +217,12 @@ class ConfigPython(Config):
 | 
				
			|||||||
            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT),
 | 
					            raise IOError(errno.ENOENT, os.strerror(errno.ENOENT),
 | 
				
			||||||
                          self.filename)
 | 
					                          self.filename)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.create_config(target)
 | 
					        self.create_config(target, task)
 | 
				
			||||||
        self.setup_environ()
 | 
					        self.setup_environ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        output = 'target: {}\n'.format(self.target)
 | 
					        output = 'target: {}\n'.format(self.target)
 | 
				
			||||||
 | 
					        output = 'task: {}\n'.format(self.task)
 | 
				
			||||||
        output += 'repos:\n'
 | 
					        output += 'repos:\n'
 | 
				
			||||||
        for repo in self.get_repos():
 | 
					        for repo in self.get_repos():
 | 
				
			||||||
            output += '  {}\n'.format(repo.__str__())
 | 
					            output += '  {}\n'.format(repo.__str__())
 | 
				
			||||||
@@ -244,11 +252,12 @@ class ConfigPython(Config):
 | 
				
			|||||||
        except KeyError:
 | 
					        except KeyError:
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_config(self, target):
 | 
					    def create_config(self, target, task):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
            Sets the configuration for `target`
 | 
					            Sets the configuration for `target`
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        self.target = 'core-image-minimal' if target is None else target
 | 
					        self.target = 'core-image-minimal' if target is None else target
 | 
				
			||||||
 | 
					        self.task = 'build' if task is None else task
 | 
				
			||||||
        self.repos = self._config['get_repos'](self, target)
 | 
					        self.repos = self._config['get_repos'](self, target)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_proxy_config(self):
 | 
					    def get_proxy_config(self):
 | 
				
			||||||
@@ -323,7 +332,7 @@ class ConfigStatic(Config):
 | 
				
			|||||||
        Implements the static kas configuration based on config files.
 | 
					        Implements the static kas configuration based on config files.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, filename, target):
 | 
					    def __init__(self, filename, target, task):
 | 
				
			||||||
        from .includehandler import GlobalIncludes, IncludeException
 | 
					        from .includehandler import GlobalIncludes, IncludeException
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
        self.setup_environ()
 | 
					        self.setup_environ()
 | 
				
			||||||
@@ -360,6 +369,8 @@ class ConfigStatic(Config):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if target:
 | 
					        if target:
 | 
				
			||||||
            self._config['target'] = target
 | 
					            self._config['target'] = target
 | 
				
			||||||
 | 
					        if task:
 | 
				
			||||||
 | 
					            self._config['task'] = task
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_repos(self):
 | 
					    def get_repos(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@@ -421,15 +432,15 @@ class ConfigStatic(Config):
 | 
				
			|||||||
        return repo_dict
 | 
					        return repo_dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def load_config(filename, target):
 | 
					def load_config(filename, target, task):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
        Return configuration generated from `filename`.
 | 
					        Return configuration generated from `filename`.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (_, ext) = os.path.splitext(filename)
 | 
					    (_, ext) = os.path.splitext(filename)
 | 
				
			||||||
    if ext == '.py':
 | 
					    if ext == '.py':
 | 
				
			||||||
        cfg = ConfigPython(filename, target)
 | 
					        cfg = ConfigPython(filename, target, task)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        cfg = ConfigStatic(filename, target)
 | 
					        cfg = ConfigStatic(filename, target, task)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return cfg
 | 
					    return cfg
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,7 +73,7 @@ class Shell:
 | 
				
			|||||||
        if args.cmd != 'shell':
 | 
					        if args.cmd != 'shell':
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cfg = load_config(args.config, args.target)
 | 
					        cfg = load_config(args.config, args.target, None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        macro = Macro()
 | 
					        macro = Macro()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user