1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2023 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19from abc import abstractmethod 20from exceptions.ohos_exception import OHOSException 21from modules.interface.module_interface import ModuleInterface 22from services.interface.preload_interface import PreloadInterface 23from services.interface.load_interface import LoadInterface 24from services.interface.build_executor_interface import BuildExecutorInterface 25from services.interface.build_file_generator_interface import BuildFileGeneratorInterface 26from resolver.interface.args_resolver_interface import ArgsResolverInterface 27 28 29class BuildModuleInterface(ModuleInterface): 30 31 def __init__(self, 32 args_dict: dict, 33 args_resolver: ArgsResolverInterface, 34 preloader: PreloadInterface, 35 loader: LoadInterface, 36 target_generator: BuildFileGeneratorInterface, 37 target_compiler: BuildExecutorInterface): 38 39 super().__init__(args_dict, args_resolver) 40 self._loader = loader 41 self._preloader = preloader 42 self._target_generator = target_generator 43 self._target_compiler = target_compiler 44 45 @property 46 def preloader(self): 47 return self._preloader 48 49 @property 50 def loader(self): 51 return self._loader 52 53 @property 54 def target_generator(self): 55 return self._target_generator 56 57 @property 58 def target_compiler(self): 59 return self._target_compiler 60 61 def run(self): 62 try: 63 self._prebuild() 64 self._preload() 65 self._load() 66 self._pre_target_generate() 67 self._target_generate() 68 self._post_target_generate() 69 self._pre_target_compilation() 70 self._target_compilation() 71 except OHOSException as exception: 72 raise exception 73 else: 74 self._post_target_compilation() 75 finally: 76 self._post_build() 77 78 @abstractmethod 79 def _prebuild(self): 80 pass 81 82 @abstractmethod 83 def _preload(self): 84 pass 85 86 @abstractmethod 87 def _load(self): 88 pass 89 90 @abstractmethod 91 def _pre_target_generate(self): 92 pass 93 94 @abstractmethod 95 def _target_generate(self): 96 pass 97 98 @abstractmethod 99 def _post_target_generate(self): 100 pass 101 102 @abstractmethod 103 def _pre_target_compilation(self): 104 pass 105 106 @abstractmethod 107 def _target_compilation(self): 108 pass 109 110 @abstractmethod 111 def _post_target_compilation(self): 112 pass 113 114 @abstractmethod 115 def _post_build(self): 116 pass 117