1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2024 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 18 19sys.path.append(os.path.dirname( 20 os.path.dirname(os.path.dirname(os.path.dirname( 21 os.path.abspath(__file__)))))) 22from scripts.util.file_utils import read_json_file # noqa: E402 23 24 25def __get_relative_install_dir(categories): 26 is_platforsdk = False 27 is_chipsetsdk = False 28 is_chipsetsdk_sp = False 29 is_llndk = False 30 is_ndk = False 31 is_passthrough = False 32 is_passthrough_indirect = False 33 for cat in categories: 34 if cat.startswith("platformsdk"): 35 is_platforsdk = True 36 elif cat.startswith("chipsetsdk"): 37 if cat.startswith("chipsetsdk_sp"): 38 is_chipsetsdk_sp = True 39 else: 40 is_chipsetsdk = True 41 elif cat.startswith("passthrough"): 42 if cat.startswith("passthrought_indirect"): 43 is_passthrough_indirect = True 44 else: 45 is_passthrough = True 46 if cat == "ndk": 47 is_ndk = True 48 if cat == "llndk": 49 is_llndk = True 50 if is_llndk: 51 return "llndk" 52 if is_ndk: 53 return "ndk" 54 if is_chipsetsdk_sp: 55 return "chipset-sdk-sp" 56 if is_chipsetsdk: 57 return "chipset-sdk" 58 if is_passthrough: 59 return "passthrough" 60 if is_passthrough_indirect: 61 return "passthrough/indirect" 62 if is_platforsdk: 63 return "platformsdk" 64 return "" 65 66 67def load_categorized_libraries(file_name): 68 res = read_json_file(file_name) 69 70 for key, val in res.items(): 71 val["relative_install_dir"] = __get_relative_install_dir(val["categories"]) 72 return res 73 74 75# 76# module_info is an json object including label and dest 77# update_module_info will update dest according to label category 78# 79def update_module_info(module_info, categorized_libraries): 80 if "dest" not in module_info: 81 return 82 83 label = module_info["label"] 84 pos = label.find("(") 85 if pos > 0: 86 label = label[:label.find("(")] 87 if label not in categorized_libraries: 88 return 89 90 dest = [] 91 for item in module_info["dest"]: 92 pos = item.rfind("/") 93 if pos < 0: 94 dest.append(item) 95 continue 96 lib_name = item[pos + 1:] 97 dir_name = item[:pos] 98 99 if dir_name.endswith("chipset-sdk") or dir_name.endswith("platformsdk") \ 100 or dir_name.endswith("chipsetsdk") or dir_name.endswith("chipset-sdk-sp") or dir_name.endswith("chipset-pub-sdk") or \ 101 dir_name.endswith("passthrough/indirect") or dir_name.endswith("passthrough"): 102 dir_name = dir_name[:dir_name.rfind("/")] 103 dest.append("{}/{}/{}".format(dir_name, categorized_libraries[label]["relative_install_dir"], lib_name)) 104 module_info["dest"] = dest 105 106 107if __name__ == '__main__': 108 categories = load_categorized_libraries(os.path.join( 109 os.path.dirname(os.path.abspath(__file__)), "categorized-libraries.json")) 110 module_info = { 111 "dest": ["system/lib/chipset-pub-sdk/libaccesstoken_sdk.z.so"], 112 "label": "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk" 113 } 114 update_module_info(module_info, categories) 115 print(module_info) 116