1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 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 sys 17import argparse 18import os 19 20sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 21from scripts.util.file_utils import read_json_file, write_json_file # noqa: E402 E501 22 23 24# read subsystem module, generate subsystem install list and deps list. 25def gen_output_file(part_name, origin_part_name, all_modules_file, 26 sdk_modules_info_file, install_modules_file, 27 dep_modules_file, current_toolchain): 28 # read subsystem module info 29 all_module_info = read_json_file(all_modules_file) 30 if all_module_info is None: 31 raise Exception( 32 "read part '{}' modules info failed.".format(part_name)) 33 34 # merge sdk install modules, may be repeat 35 if os.path.exists(sdk_modules_info_file): 36 sdk_modules_info = read_json_file(sdk_modules_info_file) 37 if sdk_modules_info is not None: 38 all_module_info.extend(sdk_modules_info) 39 40 # Generate a list of modules by part 41 modules_info_dict = {} 42 modules_def = {} # remove duplicates 43 for info in all_module_info: 44 module_def = info.get('module_def') 45 if module_def in modules_def: 46 continue 47 48 modules_def[module_def] = '' 49 _module_part_name = info.get('part_name') 50 if _module_part_name not in modules_info_dict: 51 modules_info_dict[_module_part_name] = [] 52 modules_info_dict[_module_part_name] += [info] 53 54 # Current part module list 55 part_module_list = [] 56 if origin_part_name in modules_info_dict: 57 part_module_list = modules_info_dict.pop(origin_part_name) 58 59 # Current part dependent module list 60 part_install_modules = [] 61 part_no_install_modules = [] 62 for install_module in part_module_list: 63 toolchain = install_module.get('toolchain') 64 if toolchain == '' or toolchain == current_toolchain: 65 part_install_modules.append(install_module) 66 else: 67 part_no_install_modules.append(install_module) 68 69 # write install modules file 70 write_json_file(install_modules_file, part_install_modules) 71 72 # add no install modules to dict, example: host target 73 modules_info_dict[part_name] = part_no_install_modules 74 # write dep modules file 75 write_json_file(dep_modules_file, modules_info_dict) 76 77 78def main(): 79 parser = argparse.ArgumentParser() 80 parser.add_argument('--part-name', required=True) 81 parser.add_argument('--origin-part-name', required=True) 82 parser.add_argument('--input-file', help='', required=True) 83 parser.add_argument('--sdk-modules-info-file', help='', required=True) 84 parser.add_argument('--output-install-file', help='', required=True) 85 parser.add_argument('--output-deps-file', help='', required=True) 86 parser.add_argument('--current-toolchain', help='', required=True) 87 parser.add_argument('--depfile', required=False) 88 args = parser.parse_args() 89 90 gen_output_file(args.part_name, args.origin_part_name, args.input_file, 91 args.sdk_modules_info_file, args.output_install_file, 92 args.output_deps_file, args.current_toolchain) 93 return 0 94 95 96if __name__ == '__main__': 97 sys.exit(main()) 98