15f9996aaSopenharmony_ci#!/usr/bin/env python 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd. 45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 65f9996aaSopenharmony_ci# You may obtain a copy of the License at 75f9996aaSopenharmony_ci# 85f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 145f9996aaSopenharmony_ci# limitations under the License. 155f9996aaSopenharmony_ci 165f9996aaSopenharmony_ciimport os 175f9996aaSopenharmony_ciimport sys 185f9996aaSopenharmony_ciimport argparse 195f9996aaSopenharmony_ci 205f9996aaSopenharmony_cisys.path.append( 215f9996aaSopenharmony_ci os.path.dirname( 225f9996aaSopenharmony_ci os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) 235f9996aaSopenharmony_cifrom scripts.util.file_utils import write_json_file # noqa E402 245f9996aaSopenharmony_ci 255f9996aaSopenharmony_ci 265f9996aaSopenharmony_cidef get_allowlist(): 275f9996aaSopenharmony_ci return ['hilog_java'] 285f9996aaSopenharmony_ci 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_cidef get_kits_signature_list(sign_file_root_dir: str, subsystem_name: str, 315f9996aaSopenharmony_ci sign_file_name: str): 325f9996aaSopenharmony_ci kits_signature_list = [] 335f9996aaSopenharmony_ci subsystem_sign_file_dir = os.path.join(sign_file_root_dir, subsystem_name) 345f9996aaSopenharmony_ci if not os.path.exists(subsystem_sign_file_dir): 355f9996aaSopenharmony_ci return kits_signature_list 365f9996aaSopenharmony_ci kits_module_list = os.listdir(subsystem_sign_file_dir) 375f9996aaSopenharmony_ci for module_name in kits_module_list: 385f9996aaSopenharmony_ci signature_file = os.path.join(subsystem_sign_file_dir, module_name, 395f9996aaSopenharmony_ci sign_file_name) 405f9996aaSopenharmony_ci if os.path.exists(signature_file): 415f9996aaSopenharmony_ci kits_signature_list.append(module_name) 425f9996aaSopenharmony_ci return kits_signature_list 435f9996aaSopenharmony_ci 445f9996aaSopenharmony_ci 455f9996aaSopenharmony_cidef check_remove(sign_file_root_dir: str, subsystem_name: str, kit_list: list, kit_type: str): 465f9996aaSopenharmony_ci if not os.path.exists(sign_file_root_dir): 475f9996aaSopenharmony_ci return True 485f9996aaSopenharmony_ci 495f9996aaSopenharmony_ci sign_file_name = 'signature' 505f9996aaSopenharmony_ci if kit_type == 'so': 515f9996aaSopenharmony_ci sign_file_name = 'check.txt' 525f9996aaSopenharmony_ci 535f9996aaSopenharmony_ci kits_signature_list = get_kits_signature_list(sign_file_root_dir, 545f9996aaSopenharmony_ci subsystem_name, 555f9996aaSopenharmony_ci sign_file_name) 565f9996aaSopenharmony_ci 575f9996aaSopenharmony_ci if len(kits_signature_list) != len(kit_list): 585f9996aaSopenharmony_ci return False 595f9996aaSopenharmony_ci 605f9996aaSopenharmony_ci for kits_signature_module in kits_signature_list: 615f9996aaSopenharmony_ci if kits_signature_module not in kit_list: 625f9996aaSopenharmony_ci return False 635f9996aaSopenharmony_ci return True 645f9996aaSopenharmony_ci 655f9996aaSopenharmony_ci 665f9996aaSopenharmony_cidef main(): 675f9996aaSopenharmony_ci parser = argparse.ArgumentParser() 685f9996aaSopenharmony_ci parser.add_argument('--subsystem-name', required=True) 695f9996aaSopenharmony_ci parser.add_argument('--sign-file-root-dir', required=True) 705f9996aaSopenharmony_ci parser.add_argument('--kit-list', nargs='+', default=[]) 715f9996aaSopenharmony_ci parser.add_argument('--output-file', required=True) 725f9996aaSopenharmony_ci parser.add_argument('--kit-type', required=True) 735f9996aaSopenharmony_ci parser.add_argument('--depfile', required=False) 745f9996aaSopenharmony_ci args = parser.parse_args() 755f9996aaSopenharmony_ci 765f9996aaSopenharmony_ci kit_list = args.kit_list 775f9996aaSopenharmony_ci for _kit in get_allowlist(): 785f9996aaSopenharmony_ci if _kit in kit_list: 795f9996aaSopenharmony_ci kit_list.remove(_kit) 805f9996aaSopenharmony_ci 815f9996aaSopenharmony_ci result = check_remove(args.sign_file_root_dir, args.subsystem_name, 825f9996aaSopenharmony_ci kit_list, args.kit_type) 835f9996aaSopenharmony_ci if not result: 845f9996aaSopenharmony_ci raise Exception( 855f9996aaSopenharmony_ci "Error, part '{}' kit remove, please check kit config.". 865f9996aaSopenharmony_ci format(args.subsystem_name)) 875f9996aaSopenharmony_ci write_json_file(args.output_file, {}) 885f9996aaSopenharmony_ci return 0 895f9996aaSopenharmony_ci 905f9996aaSopenharmony_ci 915f9996aaSopenharmony_ciif __name__ == '__main__': 925f9996aaSopenharmony_ci sys.exit(main()) 93