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 os 18import argparse 19 20sys.path.append( 21 os.path.dirname(os.path.dirname(os.path.dirname( 22 os.path.abspath(__file__))))) 23from scripts.util.file_utils import read_json_file, write_json_file # noqa: E402 24from scripts.util import build_utils # noqa: E402 25 26 27def binary_install_subsystem(dist_parts_info_file: str, 28 parts_src_installed_info_file: str): 29 # These subsystem have binary install packages 30 if not os.path.exists(dist_parts_info_file): 31 print("dist subsystem info file [{}] no exist.".format( 32 dist_parts_info_file)) 33 return [] 34 35 dist_parts_info = read_json_file(dist_parts_info_file) 36 if dist_parts_info is None: 37 raise Exception("read install parts info file failed.") 38 39 parts_src_list = read_json_file(parts_src_installed_info_file) 40 if parts_src_list is None: 41 raise Exception("read subsystem src flag file failed.") 42 src_part_name_list = [] 43 for _part_info in parts_src_list: 44 src_part_name_list.append(_part_info.get('part_name')) 45 46 required_subsystem = [] 47 for info in dist_parts_info: 48 part_name = info.get('part_name') 49 if part_name not in src_part_name_list: 50 required_subsystem += [info] 51 return required_subsystem 52 53 54def output_installed_info(binary_subsystem_info: str, required_parts: list): 55 write_json_file(binary_subsystem_info, required_parts) 56 57 58def main(): 59 parser = argparse.ArgumentParser() 60 parser.add_argument('--dist-parts-info-file', required=True) 61 parser.add_argument('--parts-src-installed-info-file', required=True) 62 parser.add_argument('--binary-installed-info-file', required=True) 63 parser.add_argument('--depfile', required=False) 64 args = parser.parse_args() 65 66 required_parts = binary_install_subsystem( 67 args.dist_parts_info_file, args.parts_src_installed_info_file) 68 69 output_installed_info(args.binary_installed_info_file, required_parts) 70 71 if args.depfile: 72 _dep_files = [] 73 _dep_files.append(args.dist_parts_info_file) 74 _dep_files.append(args.parts_src_installed_info_file) 75 build_utils.write_depfile(args.depfile, 76 args.binary_installed_info_file, 77 _dep_files, 78 add_pydeps=False) 79 return 0 80 81 82if __name__ == '__main__': 83 sys.exit(main()) 84