diff --git a/src/oebuild/app/plugins/bitbake/bitbake.py b/src/oebuild/app/plugins/bitbake/bitbake.py index 04fee5eadad97e5f95aa365d68db0dcd03f59bdb..17b367841227b893935e78a891590b3930f1943f 100644 --- a/src/oebuild/app/plugins/bitbake/bitbake.py +++ b/src/oebuild/app/plugins/bitbake/bitbake.py @@ -13,6 +13,7 @@ See the Mulan PSL v2 for more details. import os import argparse import textwrap +import sys from docker.errors import DockerException @@ -74,14 +75,14 @@ class Bitbake(OebuildCommand): ''' if '-h' in unknown or '--help' in unknown: self.print_help_msg() - return + sys.exit(0) command = self._get_command(unknow=unknown) if not self.check_support_bitbake(): logger.error( "Please do it in compile workspace which contain compile.yaml") - return + sys.exit(-1) if not os.path.exists('.env'): os.mknod('.env') @@ -90,7 +91,7 @@ class Bitbake(OebuildCommand): parse_compile = ParseCompile(self.compile_conf_dir) except CheckCompileError as c_e: logger.error(str(c_e)) - return + sys.exit(-1) # if has manifest.yaml, init layer repo with it yocto_dir = os.path.join(self.configure.source_dir(), @@ -103,12 +104,14 @@ class Bitbake(OebuildCommand): if parse_compile.build_in == oebuild_const.BUILD_IN_HOST: in_host = InHost(self.configure) in_host.exec(parse_compile=parse_compile, command=command) - return + sys.exit(0) + try: oebuild_util.check_docker() except DockerException as d_e: logger.error(str(d_e)) - return + sys.exit(-1) + in_container = InContainer(self.configure) in_container.exec(parse_env=parse_env, parse_compile=parse_compile, diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index 0f1b7c6986b0ecfcb4a0e58b91396f3f3ebd088b..f3eef0d68852bb69cca484f3d8eee1fd48b71516 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -55,7 +55,7 @@ class InContainer(BaseBuild): if not docker_proxy.is_image_exists(docker_param.image): logger.error('''The docker image does not exists, please run fellow command: `oebuild update docker`''') - return + sys.exit(-1) self.deal_env_container(env=parse_env, docker_param=docker_param) self.exec_compile(parse_compile=parse_compile, command=command) diff --git a/src/oebuild/app/plugins/bitbake/in_host.py b/src/oebuild/app/plugins/bitbake/in_host.py index 68a696db4ab2f588f6702e7995b4e71c51209792..8ea2e06efa23e4f45be50227f5bcabec26548829 100644 --- a/src/oebuild/app/plugins/bitbake/in_host.py +++ b/src/oebuild/app/plugins/bitbake/in_host.py @@ -58,39 +58,18 @@ class InHost(BaseBuild): except NativesdkNotExist as n_e: logger.error(str(n_e)) logger.error("Please set valid nativesdk directory") - return + sys.exit(1) except NativesdkNotValid as n_e: logger.error(str(n_e)) logger.error(''' -The nativesdk path must be valid, it is recommended -that you download the nativesdk script and then perform +The nativesdk path must be valid, it is recommended +that you download the nativesdk script and then perform initialization operations''') - return + sys.exit(1) if command is not None and command != "": self._append_build_sh(str_list=[command], build_dir=os.getcwd()) - with subprocess.Popen('bash build.sh', - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - encoding="utf-8", - text=True) as s_p: - if s_p.returncode is not None and s_p.returncode != 0: - err_msg = '' - if s_p.stderr is not None: - for line in s_p.stderr: - err_msg.join(line) - raise ValueError(err_msg) - res = None - while res is None: - res = s_p.poll() - if s_p.stdout is not None: - for line in s_p.stdout: - logger.info(line.strip('\n')) - if s_p.stderr is not None: - for line in s_p.stderr: - logger.error(line.strip('\n')) - sys.exit(res) + self._bash_build() else: # run in Interactive mode banner_list = [] @@ -109,6 +88,30 @@ initialization operations''') self.update_bashrc(new_content) pty.spawn("bash") + def _bash_build(self,): + with subprocess.Popen('bash build.sh', + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + text=True) as s_p: + if s_p.returncode is not None and s_p.returncode != 0: + err_msg = '' + if s_p.stderr is not None: + for line in s_p.stderr: + err_msg.join(line) + raise ValueError(err_msg) + res = None + while res is None: + res = s_p.poll() + if s_p.stdout is not None: + for line in s_p.stdout: + logger.info(line.strip('\n')) + if s_p.stderr is not None: + for line in s_p.stderr: + logger.error(line.strip('\n')) + sys.exit(res) + def _mk_build_sh(self, nativesdk_dir, build_dir): # get nativesdk environment path automatic for next step sdk_env_path = oebuild_util.get_nativesdk_environment(nativesdk_dir) diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index ab834f5e8b779530d935a5e2a50881888fad78a5..99640fd5f498a62c6abe6fa8af898436dc950180 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -14,6 +14,7 @@ import argparse import textwrap import os import pathlib +import sys from docker.errors import DockerException @@ -58,7 +59,7 @@ class Clear(OebuildCommand): def do_run(self, args: argparse.Namespace, unknown=None): # perpare parse help command if self.pre_parse_help(args, unknown): - return + sys.exit(1) args = args.parse_args(unknown) @@ -67,7 +68,7 @@ class Clear(OebuildCommand): self.client = DockerProxy() except DockerException: logger.error("Please install docker first!!!") - return + sys.exit(-1) self.clear_docker() def clear_docker(self, ): diff --git a/src/oebuild/app/plugins/deploy/deploy_target.py b/src/oebuild/app/plugins/deploy/deploy_target.py index 03227b3fc08e6f24ff2269db672736b240b18710..4c051daa498f98148491eb971ecdd5d1b1e42a65 100644 --- a/src/oebuild/app/plugins/deploy/deploy_target.py +++ b/src/oebuild/app/plugins/deploy/deploy_target.py @@ -13,6 +13,7 @@ See the Mulan PSL v2 for more details. import argparse import textwrap import logging +import sys from oebuild.command import OebuildCommand from oebuild.app.plugins.deploy.com_target import ComTarget @@ -50,7 +51,7 @@ oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] def do_run(self, args: argparse.Namespace, unknown=None): if '-h' in unknown or '--help' in unknown: self.print_help_msg() - return + sys.exit(1) str_args = ' '.join(unknown) com_target = ComTarget() com_target.exec(str_args=str_args, fun="deploy-target") @@ -115,7 +116,7 @@ oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] def do_run(self, args: argparse.Namespace, unknown=None): if '-h' in unknown or '--help' in unknown: self.print_help_msg() - return + sys.exit(1) str_args = ' '.join(unknown) com_target = ComTarget() com_target.exec(str_args=str_args, fun="undeploy-target") diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index dfd10311833b8d65520ac89d8d99f0835412e364..d2147dc8a11fd54d2160f5db0aa461f5aca934a6 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -175,7 +175,7 @@ class Generate(OebuildCommand): def do_run(self, args: argparse.Namespace, unknown=None): # perpare parse help command if self.pre_parse_help(args, unknown): - return + sys.exit(1) if not self.configure.is_oebuild_dir(): logger.error('Your current directory had not finished init') sys.exit(-1) @@ -186,7 +186,7 @@ class Generate(OebuildCommand): 'Currently, yocto-meta-openeuler does not support oebuild, \ please modify .oebuild/config and re-execute `oebuild update`' ) - return + sys.exit(-1) if len(unknown) == 0: config_path = self.create_kconfig(yocto_dir) @@ -204,7 +204,7 @@ class Generate(OebuildCommand): self._check_param_in_host(args=args) except ValueError as v_e: logger.error(str(v_e)) - return + sys.exit(-1) self.nativesdk_dir = args.nativesdk_dir build_in = oebuild_const.BUILD_IN_HOST @@ -219,12 +219,12 @@ class Generate(OebuildCommand): if args.list: self.list_info() - return + sys.exit(0) build_dir = self._init_build_dir(args=args) if build_dir is None: - return + sys.exit(1) parser_template = ParseTemplate(yocto_dir=yocto_dir) @@ -236,10 +236,10 @@ class Generate(OebuildCommand): parser_template=parser_template) except BaseParseTemplate as b_t: logger.error(str(b_t)) - return + sys.exit(-1) except ValueError as v_e: logger.error(str(v_e)) - return + sys.exit(-1) try: self._add_features_template(args=args, @@ -248,10 +248,10 @@ class Generate(OebuildCommand): except BaseParseTemplate as b_t: logger.error(str(b_t)) self._list_feature() - return + sys.exit(-1) except ValueError as v_e: logger.error(str(v_e)) - return + sys.exit(-1) if os.path.exists(os.path.join(build_dir, 'compile.yaml')): os.remove(os.path.join(build_dir, 'compile.yaml')) @@ -275,7 +275,7 @@ class Generate(OebuildCommand): f"{key}, {oebuild_config.docker.repo_url}:{value}") k = input("please entry number:") if k == "q": - return + sys.exit(0) try: index = int(k) docker_tag = image_list[index] diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index 6cf5ef0156b343b5a2805a2aea4c64688790f965..29e35db1eeec0c3a394a2efd51841553003bc9ec 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -84,7 +84,7 @@ class Init(OebuildCommand): # perpare parse help command if self.pre_parse_help(args, unknown): - return + sys.exit(0) args = args.parse_args(unknown) @@ -99,11 +99,11 @@ class Init(OebuildCommand): logger.error("'oebuild init' need param directory") logger.info("\noebuild init help:") self.print_help_msg() - return + sys.exit(1) if not self.init_workspace(args.directory): logger.error("mkdir %s failed", args.directory) - return + sys.exit(-1) os.chdir(args.directory) oebuild_config: Config = self.configure.parse_oebuild_config() diff --git a/src/oebuild/app/plugins/m_env/m_env.py b/src/oebuild/app/plugins/m_env/m_env.py index 6d535d4916516e313838fda4e43c74662360ebf5..15e656d49dccd5047738d2ae435ea6f7227ec6e1 100644 --- a/src/oebuild/app/plugins/m_env/m_env.py +++ b/src/oebuild/app/plugins/m_env/m_env.py @@ -107,7 +107,7 @@ class Menv(OebuildCommand): print(''' Please enter the correct command: oebuild menv create [-d -f] Create an environment -n env_name ''') - sys.exit(-1) + sys.exit(1) self.create_environment(args=args) elif command == 'activate': # Activate Environment @@ -117,7 +117,7 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm print( 'Please enter the correct command: oebuild menv activate -n env_name' ) - sys.exit(-1) + sys.exit(1) elif command == 'list': env_dict = oebuild_util.read_yaml(self.oebuild_env_yaml_path) @@ -136,7 +136,7 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm print( 'Please enter the correct command: oebuild menv remove -n env_name' ) - sys.exit(-1) + sys.exit(1) def create_environment(self, args): ''' diff --git a/src/oebuild/app/plugins/m_plugin/m_plugin.py b/src/oebuild/app/plugins/m_plugin/m_plugin.py index cad99af765f566213e9a7ed694375d8855a24699..83cdc6e90783ceac8927caf447392689ef04b92a 100644 --- a/src/oebuild/app/plugins/m_plugin/m_plugin.py +++ b/src/oebuild/app/plugins/m_plugin/m_plugin.py @@ -170,7 +170,7 @@ class MPlugin(OebuildCommand): sys.exit(0) logger.error("the %s not exist, please check the plugin file path", args.file) - sys.exit(-1) + sys.exit(1) elif command == 'list': self.list_plugin(plugin_dict=plugin_dict) elif command in ['enable', 'disable']: diff --git a/src/oebuild/app/plugins/manifest/manifest.py b/src/oebuild/app/plugins/manifest/manifest.py index d62e94bb5776b757cb8e8a14b744cb60b1ec9120..cb488a27a4c0ab113debc782468c2fb6e04d9925 100644 --- a/src/oebuild/app/plugins/manifest/manifest.py +++ b/src/oebuild/app/plugins/manifest/manifest.py @@ -75,7 +75,7 @@ class Manifest(OebuildCommand): # perpare parse help command if self.pre_parse_help(args, unknown): - return + sys.exit(0) args = args.parse_args(unknown) manifest_dir = args.manifest_dir if args.manifest_dir else \ diff --git a/src/oebuild/app/plugins/run_qemu/run_qemu.py b/src/oebuild/app/plugins/run_qemu/run_qemu.py index c4b56fe9a765846cd1cf4b42c438e559d4457f36..faed77ea543e5ddcb7928c2163831f1b5d04a07c 100644 --- a/src/oebuild/app/plugins/run_qemu/run_qemu.py +++ b/src/oebuild/app/plugins/run_qemu/run_qemu.py @@ -76,7 +76,7 @@ the container {self.container_id} failed to be destroyed, please run self.client = DockerProxy() except DockerException: logger.error("Please install docker first!!!") - return + sys.exit(-1) logger.info('Run QEMU......') docker_image = self.get_docker_image() diff --git a/src/oebuild/app/plugins/update/update.py b/src/oebuild/app/plugins/update/update.py index cf11c2688e3ac3ba235e7741a53e49ef237a289a..2a7e7c863016ac4be8f96cd28ab79bcc9d18d890 100644 --- a/src/oebuild/app/plugins/update/update.py +++ b/src/oebuild/app/plugins/update/update.py @@ -87,7 +87,7 @@ class Update(OebuildCommand): ''' # perpare parse help command if self.pre_parse_help(args, unknown): - return + sys.exit(0) args = args.parse_args(unknown) @@ -111,7 +111,7 @@ class Update(OebuildCommand): update_layer = True else: logger.error('Please run oebuild update [yocto docker layer]') - sys.exit(-1) + sys.exit(1) if update_yocto: self.get_basic_repo() @@ -123,7 +123,7 @@ class Update(OebuildCommand): self.docker_image_update(args.docker_tag) except DockerException as d_e: logger.error(str(d_e)) - return + sys.exit(-1) if update_layer: self.get_layer_repo()