stx tool: build: Add the support of build module
Implement the stx build module so that the developer could build packages or images on the host with the 'stx build xxx' command. Now support the action: [ prepare|cleanup|distro|image|${pkgname} ] stx build prepare: Finish the setup to start building stx build cleanup: Clean prepare intermediate artifacts stx build distro: Build all packages of distro layer stx build image: Build iso or other type image stx build $pkgname: Build single package Command 'stx build $pkg1,$pkg2...' to build multi-packages Please refer to the more help information with the command 'stx build --help' Story: 2008862 Task: 43013 Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com> Change-Id: Iaee817e1551c2deeca9db3821285013779c85dea
This commit is contained in:
parent
32ffad761c
commit
9f324cdc8d
128
stx/lib/stx/stx_build.py
Normal file
128
stx/lib/stx/stx_build.py
Normal file
@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2021 Wind River Systems, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from stx import command # pylint: disable=E0611
|
||||
from stx import utils # pylint: disable=E0611
|
||||
|
||||
|
||||
class HandleBuildTask:
|
||||
'''Handle the task for the build sub-command'''
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger('STX-Build')
|
||||
utils.set_logger(self.logger)
|
||||
|
||||
def buildImageCMD(self, args, prefixcmd):
|
||||
|
||||
if args.type:
|
||||
if (args.type != 'rt' and args.type != 'std'):
|
||||
self.logger.error('Option -t for generaing image only should \
|
||||
be [ rt|std ]')
|
||||
self.logger.error('Please use "stx build -h" to show the help\
|
||||
\n')
|
||||
sys.exit(1)
|
||||
|
||||
cmd = prefixcmd + '"build-image -t ' + args.type + '"\''
|
||||
else:
|
||||
cmd = prefixcmd + '"build-image"\''
|
||||
|
||||
return cmd
|
||||
|
||||
def buildDistroCMD(self, prefixcmd):
|
||||
|
||||
cmd = prefixcmd + '"build-pkgs"\''
|
||||
return cmd
|
||||
|
||||
def buildPrepareCMD(self, prefixcmd):
|
||||
|
||||
cmd = prefixcmd + '". /usr/local/bin/stx/stx-prepare-build"\''
|
||||
return cmd
|
||||
|
||||
def buildCleanupCMD(self, prefixcmd):
|
||||
|
||||
cmd = prefixcmd + '". /usr/local/bin/stx/stx-cleanup"\''
|
||||
return cmd
|
||||
|
||||
def buildPackageCMD(self, args, prefixcmd):
|
||||
|
||||
if args.force:
|
||||
cmd = prefixcmd + '"build-pkgs -c -p ' + args.build_task + '"\''
|
||||
else:
|
||||
cmd = prefixcmd + '"build-pkgs -p ' + args.build_task + '"\''
|
||||
return cmd
|
||||
|
||||
def handleBuild(self, args):
|
||||
|
||||
self.logger.setLevel(args.loglevel)
|
||||
|
||||
podname = command.get_pod_name('builder')
|
||||
if not podname:
|
||||
self.logger.error('The builder container does not exist, \
|
||||
so please use the control module to start.')
|
||||
sys.exit(1)
|
||||
|
||||
if args.build_task != 'prepare' and args.build_task != 'cleanup':
|
||||
|
||||
bashcmd = '\'find /home/${MYUNAME}/prepare-build.done \
|
||||
&>/dev/null\''
|
||||
cmd = command.generatePrefixCommand(podname, bashcmd, 0)
|
||||
|
||||
ret = subprocess.call(cmd, shell=True)
|
||||
if ret != 0:
|
||||
self.logger.warning('****************************************\
|
||||
******************************')
|
||||
self.logger.warning('The building env not be initialized yet!\
|
||||
')
|
||||
self.logger.warning('Execute \'stx build prepare\' to finish \
|
||||
the setup step before building')
|
||||
self.logger.warning('****************************************\
|
||||
******************************')
|
||||
sys.exit(1)
|
||||
|
||||
prefix_cmd = command.generatePrefixCommand(podname, '', 1)
|
||||
|
||||
if args.build_task == 'image':
|
||||
cmd = self.buildImageCMD(args, prefix_cmd)
|
||||
self.logger.debug('Execute the generation image command: [%s]',
|
||||
cmd)
|
||||
|
||||
elif args.build_task == 'distro':
|
||||
cmd = self.buildDistroCMD(prefix_cmd)
|
||||
self.logger.debug('Execute the distro compiling command: [%s].',
|
||||
cmd)
|
||||
|
||||
elif args.build_task == 'prepare':
|
||||
cmd = self.buildPrepareCMD(prefix_cmd)
|
||||
self.logger.debug('Execute the prepare command: [%s].', cmd)
|
||||
|
||||
elif args.build_task == 'cleanup':
|
||||
cmd = self.buildCleanupCMD(prefix_cmd)
|
||||
self.logger.debug('Execute the cleanup command: [%s].', cmd)
|
||||
|
||||
else:
|
||||
cmd = self.buildPackageCMD(args, prefix_cmd)
|
||||
self.logger.debug('Compile the package: [%s] with the command \
|
||||
[%s]', args.build_task, cmd)
|
||||
|
||||
try:
|
||||
subprocess.check_call(cmd, shell=True)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
raise Exception('Failed to build with the command [%s].\n \
|
||||
Returncode: %s' % (cmd, exc.returncode))
|
@ -16,6 +16,7 @@ import argparse
|
||||
import logging
|
||||
|
||||
from stx import command # pylint: disable=E0611
|
||||
from stx import stx_build # pylint: disable=E0611
|
||||
from stx import stx_configparser # pylint: disable=E0611
|
||||
from stx import stx_control # pylint: disable=E0611
|
||||
from stx import stx_repomgr # pylint: disable=E0611
|
||||
@ -36,6 +37,7 @@ class CommandLine:
|
||||
command.check_prjdir_env()
|
||||
self.handleconfig = stx_configparser.HandleConfigTask()
|
||||
self.handlecontrol = stx_control.HandleControlTask()
|
||||
self.handlebuild = stx_build.HandleBuildTask()
|
||||
self.parser = self.parseCommandLine()
|
||||
|
||||
def parseCommandLine(self):
|
||||
@ -89,6 +91,23 @@ settings.\t\teg: [ --show|--get|--add|--unset|--remove-section ]')
|
||||
required=False)
|
||||
config_subparser.set_defaults(handle=self.handleconfig.handleConfig)
|
||||
|
||||
build_subparser = subparsers.add_parser('build',
|
||||
help='Run to build packages or\
|
||||
image.\t\teg: [ prepare|distro|image|${pkgname}]')
|
||||
build_subparser.add_argument('build_task',
|
||||
help='[ prepare|cleanup|distro|image|\
|
||||
${pkgname} ]: \
|
||||
Prepare for building enviroment and \
|
||||
build packages, distro layer or image.\
|
||||
\n\n')
|
||||
build_subparser.add_argument('-f', '--force',
|
||||
help='Force to compile the package again.\
|
||||
', action='store_true', required=False)
|
||||
build_subparser.add_argument('-t', '--type',
|
||||
help='[ rt|std ]: Select the kernel type.\
|
||||
', nargs=1, required=False)
|
||||
build_subparser.set_defaults(handle=self.handlebuild.handleBuild)
|
||||
|
||||
repo_subparser = subparsers.add_parser('repomgr',
|
||||
help='Manage source|binary \
|
||||
packages.\t\teg: [ list|download|sync|mirror|clean|remove_repo|upload_pkg|\
|
||||
|
Loading…
x
Reference in New Issue
Block a user