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 19import shutil 20import json 21import glob 22sys.path.append( 23 os.path.dirname(os.path.dirname(os.path.dirname( 24 os.path.abspath(__file__))))) 25from scripts.util import build_utils # noqa: E402 26 27 28def collect_notice_files(options, dest_dir, depfiles): 29 subsystem_info_files = [] 30 with open(options.install_info_file, 'r') as file: 31 install_info = json.load(file) 32 for item in install_info: 33 subsystem_info_files.append(item['part_info_file']) 34 depfiles.extend(subsystem_info_files) 35 36 module_info_files = [] 37 for subsystem_info in subsystem_info_files: 38 with open(subsystem_info, 'r') as file: 39 subsystem_info = json.load(file) 40 for item in subsystem_info: 41 module_info_files.append(item['module_info_file']) 42 depfiles.extend(module_info_files) 43 44 for module_info in module_info_files: 45 with open(module_info, 'r') as file: 46 module_info = json.load(file) 47 if 'notice' in module_info and module_info[ 48 'type'] != "java_library": 49 notice_file = module_info['notice'] 50 if os.path.exists(notice_file) is False or os.stat( 51 notice_file).st_size == 0: 52 continue 53 dest = os.path.join(dest_dir, 54 "{}.txt".format(module_info['dest'][0])) 55 os.makedirs(os.path.dirname(dest), exist_ok=True) 56 shutil.copyfile(module_info['notice'], dest) 57 depfiles.append(module_info['notice']) 58 59 notice_files = build_utils.get_all_files(options.notice_root_dir) 60 depfiles.extend(notice_files) 61 for file in notice_files: 62 dest = os.path.join(dest_dir, 63 os.path.relpath(file, options.notice_root_dir)) 64 os.makedirs(os.path.dirname(dest), exist_ok=True) 65 shutil.copyfile(file, dest) 66 67 68def main(): 69 parser = argparse.ArgumentParser() 70 parser.add_argument('--install-info-file', required=True) 71 parser.add_argument('--notice-root-dir', required=True) 72 parser.add_argument('--output-file', required=True) 73 parser.add_argument('--depfile', required=False) 74 args = parser.parse_args() 75 76 depfiles = [args.install_info_file] 77 with build_utils.temp_dir() as tmp: 78 collect_notice_files(args, tmp, depfiles) 79 build_utils.zip_dir(args.output_file, tmp) 80 81 if args.depfile: 82 build_utils.write_depfile(args.depfile, 83 args.output_file, 84 sorted(depfiles), 85 add_pydeps=False) 86 return 0 87 88 89if __name__ == '__main__': 90 sys.exit(main()) 91