1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (c) 2025 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import argparse 18import ssl 19import sys 20sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "prebuilts_service")) 21from prebuilts_service.operater import OperateHanlder 22from prebuilts_service.pool_downloader import PoolDownloader 23from prebuilts_service.config_parser import ConfigParser 24import json 25from prebuilts_service.common_utils import get_code_dir 26 27global_args = None 28 29 30def _parse_args(): 31 parser = argparse.ArgumentParser() 32 parser.add_argument('--skip-ssl', action='store_true', help='skip ssl authentication') 33 parser.add_argument('--unsafe-perm', action='store_true', help='add "--unsafe-perm" for npm install') 34 parser.add_argument('--disable-rich', action='store_true', help='disable the rich module') 35 parser.add_argument('--enable-symlink', action='store_true', help='enable symlink while copying node_modules') 36 parser.add_argument('--build-arkuix', action='store_true', help='build ArkUI-X SDK') 37 parser.add_argument('--tool-repo', default='https://repo.huaweicloud.com', help='prebuilt file download source') 38 parser.add_argument('--npm-registry', default='https://repo.huaweicloud.com/repository/npm/', 39 help='npm download source') 40 parser.add_argument('--host-cpu', help='host cpu', required=True) 41 parser.add_argument('--host-platform', help='host platform', required=True) 42 parser.add_argument('--glibc-version', help='glibc version', required=False) 43 parser.add_argument('--config-file', help='prebuilts download config file') 44 parser.add_argument('--type', help='prebuilts download type', default="indep") 45 parser.add_argument('--part-names', help='current building part', default=None, nargs='+') 46 47 return parser 48 49 50def main(): 51 parser = _parse_args() 52 global global_args 53 global_args = parser.parse_args() 54 55 if global_args.skip_ssl: 56 global_args._create_default_https_context = ssl._create_unverified_context 57 global_args.code_dir = get_code_dir() 58 59 config_file = os.path.join(global_args.code_dir, "build", "prebuilts_config.json") 60 if global_args.config_file: 61 config_file = global_args.config_file 62 print(f"start parse config file {config_file}") 63 config_parser = ConfigParser(config_file, global_args) 64 download_operate, other_operate = config_parser.get_operate(global_args.part_names) 65 prebuilts_path = os.path.join(global_args.code_dir, "prebuilts") 66 if not os.path.exists(prebuilts_path): 67 os.makedirs(prebuilts_path) 68 69 # 使用线程池下载 70 print(f"start download prebuilts, tool list is:") 71 for item in download_operate: 72 print(item.get("remote_url")) 73 pool_downloader = PoolDownloader(download_operate, global_args) 74 unchanged = pool_downloader.start() 75 print(f"start handle other operate") 76 OperateHanlder.run(other_operate, global_args, unchanged) 77 78 79if __name__ == "__main__": 80 sys.exit(main())