|
[ Source navigation ] [ Diff markup ] [ Identifier search ] |
|||
|
Warning, file /build.py was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/usr/bin/env python3 0002 # -*- coding: utf-8 -*- 0003 0004 # 0005 # Copyright (c) 2022 Huawei Device Co., Ltd. 0006 # Licensed under the Apache License, Version 2.0 (the "License"); 0007 # you may not use this file except in compliance with the License. 0008 # You may obtain a copy of the License at 0009 # 0010 # http://www.apache.org/licenses/LICENSE-2.0 0011 # 0012 # Unless required by applicable law or agreed to in writing, software 0013 # distributed under the License is distributed on an "AS IS" BASIS, 0014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0015 # See the License for the specific language governing permissions and 0016 # limitations under the License. 0017 # 0018 0019 import os 0020 import sys 0021 import importlib 0022 import subprocess 0023 0024 0025 def search(findir: str, target: str) -> str or bool: 0026 for root, _, files in os.walk(findir): 0027 if target in files: 0028 return root 0029 return False 0030 0031 0032 def find_top() -> str: 0033 cur_dir = os.getcwd() 0034 while cur_dir != "/": 0035 build_config_file = os.path.join( 0036 cur_dir, 'build/config/BUILDCONFIG.gn') 0037 if os.path.exists(build_config_file): 0038 return cur_dir 0039 cur_dir = os.path.dirname(cur_dir) 0040 0041 0042 def get_python(python_relative_dir: str) -> str: 0043 topdir = find_top() 0044 if python_relative_dir is None: 0045 python_relative_dir = 'prebuilts/python' 0046 python_base_dir = os.path.join(topdir, python_relative_dir) 0047 0048 if os.path.exists(python_base_dir): 0049 python_dir = search(python_base_dir, 'python3') 0050 return os.path.join(python_dir, 'python3') 0051 else: 0052 print("please execute build/prebuilts_download.sh.", 0053 "if you used '--python-dir', check whether the input path is valid.") 0054 sys.exit() 0055 0056 0057 def check_output(cmd: str, **kwargs) -> str: 0058 process = subprocess.Popen(cmd, 0059 stdout=subprocess.PIPE, 0060 stderr=subprocess.STDOUT, 0061 universal_newlines=True, 0062 **kwargs) 0063 for line in iter(process.stdout.readline, ''): 0064 sys.stdout.write(line) 0065 sys.stdout.flush() 0066 0067 process.wait() 0068 ret_code = process.returncode 0069 0070 return ret_code 0071 0072 0073 def build(path: str, args_list: list) -> str: 0074 python_dir = None 0075 if "--python-dir" in args_list: 0076 index = args_list.index("--python-dir") 0077 if index < len(args_list) - 1: 0078 python_dir = args_list[index + 1] 0079 del args_list[index: index + 2] 0080 else: 0081 print("-python-dir parmeter missing value.") 0082 sys.exit() 0083 python_executable = get_python(python_dir) 0084 cmd = [python_executable, 'build/hb/main.py', 'build'] + args_list 0085 return check_output(cmd, cwd=path) 0086 0087 0088 def main(): 0089 root_path = find_top() 0090 return build(root_path, sys.argv[1:]) 0091 0092 0093 if __name__ == "__main__": 0094 sys.exit(main())
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] |
本网站由冷钦街制作 主页 |
蜀ICP备2022028677 |