1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2025 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 services.interface.build_file_generator_interface import BuildFileGeneratorInterface 20from util.system_util import SystemUtil 21from exceptions.ohos_exception import OHOSException 22import os 23 24 25class IndepBuild(BuildFileGeneratorInterface): 26 27 def __init__(self): 28 super().__init__() 29 30 def run(self): 31 flags_list = self._convert_flags() 32 cmd = ["/bin/bash", "build/indep_configs/build_indep.sh"] 33 cmd.extend(flags_list) 34 variant = self.flags_dict["variant"] 35 logpath = os.path.join('out', variant, 'build.log') 36 ret_code = SystemUtil.exec_command(cmd, log_path=logpath, pre_msg="run indep build", 37 after_msg="indep build end") 38 if ret_code != 0: 39 raise OHOSException(f'ERROR: build_indep.sh encountered a problem, please check, cmd: {cmd}', '0001') 40 41 def _convert_flags(self) -> list: 42 flags_list = [] 43 flags_list.append(os.path.join(os.path.expanduser("~"), ".hpm/.hpmcache")) 44 flags_list.append(self.flags_dict["path"]) 45 build_type = self.flags_dict["buildType"] 46 if build_type == "both": 47 flags_list.append("1") 48 elif build_type == "onlytest": 49 flags_list.append("2") 50 else: 51 flags_list.append("0") 52 variant = self.flags_dict["variant"] 53 flags_list.append(variant) 54 self.flags_dict.pop("buildType") 55 self.flags_dict.pop("path") 56 57 for key in self.flags_dict.keys(): 58 if isinstance(self.flags_dict[key], bool) and self.flags_dict[key]: 59 flags_list.append(f"--{key}") 60 if isinstance(self.flags_dict[key], str) and self.flags_dict[key]: 61 flags_list.append(f"--{key}") 62 flags_list.append(f"{self.flags_dict[key]}") 63 if isinstance(self.flags_dict[key], list) and self.flags_dict[key]: 64 flags_list.append(f"--{key}") 65 flags_list.extend(self.flags_dict[key]) 66 return flags_list 67