diff --git a/src/oebuild/app/conf/oebuild.sh b/src/oebuild/app/conf/oebuild.sh index 57744bb8cbc5d851669707f175d6cdda93310fe8..dc303a525583a7be801944393e8aac80ec9bb6cb 100755 --- a/src/oebuild/app/conf/oebuild.sh +++ b/src/oebuild/app/conf/oebuild.sh @@ -5,7 +5,7 @@ _myobj_complete_func() { secondary_command_name="${COMP_WORDS[COMP_CWORD-1]}" completion_txt="init update generate bitbake manifest clear runqemu menv deploy-target undeploy-target mplugin" case "${secondary_command_name}" in oebuild) - COMPREPLY=($(compgen -W "${completion_txt}" -- ${command_name})) + COMPREPLY=($(compgen -f -W "${completion_txt}" -- ${command_name})) esac case "${secondary_command_name}" in menv) diff --git a/src/oebuild/app/main.py b/src/oebuild/app/main.py index 4a5f941d79f10146fefb338793f36d3b3c76487b..10cfef6270f84f986066c4794cbdc661f8de9201 100644 --- a/src/oebuild/app/main.py +++ b/src/oebuild/app/main.py @@ -14,12 +14,13 @@ import sys import pathlib from collections import OrderedDict import pwd +from shutil import rmtree import oebuild.util as oebuild_util import oebuild.const as oebuild_const from oebuild.m_log import logger -from oebuild.struct import CompileParam -from oebuild.parse_param import ParseOebuildEnvParam, ParseCompileParam +from oebuild.parse_param import ParseCompileParam +from oebuild.configure import Configure from oebuild.auto_completion import AutoCompletion from oebuild.version import __version__ from oebuild.spec import get_spec, _ExtCommand @@ -197,125 +198,107 @@ class QuickBuild(): def __init__(self, build_yaml_path): self.app = OebuildApp() self.build_yaml_path = pathlib.Path(build_yaml_path) - self.oebuild_env = None - self.build_data = None + self.compile_param = None + self.workdir = None + self.build_dir = None def _check_yaml(self,): if not os.path.exists(self.build_yaml_path.absolute()): logger.error("%s is not exists!", self.build_yaml_path) sys.exit(-1) data = oebuild_util.read_yaml(yaml_path=self.build_yaml_path) - self.build_data = data - if "oebuild_env" not in data: - logger.error("%s is not valid", self.build_yaml_path.name) - sys.exit(-1) - self.oebuild_env = ParseOebuildEnvParam().parse_to_obj(data['oebuild_env']) + compile_param = ParseCompileParam().parse_to_obj(compile_param_dict=data) + self.compile_param = compile_param def run(self): ''' Execute oebuild commands in order. ''' - self._check_yaml() - - self.do_init() + if not Configure().is_oebuild_dir(): + logger.error('Your current directory is not oebuild workspace') + sys.exit(-1) + self.workdir = Configure().oebuild_topdir() - self.do_update_layer() + self._check_yaml() + self.build_dir = self.compile_param.machine - self.do_build_list() + self.generate() - def do_init(self, ): - ''' - Execute oebuild command : oebuild init [directory] [-u yocto_remote_url] [-b branch] - ''' - argv = [ - 'init', - ] - try: - data = oebuild_util.read_yaml(yaml_path=self.build_yaml_path) - # get openeuler repo param - if 'openeuler_layer' in data: - argv.append("-u") - argv.append(self.oebuild_env.openeuler_layer.remote_url) - - argv.append("-b") - argv.append(self.oebuild_env.openeuler_layer.version) - argv.append(self.oebuild_env.workdir) - except Exception as e_p: - raise e_p - self.app.run(argv or sys.argv[1:]) - - def do_update_layer(self, ): - ''' - Execute oebuild command : oebuild update [yocto docker layer] [-tag] - ''' - argv = [ - 'update', - 'layer' - ] - os.chdir(self.oebuild_env.workdir) - self.app.run(argv or sys.argv[1:]) - - def do_build_list(self,): - ''' - Build sequentially from the given compile parameter list. - ''' - for build_name in self.oebuild_env.build_list: - self._generate_and_bitbake(build_name=build_name) + self.bitbake() - def _generate_and_bitbake(self, build_name): + def generate(self): ''' - Execute oebuild command : oebuild generate + xxx ''' - if build_name not in self.build_data: - logger.error("lack %s dict data in %s", build_name, self.build_yaml_path) - sys.exit(-1) - compile_param_dict = self.build_data[build_name] - compile_param = ParseCompileParam().parse_to_obj(compile_param_dict=compile_param_dict) - self._generate(compile_param=compile_param, build_name=build_name) - compile_dir = os.path.join(self.oebuild_env.workdir, "build", build_name) - self._bitbake( - bitbake_cmds=compile_param.bitbake_cmds, - compile_dir=compile_dir, - build_in=compile_param.build_in) - - def _generate(self, compile_param: CompileParam, build_name): - # check compile if exists, if exists, exit with -1 - compile_dir = os.path.join(self.oebuild_env.workdir, "build", build_name) - if os.path.exists(compile_dir): - logger.error("%s has exists", compile_dir) - sys.exit(-1) - - if compile_param.build_in == oebuild_const.BUILD_IN_DOCKER: - if compile_param.docker_param is None: + os.chdir(Configure().build_dir()) + self._init_build_dir() + if self.compile_param.build_in == oebuild_const.BUILD_IN_DOCKER: + if self.compile_param.docker_param is None: logger.error("param is error, build in docker need docker_param") sys.exit(-1) # check src and compile_dir if exists src_volumn_flag = False compile_volumn_flag = False - for volumn in compile_param.docker_param.volumns: + for volumn in self.compile_param.docker_param.volumns: volumn_split = volumn.split(":") if oebuild_const.CONTAINER_SRC == volumn_split[1].strip(" "): src_volumn_flag = True if volumn_split[1].strip(" ").startswith(oebuild_const.CONTAINER_BUILD): compile_volumn_flag = True if not src_volumn_flag: - compile_param.docker_param.volumns.append( - f"{self.oebuild_env.workdir}/src:{oebuild_const.CONTAINER_SRC}" + self.compile_param.docker_param.volumns.append( + f"{self.workdir}/src:{oebuild_const.CONTAINER_SRC}" ) if not compile_volumn_flag: - compile_param.docker_param.volumns.append( - f"{compile_dir}:{oebuild_const.CONTAINER_BUILD}/{build_name}" + volumn_dir = os.path.join(oebuild_const.CONTAINER_BUILD, self.build_dir) + self.compile_param.docker_param.volumns.append( + f"{os.path.abspath(self.build_dir)}:{volumn_dir}" ) - compile_param_dict = ParseCompileParam().parse_to_dict(compile_param=compile_param) - os.makedirs(compile_dir) - compile_yaml_path = os.path.join(compile_dir, "compile.yaml") + compile_param_dict = ParseCompileParam().parse_to_dict(compile_param=self.compile_param) + compile_yaml_path = os.path.join(self.build_dir, "compile.yaml") oebuild_util.write_yaml(yaml_path=compile_yaml_path, data=compile_param_dict) - def _bitbake(self, bitbake_cmds, compile_dir, build_in): - os.chdir(compile_dir) - if build_in == oebuild_const.BUILD_IN_DOCKER: - self._update_docker() - for bitbake_cmd in bitbake_cmds: + def _init_build_dir(self): + # check compile if exists, if exists, exit with -1 + if os.path.exists(self.build_dir): + build_dir = self.build_dir + logger.warning("the build directory %s already exists", build_dir) + while True: + in_res = input(f""" + do you want to overwrite it({os.path.basename(build_dir)})? the overwrite action + will replace the compile.yaml or toolchain.yaml to new and delete conf directory, + enter Y for yes, N for no, C for create:""") + if in_res not in ["Y", "y", "yes", "N", "n", "no", "C", "c", "create"]: + print(""" + wrong input""") + continue + if in_res in ['N', 'n', 'no']: + sys.exit(0) + if in_res in ['C', 'c', 'create']: + in_res = input(""" + please enter now build name, we will create it under build directory:""") + build_dir = os.path.join(Configure().build_dir(), in_res) + if os.path.exists(build_dir): + continue + break + self.build_dir = build_dir + if os.path.exists(os.path.join(self.build_dir, "conf")): + rmtree(os.path.join(self.build_dir, "conf")) + elif os.path.exists(self.build_dir): + rmtree(self.build_dir) + os.makedirs(self.build_dir, exist_ok=True) + + def bitbake(self): + ''' + xxx + ''' + os.chdir(self.build_dir) + if self.compile_param.bitbake_cmds is None: + print("================================================\n\n" + f"please enter {self.build_dir} for next steps!!!\n\n" + "================================================\n") + return + for bitbake_cmd in self.compile_param.bitbake_cmds: bitbake_cmd: str = bitbake_cmd.strip(" ") argv = [ 'bitbake', @@ -323,16 +306,6 @@ class QuickBuild(): ] self.app.run(argv or sys.argv[1:]) - def _update_docker(self,): - ''' - Execute oebuild command : oebuild update [yocto docker layer] [-tag] - ''' - argv = [ - 'update', - 'docker' - ] - self.app.run(argv or sys.argv[1:]) - def main(argv=None): ''' diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index abf26593619803d6eb375035c0946fe554871a4f..04108a0aeb3e63274a053782d2cd2fe891fcc298 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -131,7 +131,8 @@ class InContainer(BaseBuild): exit_code = 1 else: logger.info(line[0].decode().strip('\n')) - sys.exit(exit_code) + if exit_code != 0: + sys.exit(exit_code) else: content = self.bashrc.get_bashrc_content() for b_s in oebuild_const.BASH_BANNER.split('\n'): diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 9a2691866cc925f46e0a3be69f720ad7e87d10f3..5adf08eb295b58c6cc51c6561f877ad2fe9736b7 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -305,7 +305,7 @@ Wrong platform, please run `oebuild generate -l` to view support feature""") # detects if a build directory already exists if os.path.exists(build_dir): logger.warning("the build directory %s already exists", build_dir) - while True: + while not args.yes: in_res = input(f""" do you want to overwrite it({os.path.basename(build_dir)})? the overwrite action will replace the compile.yaml or toolchain.yaml to new and delete conf directory, @@ -327,7 +327,7 @@ Wrong platform, please run `oebuild generate -l` to view support feature""") rmtree(os.path.join(build_dir, "conf")) elif os.path.exists(build_dir): rmtree(build_dir) - os.makedirs(build_dir) + os.makedirs(build_dir, exist_ok=True) return build_dir def list_info(self, ): diff --git a/src/oebuild/app/plugins/generate/parses.py b/src/oebuild/app/plugins/generate/parses.py index 31214e9067b85a24bd2586c7d0e6489f6da6cd23..8df8173a330423d738e2aa76166157703a6f5965 100644 --- a/src/oebuild/app/plugins/generate/parses.py +++ b/src/oebuild/app/plugins/generate/parses.py @@ -15,7 +15,7 @@ import oebuild.const as oebuild_const def parsers(parser): ''' - xxx + for generate param parser ''' parser.add_argument('-l', '--list', @@ -69,6 +69,14 @@ def parsers(parser): this param is build directory, the default is same to platform ''') + parser.add_argument('-y', + '--yes', + dest='yes', + action="store_true", + help=''' + this param is default action, if use, the default action is yes in next steps + ''') + parser.add_argument('-t', '--toolchain_dir', dest='toolchain_dir', diff --git a/src/oebuild/parse_param.py b/src/oebuild/parse_param.py index feae9e81ed440966a17d6593255e3c3d32b25d2d..1a19a936bee8027f3b9ca402e7fe4a25f272ce92 100644 --- a/src/oebuild/parse_param.py +++ b/src/oebuild/parse_param.py @@ -12,44 +12,11 @@ See the Mulan PSL v2 for more details. from typing import Dict -from oebuild.struct import RepoParam, DockerParam, CompileParam, ToolchainParam, OebuildEnv +from oebuild.struct import RepoParam, DockerParam, CompileParam, ToolchainParam import oebuild.util as oebuild_util import oebuild.const as oebuild_const -class ParseOebuildEnvParam: - ''' - OebuildEnv: - workdir: str - openeuler_layer: RepoParam - build_list: Optional[list] - ''' - @staticmethod - def parse_to_obj(oebuild_env_param_dict) -> OebuildEnv: - ''' - parse dict to OebuildEnv - ''' - return OebuildEnv( - workdir=oebuild_env_param_dict['workdir'], - openeuler_layer=(None if 'openeuler_layer' not in oebuild_env_param_dict else - ParseRepoParam.parse_to_obj( - oebuild_env_param_dict['openeuler_layer'])), - build_list=(None if 'build_list' not in oebuild_env_param_dict else - oebuild_env_param_dict['build_list']) - ) - - @staticmethod - def parse_to_dict(oebuild_env_obj: OebuildEnv): - ''' - parse OebuildEnv to dict - ''' - return { - "workdir": oebuild_env_obj.workdir, - "openeuler_layer": oebuild_env_obj.openeuler_layer, - "build_list": oebuild_env_obj.build_list - } - - class ParseRepoParam: ''' RepoParam: @@ -129,6 +96,7 @@ class ParseCompileParam: llvm_toolchain_dir: Optional[str] nativesdk_dir: Optional[str] + bitbake_cmds: Optional[list] ''' @staticmethod def parse_to_obj(compile_param_dict) -> CompileParam: diff --git a/src/oebuild/struct.py b/src/oebuild/struct.py index 08e6cd84560c7def1575f96e5d43e901b36d3a02..10b36a8b732616f4bda107b89528bfff24d1a75b 100644 --- a/src/oebuild/struct.py +++ b/src/oebuild/struct.py @@ -27,16 +27,6 @@ class RepoParam: version: str -@dataclass -class OebuildEnv: - ''' - when run oebuild build.yaml, the OebuildEnv will be need in build.yaml - ''' - workdir: str - openeuler_layer: Optional[RepoParam] - build_list: Optional[list] - - @dataclass class DockerParam: '''