diff --git a/hb/containers/arg.py b/hb/containers/arg.py index 82fc18c0caded3719c957c6c2ec148c6ad1d7c28..346379a1d58f04a933ab56b01869681b1b92052d 100644 --- a/hb/containers/arg.py +++ b/hb/containers/arg.py @@ -32,6 +32,18 @@ from resources.global_var import DEFAULT_ENV_ARGS from resources.global_var import CURRENT_ENV_ARGS from resources.global_var import DEFAULT_TOOL_ARGS from resources.global_var import CURRENT_TOOL_ARGS +from resources.global_var import DEFAULT_INDEP_BUILD_ARGS +from resources.global_var import CURRENT_INDEP_BUILD_ARGS +from resources.global_var import DEFAULT_INSTALL_ARGS +from resources.global_var import CURRENT_INSTALL_ARGS +from resources.global_var import DEFAULT_PACKAGE_ARGS +from resources.global_var import CURRENT_PACKAGE_ARGS +from resources.global_var import DEFAULT_PUBLISH_ARGS +from resources.global_var import CURRENT_PUBLISH_ARGS +from resources.global_var import DEFAULT_UPDATE_ARGS +from resources.global_var import CURRENT_UPDATE_ARGS +from resources.global_var import DEFAULT_PUSH_ARGS +from resources.global_var import CURRENT_PUSH_ARGS from resources.global_var import ARGS_DIR from exceptions.ohos_exception import OHOSException from util.log_util import LogUtil @@ -48,7 +60,12 @@ class ModuleType(Enum): ENV = 2 CLEAN = 3 TOOL = 4 - + INDEP_BUILD = 5 + INSTALL = 6 + PACKAGE = 7 + PUBLISH = 8 + UPDATE = 9 + PUSH = 10 class ArgType(): @@ -283,6 +300,18 @@ class Arg(): args_file_path = CURRENT_ENV_ARGS elif module_type == ModuleType.TOOL: args_file_path = CURRENT_TOOL_ARGS + elif module_type == ModuleType.INDEP_BUILD: + args_file_path = CURRENT_INDEP_BUILD_ARGS + elif module_type == ModuleType.INSTALL: + args_file_path = CURRENT_INSTALL_ARGS + elif module_type == ModuleType.PACKAGE: + args_file_path = CURRENT_PACKAGE_ARGS + elif module_type == ModuleType.PUBLISH: + args_file_path = CURRENT_PUBLISH_ARGS + elif module_type == ModuleType.UPDATE: + args_file_path = CURRENT_UPDATE_ARGS + elif module_type == ModuleType.PUSH: + args_file_path = CURRENT_PUSH_ARGS else: raise OHOSException( 'You are trying to write args file, but there is no corresponding module "{}" args file' @@ -311,6 +340,24 @@ class Arg(): elif module_type == ModuleType.TOOL: args_file_path = CURRENT_TOOL_ARGS default_file_path = DEFAULT_TOOL_ARGS + elif module_type == ModuleType.INDEP_BUILD: + args_file_path = CURRENT_INDEP_BUILD_ARGS + default_file_path = DEFAULT_INDEP_BUILD_ARGS + elif module_type == ModuleType.INSTALL: + args_file_path = CURRENT_INSTALL_ARGS + default_file_path = DEFAULT_INSTALL_ARGS + elif module_type == ModuleType.PACKAGE: + args_file_path = CURRENT_PACKAGE_ARGS + default_file_path = DEFAULT_PACKAGE_ARGS + elif module_type == ModuleType.PUBLISH: + args_file_path = CURRENT_PUBLISH_ARGS + default_file_path = DEFAULT_PUBLISH_ARGS + elif module_type == ModuleType.UPDATE: + args_file_path = CURRENT_UPDATE_ARGS + default_file_path = DEFAULT_UPDATE_ARGS + elif module_type == ModuleType.PUSH: + args_file_path = CURRENT_PUSH_ARGS + default_file_path = DEFAULT_PUSH_ARGS else: raise OHOSException( 'You are trying to read args file, but there is no corresponding module "{}" args file' @@ -327,3 +374,22 @@ class Arg(): for file in os.listdir(CURRENT_ARGS_DIR): if file.endswith('.json') and os.path.exists(os.path.join(CURRENT_ARGS_DIR, file)): os.remove(os.path.join(CURRENT_ARGS_DIR, file)) + + @staticmethod + def clean_args_file_by_type(module_type: ModuleType): + args_file_path = '' + if module_type == ModuleType.INSTALL: + args_file_path = CURRENT_INSTALL_ARGS + elif module_type == ModuleType.PACKAGE: + args_file_path = CURRENT_PACKAGE_ARGS + elif module_type == ModuleType.UPDATE: + args_file_path = CURRENT_UPDATE_ARGS + elif module_type == ModuleType.ENV: + args_file_path = CURRENT_ENV_ARGS + elif module_type == ModuleType.INDEP_BUILD: + args_file_path = CURRENT_INDEP_BUILD_ARGS + elif module_type == ModuleType.PUSH: + args_file_path = CURRENT_PUSH_ARGS + if os.path.exists(args_file_path): + os.remove(args_file_path) + \ No newline at end of file diff --git a/hb/containers/status.py b/hb/containers/status.py index a80ef60e644ba2f4c9bbb9eb6d48b716af86fb0c..9ef37db11b22758825502f4aafcd75c87e7ee7ca 100644 --- a/hb/containers/status.py +++ b/hb/containers/status.py @@ -69,7 +69,7 @@ def throw_exception(func): def _print_formatted_tracebak(_code, _exception, _type, _desc, _solution): _log_path = '' - if IoUtil.read_json_file(ROOT_CONFIG_FILE).get('out_path') is not None: + if os.path.exists(ROOT_CONFIG_FILE) and IoUtil.read_json_file(ROOT_CONFIG_FILE).get('out_path') is not None: _log_path = os.path.join(IoUtil.read_json_file( ROOT_CONFIG_FILE).get('out_path'), 'build.log') else: diff --git a/hb/main.py b/hb/main.py index e268f990c139294a165ca7ed32a044638fd4874b..c01bcc1c0e998a27d064bd85984e33c4c3166dfc 100755 --- a/hb/main.py +++ b/hb/main.py @@ -33,12 +33,20 @@ from services.preloader import OHOSPreloader from services.loader import OHOSLoader from services.gn import Gn from services.ninja import Ninja +from services.hpm import Hpm +from services.hdc import Hdc from resolver.build_args_resolver import BuildArgsResolver from resolver.set_args_resolver import SetArgsResolver from resolver.clean_args_resolver import CleanArgsResolver from resolver.env_args_resolver import EnvArgsResolver from resolver.tool_args_resolver import ToolArgsResolver +from resolver.indep_build_args_resolver import IndepBuildArgsResolver +from resolver.install_args_resolver import InstallArgsResolver +from resolver.package_args_resolver import PackageArgsResolver +from resolver.publish_args_resolver import PublishArgsResolver +from resolver.update_args_resolver import UpdateArgsResolver +from resolver.push_args_resolver import PushArgsResolver from modules.interface.module_interface import ModuleInterface from modules.interface.build_module_interface import BuildModuleInterface @@ -46,12 +54,24 @@ from modules.interface.set_module_interface import SetModuleInterface from modules.interface.env_module_interface import EnvModuleInterface from modules.interface.clean_module_interface import CleanModuleInterface from modules.interface.tool_module_interface import ToolModuleInterface +from modules.interface.indep_build_module_interface import IndepBuildModuleInterface +from modules.interface.install_module_interface import InstallModuleInterface +from modules.interface.package_module_interface import PackageModuleInterface +from modules.interface.publish_module_interface import PublishModuleInterface +from modules.interface.update_module_interface import UpdateModuleInterface +from modules.interface.push_module_interface import PushModuleInterface from modules.ohos_build_module import OHOSBuildModule from modules.ohos_set_module import OHOSSetModule from modules.ohos_clean_module import OHOSCleanModule from modules.ohos_env_module import OHOSEnvModule from modules.ohos_tool_module import OHOSToolModule +from modules.ohos_indep_build_module import OHOSIndepBuildModule +from modules.ohos_install_module import OHOSInstallModule +from modules.ohos_package_module import OHOSPackageModule +from modules.ohos_publish_module import OHOSPublishModule +from modules.ohos_update_module import OHOSUpdateModule +from modules.ohos_push_module import OHOSPushModule from helper.separator import Separator from util.log_util import LogUtil @@ -101,13 +121,64 @@ class Main(): tool_args_resolever = ToolArgsResolver(args_dict) return OHOSToolModule(args_dict, tool_args_resolever, generate_ninja) + def _init_indep_build_module(self) -> IndepBuildModuleInterface: + Arg.clean_args_file_by_type(ModuleType.INDEP_BUILD) + args_dict = Arg.parse_all_args(ModuleType.INDEP_BUILD) + hpm = Hpm() + indep_build_args_resolver = IndepBuildArgsResolver(args_dict) + return OHOSIndepBuildModule(args_dict, indep_build_args_resolver, hpm) + + def _is_indep_build(self)-> bool: + if "--indep-build" in sys.argv[2:] or "-i" in sys.argv[2:]: + return True + env_args_dict = Arg.read_args_file(ModuleType.ENV) + return env_args_dict.get("indep_build").get("argDefault") + + def _init_install_module(self) -> InstallModuleInterface: + Arg.clean_args_file_by_type(ModuleType.INSTALL) + args_dict = Arg.parse_all_args(ModuleType.INSTALL) + hpm = Hpm() + install_args_resolver = InstallArgsResolver(args_dict) + return OHOSInstallModule(args_dict, install_args_resolver, hpm) + + def _init_package_module(self) -> PackageModuleInterface: + Arg.clean_args_file_by_type(ModuleType.PACKAGE) + args_dict = Arg.parse_all_args(ModuleType.PACKAGE) + hpm = Hpm() + package_args_resolver = PackageArgsResolver(args_dict) + return OHOSPackageModule(args_dict, package_args_resolver, hpm) + + def _init_publish_module(self) -> PublishModuleInterface: + args_dict = Arg.parse_all_args(ModuleType.PUBLISH) + hpm = Hpm() + publish_args_resolver = PublishArgsResolver(args_dict) + return OHOSPublishModule(args_dict, publish_args_resolver, hpm) + + def _init_update_module(self) -> UpdateModuleInterface: + Arg.clean_args_file_by_type(ModuleType.UPDATE) + args_dict = Arg.parse_all_args(ModuleType.UPDATE) + hpm = Hpm() + update_args_resolver = UpdateArgsResolver(args_dict) + return OHOSUpdateModule(args_dict, update_args_resolver, hpm) + + def _init_push_module(self) -> PushModuleInterface: + args_dict = Arg.parse_all_args(ModuleType.PUSH) + hdc = Hdc() + update_args_resolver = PushArgsResolver(args_dict) + return OHOSPushModule(args_dict, update_args_resolver, hdc) + @staticmethod @throw_exception def main(): main = Main() module_type = sys.argv[1] if module_type == 'build': - module = main._init_build_module() + if main._is_indep_build(): + module = main._init_indep_build_module() + else: + module = main._init_build_module() + elif module_type == "indep_build": + module = main._init_indep_build_module() elif module_type == 'set': module = main._init_set_module() elif module_type == 'env': @@ -116,6 +187,16 @@ class Main(): module = main._init_clean_module() elif module_type == 'tool': module = main._init_tool_module() + elif module_type == 'install': + module = main._init_install_module() + elif module_type == 'package': + module = main._init_package_module() + elif module_type == 'publish': + module = main._init_publish_module() + elif module_type == 'update': + module = main._init_update_module() + elif module_type == 'push': + module = main._init_push_module() elif module_type == 'help': for all_module_type in ModuleType: LogUtil.hb_info(Separator.long_line) diff --git a/hb/modules/interface/env_module_interface.py b/hb/modules/interface/env_module_interface.py index 7f44a4999ce7fb6557bd689999715e7a63885b90..922b9532fe70216b9551d06e0ce2b865bf8e4ff9 100644 --- a/hb/modules/interface/env_module_interface.py +++ b/hb/modules/interface/env_module_interface.py @@ -34,6 +34,11 @@ class EnvModuleInterface(ModuleInterface): def env_install(self): pass + @abstractmethod + def clean(self): + pass + def run(self): self.env_check() self.env_install() + self.clean() diff --git a/hb/modules/interface/indep_build_module_interface.py b/hb/modules/interface/indep_build_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..db7d9a763ec994999c4c95d7294a17aefe6adcbc --- /dev/null +++ b/hb/modules/interface/indep_build_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class IndepBuildModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _target_compilation(self): + pass + + def run(self): + try: + self._target_compilation() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/interface/install_module_interface.py b/hb/modules/interface/install_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..e5a3754db717ea380a9c6cbd71767f8d58ce9376 --- /dev/null +++ b/hb/modules/interface/install_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class InstallModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _install(self): + pass + + def run(self): + try: + self._install() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/interface/package_module_interface.py b/hb/modules/interface/package_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..b6df5f6b9c853bef207bf40a8c06c52264941de7 --- /dev/null +++ b/hb/modules/interface/package_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class PackageModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _package(self): + pass + + def run(self): + try: + self._package() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/interface/publish_module_interface.py b/hb/modules/interface/publish_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..ef07749006e25bf141605a0d4cc21f30c0885e50 --- /dev/null +++ b/hb/modules/interface/publish_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class PublishModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _publish(self): + pass + + def run(self): + try: + self._publish() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/interface/push_module_interface.py b/hb/modules/interface/push_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..2358a9f09117a72dc208c39ca3a900e363412f92 --- /dev/null +++ b/hb/modules/interface/push_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class PushModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _push(self): + pass + + def run(self): + try: + self._push() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/interface/update_module_interface.py b/hb/modules/interface/update_module_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..a1b5154c67bff6dccc515eca72fafe38de7d7ab9 --- /dev/null +++ b/hb/modules/interface/update_module_interface.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from abc import abstractmethod +from exceptions.ohos_exception import OHOSException +from modules.interface.module_interface import ModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface + + +class UpdateModuleInterface(ModuleInterface): + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface): + super().__init__(args_dict, args_resolver) + + @abstractmethod + def _update(self): + pass + + def run(self): + try: + self._update() + except OHOSException as exception: + raise exception \ No newline at end of file diff --git a/hb/modules/ohos_env_module.py b/hb/modules/ohos_env_module.py index 3d4f233b92652e2bbe8a9b8dffef6721017314c2..6a9d65745dbfad979cfa545884ed4e063cb1458e 100644 --- a/hb/modules/ohos_env_module.py +++ b/hb/modules/ohos_env_module.py @@ -37,7 +37,12 @@ class OHOSEnvModule(EnvModuleInterface): 'OHOSEnvModule has not been instantiated', '0000') def env_check(self): - self.args_resolver.resolve_arg(self.args_dict['check'], self) + if not self.args_dict['indep_build'].arg_value: + self.args_resolver.resolve_arg(self.args_dict['check'], self) def env_install(self): - self.args_resolver.resolve_arg(self.args_dict['install'], self) + if not self.args_dict['indep_build'].arg_value: + self.args_resolver.resolve_arg(self.args_dict['install'], self) + + def clean(self): + self.args_resolver.resolve_arg(self.args_dict['clean'],self) \ No newline at end of file diff --git a/hb/modules/ohos_indep_build_module.py b/hb/modules/ohos_indep_build_module.py new file mode 100644 index 0000000000000000000000000000000000000000..74fa07e4f750ce2aba0c32bb9247f1fe7685842d --- /dev/null +++ b/hb/modules/ohos_indep_build_module.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from modules.interface.indep_build_module_interface import IndepBuildModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSIndepBuildModule(IndepBuildModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hpm = hpm + OHOSIndepBuildModule._instance = self + + @staticmethod + def get_instance(): + if OHOSIndepBuildModule._instance is not None: + return OHOSIndepBuildModule._instance + else: + raise OHOSException( + 'OHOSIndepBuildModule has not been instantiated', '0000') + + @property + def hpm(self): + return self._hpm + + def _target_compilation(self): + self._run_phase() + self.hpm.run() + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('{} build success') + + def _run_phase(self): + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) \ No newline at end of file diff --git a/hb/modules/ohos_install_module.py b/hb/modules/ohos_install_module.py new file mode 100644 index 0000000000000000000000000000000000000000..86a9caf3948f38ba1766447faa59431d93c936c1 --- /dev/null +++ b/hb/modules/ohos_install_module.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from services.hpm import CMDTYPE +from modules.interface.install_module_interface import InstallModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSInstallModule(InstallModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hpm = hpm + OHOSInstallModule._instance = self + + @staticmethod + def get_instance(): + if OHOSInstallModule._instance is not None: + return OHOSInstallModule._instance + else: + raise OHOSException( + 'OHOSInstallModule has not been instantiated', '0000') + + @property + def hpm(self): + return self._hpm + + def _install(self): + self._run_phase() + self.hpm.execute_hpm_cmd(CMDTYPE.INSTALL) + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('{} build success') + + def _run_phase(self): + #if not self.args_dict.get("global").arg_value: + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) \ No newline at end of file diff --git a/hb/modules/ohos_package_module.py b/hb/modules/ohos_package_module.py new file mode 100644 index 0000000000000000000000000000000000000000..441958db7d895195f8ee2f6516e5dc516bf554a2 --- /dev/null +++ b/hb/modules/ohos_package_module.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from services.hpm import CMDTYPE +from modules.interface.package_module_interface import PackageModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSPackageModule(PackageModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hpm = hpm + OHOSPackageModule._instance = self + + @staticmethod + def get_instance(): + if OHOSPackageModule._instance is not None: + return OHOSPackageModule._instance + else: + raise OHOSException( + 'OHOSPackageModule has not been instantiated', '0000') + + @property + def hpm(self): + return self._hpm + + def _package(self): + self._run_phase() + self.hpm.execute_hpm_cmd(CMDTYPE.PACKAGE) + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('hb package failed') + + def _run_phase(self): + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) \ No newline at end of file diff --git a/hb/modules/ohos_publish_module.py b/hb/modules/ohos_publish_module.py new file mode 100644 index 0000000000000000000000000000000000000000..051774527f1588823bb5836b787b3d3ea6098d05 --- /dev/null +++ b/hb/modules/ohos_publish_module.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from services.hpm import CMDTYPE +from modules.interface.publish_module_interface import PublishModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSPublishModule(PublishModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hpm = hpm + OHOSPublishModule._instance = self + + @staticmethod + def get_instance(): + if OHOSPublishModule._instance is not None: + return OHOSPublishModule._instance + else: + raise OHOSException( + 'OHOSPublishModule has not been instantiated', '0000') + + @property + def hpm(self): + return self._hpm + + def _publish(self): + self._run_phase() + self.hpm.execute_hpm_cmd(CMDTYPE.PUBLISH) + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('hb publish failed') + + def _run_phase(self): + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) \ No newline at end of file diff --git a/hb/modules/ohos_push_module.py b/hb/modules/ohos_push_module.py new file mode 100644 index 0000000000000000000000000000000000000000..342baf4aeee351e1b33cbcd913e3d9d92819ac28 --- /dev/null +++ b/hb/modules/ohos_push_module.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from services.hdc import CMDTYPE +from modules.interface.push_module_interface import PushModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSPushModule(PushModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hdc: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hdc = hdc + OHOSPushModule._instance = self + + @staticmethod + def get_instance(): + if OHOSPushModule._instance is not None: + return OHOSPushModule._instance + else: + raise OHOSException( + 'OHOSPushModule has not been instantiated', '0000') + + @property + def hdc(self): + return self._hdc + + def _push(self): + self._run_phase() + + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('hb push failed') + + def _run_phase(self): + if self.args_dict['list_targets'].arg_value: + self.args_resolver.resolve_arg(self.args_dict["list_targets"], self) + else: + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) + self.hdc.execute_hdc_cmd(CMDTYPE.PUSH) \ No newline at end of file diff --git a/hb/modules/ohos_update_module.py b/hb/modules/ohos_update_module.py new file mode 100644 index 0000000000000000000000000000000000000000..96888a8fda0c4dd80b3b809c931e8b06f9309169 --- /dev/null +++ b/hb/modules/ohos_update_module.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. +# + +from services.hpm import CMDTYPE +from modules.interface.update_module_interface import UpdateModuleInterface +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from util.log_util import LogUtil +from containers.status import throw_exception + + +class OHOSUpdateModule(UpdateModuleInterface): + + _instance = None + + def __init__(self, args_dict: dict, args_resolver: ArgsResolverInterface, hpm: BuildFileGeneratorInterface): + super().__init__(args_dict, args_resolver) + self._hpm = hpm + OHOSUpdateModule._instance = self + + @staticmethod + def get_instance(): + if OHOSUpdateModule._instance is not None: + return OHOSUpdateModule._instance + else: + raise OHOSException( + 'OHOSUpdateModule has not been instantiated', '0000') + + @property + def hpm(self): + return self._hpm + + def _update(self): + self._run_phase() + self.hpm.execute_hpm_cmd(CMDTYPE.UPDATE) + + @throw_exception + def run(self): + try: + super().run() + except OHOSException as exception: + raise exception + else: + LogUtil.hb_info('hb update failed') + + def _run_phase(self): + for arg in self.args_dict.values(): + self.args_resolver.resolve_arg(arg, self) \ No newline at end of file diff --git a/hb/resolver/env_args_resolver.py b/hb/resolver/env_args_resolver.py index 050287f1364b622726e2b4e805fade70d7e51d91..35d255db9d47db2c11d89040514fb916e0228eab 100644 --- a/hb/resolver/env_args_resolver.py +++ b/hb/resolver/env_args_resolver.py @@ -19,7 +19,7 @@ import os import subprocess -from containers.arg import Arg +from containers.arg import Arg, ModuleType from resolver.interface.args_resolver_interface import ArgsResolverInterface from modules.interface.env_module_interface import EnvModuleInterface from resources.global_var import ENV_SETUP_FILE, ROOT_CONFIG_FILE, BUILD_CONFIG_FILE @@ -86,3 +86,20 @@ class EnvArgsResolver(ArgsResolverInterface): subprocess.run('bash {}'.format(ENV_SETUP_FILE)) else: raise OHOSException("There is no {} file", "0000") + + @staticmethod + def resolve_target_cpu(target_arg: Arg, env_module: EnvModuleInterface): + pass + + @staticmethod + def resolve_target_os(target_arg: Arg, env_module: EnvModuleInterface): + pass + + @staticmethod + def resolve_part(target_arg: Arg, env_module: EnvModuleInterface): + pass + + @staticmethod + def resolve_clean(target_arg: Arg, env_module: EnvModuleInterface): + if target_arg.arg_value: + Arg.clean_args_file_by_type(ModuleType.ENV) \ No newline at end of file diff --git a/hb/resolver/indep_build_args_resolver.py b/hb/resolver/indep_build_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..dcf63b7f89859aab14d92e54fbad77adf9deec56 --- /dev/null +++ b/hb/resolver/indep_build_args_resolver.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.indep_build_module_interface import IndepBuildModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException + +class IndepBuildArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_target_cpu(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): + build_executor = indep_build_module.hpm + if target_arg.arg_value: + build_executor.regist_flag('cpu', target_arg.arg_value) + else: + args_dict = Arg.read_args_file(ModuleType.ENV) + arg = args_dict.get("target_cpu") + build_executor.regist_flag('cpu', arg.get("argDefault")) + + @staticmethod + def resolve_target_os(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): + build_executor = indep_build_module.hpm + if target_arg.arg_value: + build_executor.regist_flag('os', target_arg.arg_value) + else: + args_dict = Arg.read_args_file(ModuleType.ENV) + arg = args_dict.get("target_os") + build_executor.regist_flag('os', arg.get("argDefault")) + + @staticmethod + def resolve_part(target_arg: Arg, indep_build_module: IndepBuildModuleInterface): + ''' + 编译部件名获取优先级: hb build 指定的部件名参数 > hb build 在部件源码仓运行时通过找到bundle.json获取到的部件名 > hb env 设置的部件名参数 + ''' + build_executor = indep_build_module.hpm + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + target_arg.arg_value = sys.argv[2] + + if target_arg.arg_value: + bundle_path = ComponentUtil.search_bundle_file(target_arg.arg_value) + if not bundle_path: + raise OHOSException('ERROR argument "hb build ": Invalid part_name "{}". '.format(target_arg.arg_value)) + build_executor.regist_flag('path', bundle_path) + elif ComponentUtil.is_in_component_dir(os.getcwd()): + part_name, bundle_path = ComponentUtil.get_component(os.getcwd()) + if part_name: + target_arg.arg_value = part_name + build_executor.regist_flag('path', bundle_path) + else: + raise OHOSException('ERROR argument "no bundle.json": Invalid directory "{}". '.format(os.getcwd())) + else: + args_dict = Arg.read_args_file(ModuleType.ENV) + arg = args_dict.get("part") + if arg.get("argDefault"): + bundle_path = ComponentUtil.search_bundle_file(arg.get("argDefault")) + if not bundle_path: + raise OHOSException('ERROR argument "hb env --part ": Invalid part_name "{}". '.format(target_arg.arg_value)) + build_executor.regist_flag('path', bundle_path) + else: + raise OHOSException('ERROR argument "hb build ": no part_name . ') diff --git a/hb/resolver/install_args_resolver.py b/hb/resolver/install_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..e6d2a420c44ccb6aa6f8e5582a8d7454b8030e4f --- /dev/null +++ b/hb/resolver/install_args_resolver.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.install_module_interface import InstallModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException +from services.hpm import CMDTYPE + +class InstallArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_part(target_arg: Arg, install_module: InstallModuleInterface): + part_name = target_arg.arg_value + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + part_name = sys.argv[2] + if part_name: + install_module.hpm.regist_flag('part_name', part_name) + + + @staticmethod + def resolve_global(target_arg: Arg, install_module: InstallModuleInterface): + if target_arg.arg_value == True or target_arg.arg_value == '': + install_module.hpm.regist_flag('global', '') + + @staticmethod + def resolve_local(target_arg: Arg, install_module: InstallModuleInterface): + if target_arg.arg_value: + install_module.hpm.regist_flag('local', target_arg.arg_value) \ No newline at end of file diff --git a/hb/resolver/package_args_resolver.py b/hb/resolver/package_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..d9f60012bbfca6b21039366b40d20037239f9c35 --- /dev/null +++ b/hb/resolver/package_args_resolver.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.package_module_interface import PackageModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException +from services.hpm import CMDTYPE + +class PackageArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_part(target_arg: Arg, package_module: PackageModuleInterface): + part_name = target_arg.arg_value + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + part_name = sys.argv[2] + if part_name: + package_module.hpm.regist_flag('part_name', part_name) + + + @staticmethod + def resolve_output(target_arg: Arg, package_module: PackageModuleInterface): + if target_arg.arg_value: + package_module.hpm.regist_flag('output', target_arg.arg_value) \ No newline at end of file diff --git a/hb/resolver/publish_args_resolver.py b/hb/resolver/publish_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..be0e644f38ac4a770457689d9fe9d131ae192be5 --- /dev/null +++ b/hb/resolver/publish_args_resolver.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.publish_module_interface import PublishModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException +from services.hpm import CMDTYPE + +class PublishArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_part(target_arg: Arg, publish_module: PublishModuleInterface): + part_name = target_arg.arg_value + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + part_name = sys.argv[2] + if part_name: + publish_module.hpm.regist_flag('part_name', part_name) diff --git a/hb/resolver/push_args_resolver.py b/hb/resolver/push_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..f50ba03e651946337c625268768e3b0d644f4972 --- /dev/null +++ b/hb/resolver/push_args_resolver.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.push_module_interface import PushModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException +from services.hdc import CMDTYPE + +class PushArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_part(target_arg: Arg, push_module: PushModuleInterface): + part_name = target_arg.arg_value + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + part_name = sys.argv[2] + if part_name: + push_module.hdc.regist_flag('part_name', part_name) + + @staticmethod + def resolve_target(target_arg: Arg, push_module: PushModuleInterface): + if target_arg.arg_value: + push_module.hdc.regist_flag('target', target_arg.arg_value) + else: + raise OHOSException('ERROR argument "hb push no target set". ') + + @staticmethod + def resolve_list_targets(target_arg: Arg, push_module: PushModuleInterface): + if target_arg.arg_value: + push_module.hdc.execute_hdc_cmd(CMDTYPE.LIST_TARGETS) + Arg.write_args_file("list_targets",False,ModuleType.PUSH) + + @staticmethod + def resolve_reboot(target_arg: Arg, push_module: PushModuleInterface): + if target_arg.arg_value: + push_module.hdc.regist_flag('reboot',True) + + @staticmethod + def resolve_src(target_arg: Arg, push_module: PushModuleInterface): + if target_arg.arg_value: + push_module.hdc.regist_flag('src',target_arg.arg_value) + Arg.write_args_file("src","",ModuleType.PUSH) \ No newline at end of file diff --git a/hb/resolver/update_args_resolver.py b/hb/resolver/update_args_resolver.py new file mode 100644 index 0000000000000000000000000000000000000000..ee30cdb3cf27201f557b53bb934a2e12c426e595 --- /dev/null +++ b/hb/resolver/update_args_resolver.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 os +import sys + +from containers.arg import Arg +from containers.arg import ModuleType +from resolver.interface.args_resolver_interface import ArgsResolverInterface +from modules.interface.update_module_interface import UpdateModuleInterface +from util.component_util import ComponentUtil +from exceptions.ohos_exception import OHOSException +from services.hpm import CMDTYPE + +class UpdateArgsResolver(ArgsResolverInterface): + + def __init__(self, args_dict: dict): + super().__init__(args_dict) + + @staticmethod + def resolve_part(target_arg: Arg, update_module: UpdateModuleInterface): + part_name = target_arg.arg_value + if len(sys.argv) > 2 and not sys.argv[2].startswith("-"): # 第一个部件名参数 + part_name = sys.argv[2] + if part_name: + update_module.hpm.regist_flag('part_name', part_name) + + @staticmethod + def resolve_global(target_arg: Arg, update_module: UpdateModuleInterface): + if target_arg.arg_value == True or target_arg.arg_value == '': + update_module.hpm.regist_flag('global', '') \ No newline at end of file diff --git a/hb/resources/args/default/envargs.json b/hb/resources/args/default/envargs.json index b86db9d15f4a525d1582e5e124cebe1d4b4c87d6..7e90eec68732220da537ee3ad1f46b79bc4dbce0 100644 --- a/hb/resources/args/default/envargs.json +++ b/hb/resources/args/default/envargs.json @@ -1,4 +1,16 @@ { + "clean": { + "arg_name": "--clean", + "argDefault": false, + "arg_help": "Default:false. Help: clean all env args", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-l" + }, + "resolve_function": "resolve_clean", + "testFunction": "testClean" + }, "check": { "arg_name": "--check", "argDefault": true, @@ -19,5 +31,65 @@ "arg_attribute": {}, "resolve_function": "resolve_install", "testFunction": "TestInstall" - } + }, + "indep_build": { + "arg_name": "--indep-build", + "argDefault": false, + "arg_help": "Default:false. Help: switch to independent build", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-i" + }, + "resolve_function": "resolve_install", + "testFunction": "TestInstall" + }, + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:Specify component name, run 'hb env --part {part_name}' ", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "target_cpu": { + "arg_name": "--target-cpu", + "argDefault": "arm", + "arg_help": "Default:'arm'. Help:Specifies the desired cpu architecture for the build, each may support different cpu architectures, run 'hb env --target-cpu {cpu_architectures}' to set cpu architectures", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "optional": [ + "arm", + "arm64", + "x86_64", + "x64", + "mipsel", + "riscv64" + ] + }, + "resolve_function": "resolve_target_cpu", + "testFunction": "testBuildTargetCpu" + }, + "target_os": { + "arg_name": "--target-os", + "argDefault": "linux", + "arg_help": "Default:''. Help:Specifies the desired os type for the build, each may support different os type, run 'hb env --target-os {os_type}' to set os type", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "optional": [ + "android", + "ohos", + "mac", + "linux", + "windows" + ] + }, + "resolve_function": "resolve_target_os", + "testFunction": "testBuildTargetOs" + } } \ No newline at end of file diff --git a/hb/resources/args/default/indepbuildargs.json b/hb/resources/args/default/indepbuildargs.json new file mode 100644 index 0000000000000000000000000000000000000000..0cb9afc1afc3e5ee4c519d2cbe79a75fadc1f2a6 --- /dev/null +++ b/hb/resources/args/default/indepbuildargs.json @@ -0,0 +1,50 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify component name, run 'hb build {part_name} or hb build --part {part_name}'", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "target_cpu": { + "arg_name": "--target-cpu", + "argDefault": "", + "arg_help": "Default:''. Help:Specifies the desired cpu architecture for the build, each may support different cpu architectures, run 'hb build --target-cpu {cpu_architectures}' to set os type cpu architectures", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "optional": [ + "arm", + "arm64", + "x86_64", + "x64", + "mipsel", + "riscv64" + ] + }, + "resolve_function": "resolve_target_cpu", + "testFunction": "" + }, + "target_os": { + "arg_name": "--target-os", + "argDefault": "", + "arg_help": "Default:''. Help:Specifies the desired os type for the build, each may support different os type, run 'hb build --target-os {os_type}' to set os type", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "optional": [ + "android", + "ohos", + "mac", + "linux", + "windows" + ] + }, + "resolve_function": "resolve_target_os", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/args/default/installargs.json b/hb/resources/args/default/installargs.json new file mode 100644 index 0000000000000000000000000000000000000000..f2d3e100459691a7ffebec9e740cf6a5c2a51617 --- /dev/null +++ b/hb/resources/args/default/installargs.json @@ -0,0 +1,37 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify package name, run 'hb install {package_name} or hb install --part {package_name}'", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "global": { + "arg_name": "--global", + "argDefault": false, + "arg_help": "Default:false. Help:global install, run 'hb install {package_name} --global'", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-g" + }, + "resolve_function": "resolve_global", + "testFunction": "testCheck" + }, + "local": { + "arg_name": "--local", + "argDefault": "", + "arg_help": "Default:''. Help:install local package file, run 'hb install --local {package_path}'", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "abbreviation": "-l" + }, + "resolve_function": "resolve_local", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/args/default/packageargs.json b/hb/resources/args/default/packageargs.json new file mode 100644 index 0000000000000000000000000000000000000000..adef03b33651a1cae7ca04f983791928752f433d --- /dev/null +++ b/hb/resources/args/default/packageargs.json @@ -0,0 +1,25 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify component name, run 'hb package or hb package --part '", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "output": { + "arg_name": "--output", + "argDefault": "", + "arg_help": "Default:''. Help:specify the output directory, which is generated by default in the current directory", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "abbreviation": "-o" + }, + "resolve_function": "resolve_output", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/args/default/publishargs.json b/hb/resources/args/default/publishargs.json new file mode 100644 index 0000000000000000000000000000000000000000..3e31257ba707b325e0da7914bddc55b86f5aa62a --- /dev/null +++ b/hb/resources/args/default/publishargs.json @@ -0,0 +1,13 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify component name, run 'hb publish {part_name} or hb publish --part {part_name}' to xxxxxx", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/args/default/pushargs.json b/hb/resources/args/default/pushargs.json new file mode 100644 index 0000000000000000000000000000000000000000..58b4d3828c7efa75044a49fcc8eb326aaf7eedbf --- /dev/null +++ b/hb/resources/args/default/pushargs.json @@ -0,0 +1,61 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify component name, run 'hb push {part_name} or hb push --part {part_name}' ", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "target": { + "arg_name": "--target", + "argDefault": "", + "arg_help": "Default:''. Help:specify target name, run 'hb push -t {target_number} or hb push --target {target_number}' ", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "abbreviation": "-t" + }, + "resolve_function": "resolve_target", + "testFunction": "" + }, + "list_targets": { + "arg_name": "--list-targets", + "argDefault": false, + "arg_help": "Default:''. Help:list all target, run 'hb push --list-targets or hb push -l ' ", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-l" + }, + "resolve_function": "resolve_list_targets", + "testFunction": "" + }, + "src": { + "arg_name": "--src", + "argDefault": "", + "arg_help": "Default:''. Help:specify hdc send file, run 'hb push --src or hb push -s' ", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + "abbreviation": "-s" + }, + "resolve_function": "resolve_src", + "testFunction": "" + }, + "reboot": { + "arg_name": "--reboot", + "argDefault": false, + "arg_help": "Default:''. Help:reboot device, run 'hb push --reboot or hb push -r ' ", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-r" + }, + "resolve_function": "resolve_reboot", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/args/default/updateargs.json b/hb/resources/args/default/updateargs.json new file mode 100644 index 0000000000000000000000000000000000000000..b33ad51bdb5118c8307fdd6c6b4eb41a75ec3b7a --- /dev/null +++ b/hb/resources/args/default/updateargs.json @@ -0,0 +1,25 @@ +{ + "part": { + "arg_name": "--part", + "argDefault": "", + "arg_help": "Default:''. Help:specify component name, run 'hb update {part_name} or hb update --part {part_name}' ", + "arg_phase": "prebuild", + "arg_type": "str", + "arg_attribute": { + }, + "resolve_function": "resolve_part", + "testFunction": "" + }, + "global": { + "arg_name": "--global", + "argDefault": false, + "arg_help": "Default:false. Help:global update, run 'hb update {part_name} --global'", + "arg_phase": "prebuild", + "arg_type": "bool", + "arg_attribute": { + "abbreviation": "-g" + }, + "resolve_function": "resolve_global", + "testFunction": "" + } +} \ No newline at end of file diff --git a/hb/resources/global_var.py b/hb/resources/global_var.py index f21251da9e46223c50ca59b0315feb0816104d82..3507ea13834cb8908e41ed24c4fd665ef157f6cf 100644 --- a/hb/resources/global_var.py +++ b/hb/resources/global_var.py @@ -38,6 +38,24 @@ DEFAULT_ENV_ARGS = os.path.join( DEFAULT_TOOL_ARGS = os.path.join( CURRENT_HB_DIR, 'resources/args/default/toolargs.json') +DEFAULT_INDEP_BUILD_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/indepbuildargs.json') + +DEFAULT_INSTALL_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/installargs.json') + +DEFAULT_PACKAGE_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/packageargs.json') + +DEFAULT_PUBLISH_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/publishargs.json') + +DEFAULT_UPDATE_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/updateargs.json') + +DEFAULT_PUSH_ARGS = os.path.join( + CURRENT_HB_DIR, 'resources/args/default/pushargs.json') + CURRENT_ARGS_DIR = os.path.join(CURRENT_OHOS_ROOT, 'out/hb_args') CURRENT_BUILD_ARGS = os.path.join( CURRENT_ARGS_DIR, 'buildargs.json') @@ -49,6 +67,18 @@ CURRENT_ENV_ARGS = os.path.join( CURRENT_ARGS_DIR, 'envargs.json') CURRENT_TOOL_ARGS = os.path.join( CURRENT_ARGS_DIR, 'toolargs.json') +CURRENT_INDEP_BUILD_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'indepbuildargs.json') +CURRENT_INSTALL_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'installargs.json') +CURRENT_PACKAGE_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'packageargs.json') +CURRENT_PUBLISH_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'publishargs.json') +CURRENT_UPDATE_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'updateargs.json') +CURRENT_PUSH_ARGS = os.path.join( + CURRENT_ARGS_DIR, 'pushargs.json') BUILD_CONFIG_FILE = os.path.join( CURRENT_HB_DIR, 'resources/config/config.json') @@ -57,3 +87,5 @@ STATUS_FILE = os.path.join(CURRENT_HB_DIR, 'resources/status/status.json') ENV_SETUP_FILE = os.path.join( CURRENT_BUILD_DIR, 'build_scripts', 'env_setup.sh') + +COMPONENTS_PATH_DIR = os.path.join(CURRENT_OHOS_ROOT, 'out/components_path.json') \ No newline at end of file diff --git a/hb/services/hdc.py b/hb/services/hdc.py new file mode 100644 index 0000000000000000000000000000000000000000..72cd2041107486e1c6d3d72680966f6d637a290c --- /dev/null +++ b/hb/services/hdc.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 shutil +import sys +import os +import time +import threading +import subprocess +from enum import Enum + +from containers.status import throw_exception +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from containers.arg import Arg, ModuleType +from util.system_util import SystemUtil +from util.io_util import IoUtil +from util.log_util import LogUtil +from util.component_util import ComponentUtil + +class CMDTYPE(Enum): + PUSH = 1 + LIST_TARGETS = 2 +class Hdc(BuildFileGeneratorInterface): + + def __init__(self): + super().__init__() + self._regist_hdc_path() + self._regist_hpm_cache() + + def run(self): + self.execute_hdc_cmd(CMDTYPE.PUSH) + + @throw_exception + def execute_hdc_cmd(self, cmd_type: int, **kwargs): + if cmd_type == CMDTYPE.PUSH: + return self._execute_hdc_push_cmd() + elif cmd_type == CMDTYPE.LIST_TARGETS: + return self._execute_hdc_list_targets_cmd() + else: + raise OHOSException( + 'You are tring to use an unsupported hdc cmd type "{}"'.format(cmd_type), '3001') + + + @throw_exception + def _regist_hdc_path(self): + hdc_path = shutil.which("hdc") + if os.path.exists(hdc_path): + self.exec = hdc_path + else: + raise OHOSException( + 'There is no hdc executable file at {}'.format(hdc_path), '0001') + + @throw_exception + def _regist_hpm_cache(self): + self.hpm_config_path = "~/.hpm" + hpm_path = shutil.which("hpm") + if os.path.exists(hpm_path): + command = [ hpm_path, "config", "get", "modelRepository" ] + output = subprocess.check_output(command) + if output: + self.hpm_config_path = output.decode('utf-8').rstrip("\n") + + + + # 通过部件名获取部件二进制路径 + def get_send_file(self, part_name): + srcs = [] + target = "" + bundle_file = os.path.join(self.hpm_config_path,'.hpmcache/binarys/subsystem', part_name, "bundle.json") + if not os.path.exists(bundle_file): + return srcs, target + bundle_info = IoUtil.read_json_file(bundle_file) + deployment = bundle_info.get("deployment") + if deployment: + src = deployment.get("src","") + target = deployment.get("target","") + if not src.startswith("/"): + src = os.path.join(os.path.dirname(bundle_file),src) + srcs = get_files_by_path(src) + return srcs , target + @throw_exception + def _execute_hdc_push_cmd(self, **kwargs): + connect_key = self.flags_dict.get("target") + # mount + hdc_mount_cmd = [ self.exec, '-t', connect_key, 'shell', 'mount', '-o', 'rw,remount', '/' ] + SystemUtil.exec_command(hdc_mount_cmd) + # parse part_name + part_name = self.flags_dict.get("part_name") + send_files, target = self.get_send_file(part_name) + send_src = self.flags_dict.get("src") + if send_src: + send_files = get_files_by_path(send_src) + # send file + for send_file in send_files: + hdc_push_cmd = [self.exec, "-t", connect_key, "file", "send", send_file, os.path.join(target,os.path.basename(send_file)) ] + SystemUtil.exec_command(hdc_push_cmd) + hdc_push_chown_cmd = [ self.exec , "-t", connect_key, "shell", "chown", "root:root", os.path.join(target,os.path.basename(send_file)) ] + SystemUtil.exec_command(hdc_push_chown_cmd) + + # reboot + if self.flags_dict.get("reboot"): + hdc_reboot_cmd = [ self.exec , '-t', connect_key , 'shell', 'reboot'] + SystemUtil.exec_command(hdc_reboot_cmd) + + @throw_exception + def _execute_hdc_list_targets_cmd(self, **kwargs): + hdc_list_targets_cmd = [self.exec, "list", "targets" ] + SystemUtil.exec_command(hdc_list_targets_cmd) + + +def get_files_by_path(path): + output = [] + if os.path.isdir(path): + for root, dirnames, filenames in os.walk(path): + for filename in filenames: + output.append(os.path.join(root,filename)) + else: + output.append(path) + return output \ No newline at end of file diff --git a/hb/services/hpm.py b/hb/services/hpm.py new file mode 100644 index 0000000000000000000000000000000000000000..14115d7689ab26a96b27d73371569096c7c931e4 --- /dev/null +++ b/hb/services/hpm.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 shutil +import sys +import os +import time +import threading +from enum import Enum + +from containers.status import throw_exception +from exceptions.ohos_exception import OHOSException +from services.interface.build_file_generator_interface import BuildFileGeneratorInterface +from containers.arg import Arg, ModuleType +from util.system_util import SystemUtil +from util.io_util import IoUtil +from util.log_util import LogUtil +from util.component_util import ComponentUtil + +class CMDTYPE(Enum): + BUILD = 1 + INSTALL = 2 + PACKAGE = 3 + PUBLISH = 4 + UPDATE = 5 + +class Hpm(BuildFileGeneratorInterface): + + def __init__(self): + super().__init__() + self._regist_hpm_path() + + def run(self): + self.execute_hpm_cmd(CMDTYPE.BUILD) + + @throw_exception + def execute_hpm_cmd(self, cmd_type: int, **kwargs): + if cmd_type == CMDTYPE.BUILD: + return self._execute_hpm_build_cmd() + elif cmd_type == CMDTYPE.INSTALL: + return self._execute_hpm_install_cmd() + elif cmd_type == CMDTYPE.PACKAGE: + return self._execute_hpm_pack_cmd() + elif cmd_type == CMDTYPE.PUBLISH: + return self._execute_hpm_publish_cmd() + elif cmd_type == CMDTYPE.UPDATE: + return self._execute_hpm_update_cmd() + else: + raise OHOSException( + 'You are tring to use an unsupported hpm cmd type "{}"'.format(cmd_type), '3001') + + '''Description: Get hpm excutable path and regist it + @parameter: none + @return: Status + ''' + + @throw_exception + def _regist_hpm_path(self): + hpm_path = shutil.which("hpm") + if os.path.exists(hpm_path): + self.exec = hpm_path + else: + raise OHOSException( + 'There is no hpm executable file at {}'.format(hpm_path), '0001') + + '''Description: Convert all registed args into a list + @parameter: none + @return: list of all registed args + ''' + + def _convert_args(self) -> list: + args_list = [] + + for key, value in self.args_dict.items(): + if isinstance(value, bool): + args_list.append('{}={}'.format(key, str(value).lower())) + + elif isinstance(value, str): + args_list.append('{}="{}"'.format(key, value)) + + elif isinstance(value, int): + args_list.append('{}={}'.format(key, value)) + + elif isinstance(value, list): + args_list.append('{}="{}"'.format(key, "&&".join(value))) + + return args_list + + '''Description: Convert all registed flags into a list + @parameter: none + @return: list of all registed flags + ''' + + def _convert_flags(self) -> list: + flags_list = [] + + for key, value in self.flags_dict.items(): + # 部件参数无需参数名 + if key == "part_name": + flags_list.append(str(value)) + else: + if value == '': + flags_list.append('--{}'.format(key)) + else: + flags_list.extend(['--{}'.format(key).lower(), '{}'.format(str(value)).lower()]) + + return flags_list + + + def _check_parts_validity(self, components:list): + illegal_components = [] + for component in components: + if not ComponentUtil.search_bundle_file(component): + illegal_components.append(component) + if illegal_components: + raise OHOSException('ERROR argument "--parts": Invalid parts "{}". '.format(illegal_components)) + + @throw_exception + def _execute_hpm_build_cmd(self, **kwargs): + hpm_build_cmd = [self.exec, "build" ] + self._convert_flags() + SystemUtil.exec_command(hpm_build_cmd) + + + + @throw_exception + def _execute_hpm_install_cmd(self, **kwargs): + hpm_install_cmd = [self.exec, "install" ] + self._convert_flags() + SystemUtil.exec_command(hpm_install_cmd) + + @throw_exception + def _execute_hpm_pack_cmd(self, **kwargs): + hpm_pack_cmd = [self.exec, "pack" ] + self._convert_flags() + SystemUtil.exec_command(hpm_pack_cmd) + + @throw_exception + def _execute_hpm_publish_cmd(self, **kwargs): + hpm_publish_cmd = [self.exec, "publish" ] + self._convert_flags() + SystemUtil.exec_command(hpm_publish_cmd) + + @throw_exception + def _execute_hpm_update_cmd(self, **kwargs): + hpm_update_cmd = [self.exec, "update" ] + self._convert_flags() + SystemUtil.exec_command(hpm_update_cmd) + \ No newline at end of file diff --git a/hb/util/component_util.py b/hb/util/component_util.py index 7dff91e2917a9f1271a6c05e6dded89ad37ed67c..cc4c8abc2884e76c60ccf73d0ab85f48c7fb6a4d 100644 --- a/hb/util/component_util.py +++ b/hb/util/component_util.py @@ -19,6 +19,7 @@ import os import re from resources.global_var import CURRENT_OHOS_ROOT +from resources.global_var import COMPONENTS_PATH_DIR from exceptions.ohos_exception import OHOSException from util.io_util import IoUtil from containers.status import throw_exception @@ -49,6 +50,15 @@ class ComponentUtil(): return '' + @staticmethod + def get_component(path: str) -> str: + found_bundle_file, bundle_path = _recurrent_search_bundle_file(path) + if found_bundle_file: + data = IoUtil.read_json_file(bundle_path) + return data['component']['name'] , os.path.dirname(bundle_path) + + return '' , '' + @staticmethod @throw_exception def get_component_module_full_name(out_path: str, component_name: str, module_name: str) -> str: @@ -80,6 +90,10 @@ class ComponentUtil(): raise OHOSException('You are trying to compile a module {} which do not exists in {} while compiling {}'.format( module_name, component_name, out_path), "4001") + @staticmethod + def search_bundle_file(component_name: str): + all_bundle_path = get_all_bundle_path(CURRENT_OHOS_ROOT) + return all_bundle_path.get(component_name) def _recurrent_search_bundle_file(path: str): cur_dir = path @@ -90,3 +104,19 @@ def _recurrent_search_bundle_file(path: str): return True, bundle_json cur_dir = os.path.dirname(cur_dir) return False, '' + +def get_all_bundle_path(path): + if os.path.exists(COMPONENTS_PATH_DIR): + return IoUtil.read_json_file(COMPONENTS_PATH_DIR) + bundles_path = {} + for root, dirnames, filenames in os.walk(path): + if root == os.path.join(path,"out") or root == os.path.join(path,".repo"): + continue + for filename in filenames: + if filename == "bundle.json": + bundle_json = os.path.join(root,filename) + data = IoUtil.read_json_file(bundle_json) + if data.get("component") and data.get("component").get("name"): + bundles_path[data["component"]["name"]] = os.path.dirname(bundle_json) + IoUtil.dump_json_file(COMPONENTS_PATH_DIR,bundles_path) + return bundles_path \ No newline at end of file