diff --git a/tools/deps_guard/elf_file_mgr/sa/sa.py b/tools/deps_guard/elf_file_mgr/sa/sa.py index ada67e43e091ba0b016832db5367fb7874ab70c3..d8b1472da3e538982497109e646cbfad67369122 100755 --- a/tools/deps_guard/elf_file_mgr/sa/sa.py +++ b/tools/deps_guard/elf_file_mgr/sa/sa.py @@ -23,50 +23,50 @@ import os import xml.etree.ElementTree as ET def xml_node_find_by_name(node, name): - for item in node: - if item.tag == name: - return item.text - return None + for item in node: + if item.tag == name: + return item.text + return None class SAParser(object): - @staticmethod - def __parse_sa_profile(all_sa, full_name): - with open(full_name, "r") as f: - profile = json.load(f) - process = profile["process"] - for sa in profile["systemability"]: - libpath = sa["libpath"] - sa_key = os.path.basename(libpath) - sa["process"] = process - all_sa[sa_key] = sa + @staticmethod + def __parse_sa_profile(all_sa, full_name): + with open(full_name, "r") as f: + profile = json.load(f) + process = profile["process"] + for sa in profile["systemability"]: + libpath = sa["libpath"] + sa_key = os.path.basename(libpath) + sa["process"] = process + all_sa[sa_key] = sa - @staticmethod - def __add_sa_info(all_sa, mgr): - if not mgr: - return - for mod in mgr.get_all(): - mod["sa_id"] = 0 - if mod["name"] not in all_sa: - continue - mod["sa_id"] = int(all_sa[mod["name"]]["name"]) + @staticmethod + def __add_sa_info(all_sa, mgr): + if not mgr: + return + for mod in mgr.get_all(): + mod["sa_id"] = 0 + if mod["name"] not in all_sa: + continue + mod["sa_id"] = int(all_sa[mod["name"]]["name"]) - @staticmethod - def load(mgr, out_root_path): - all_sa = {} - path = os.path.join(out_root_path, "packages/phone/system/profile") - if not os.path.exists(path): - return + @staticmethod + def load(mgr, out_root_path): + all_sa = {} + path = os.path.join(out_root_path, "packages/phone/system/profile") + if not os.path.exists(path): + return - for f in os.listdir(path): - full_name = os.path.join(path, f) - if os.path.isfile(full_name) and f.endswith(".json"): - try: - SAParser.__parse_sa_profile(all_sa, full_name) - except: - pass + for f in os.listdir(path): + full_name = os.path.join(path, f) + if os.path.isfile(full_name) and f.endswith(".json"): + try: + SAParser.__parse_sa_profile(all_sa, full_name) + except: + pass - SAParser.__add_sa_info(all_sa, mgr) + SAParser.__add_sa_info(all_sa, mgr) if __name__ == '__main__': - parser = SAParser() - parser.load(None, "/home/handy/qemu/out/rk3568") + parser = SAParser() + parser.load(None, "/home/handy/qemu/out/rk3568") diff --git a/tools/deps_guard/rules_checker/chipsetsdk.py b/tools/deps_guard/rules_checker/chipsetsdk.py index 3fb8ca6993a01a1a37be6d23933ace568e9d81ac..0fc8ce451dab87202b61dcebb294d83676ed1a8f 100755 --- a/tools/deps_guard/rules_checker/chipsetsdk.py +++ b/tools/deps_guard/rules_checker/chipsetsdk.py @@ -22,170 +22,172 @@ import json from .base_rule import BaseRule class ChipsetSDKRule(BaseRule): - RULE_NAME = "ChipsetSDK" - - def __is_chipsetsdk_tagged(self, mod): - if not "innerapi_tags" in mod: - return False - #if "ndk" in mod["innerapi_tags"]: - # return True - if "chipsetsdk" in mod["innerapi_tags"]: - return True - return False - - def __is_chipsetsdk_indirect(self, mod): - if not "innerapi_tags" in mod: - return False - if "chipsetsdk_indirect" in mod["innerapi_tags"]: - return True - return False - - def __write_innerkits_header_files(self): - inner_kits_info = os.path.join(self.get_mgr().get_product_out_path(), "build_configs/parts_info/inner_kits_info.json") - with open(inner_kits_info, "r") as f: - info = json.load(f) - - headers = [] - for sdk in self.__chipsetsdks: - path = sdk["labelPath"][:sdk["labelPath"].find(":")] - target_name = sdk["labelPath"][sdk["labelPath"].find(":")+1:] - item = {"name": sdk["componentName"] + ":" + target_name, "so_file_name": sdk["name"], "path": sdk["labelPath"], "headers": []} - if sdk["componentName"] not in info: - headers.append(item) - continue - - for name, innerapi in info[sdk["componentName"]].items(): - if innerapi["label"] != sdk["labelPath"]: - continue - gotHeaders = True - base = innerapi["header_base"] - for f in innerapi["header_files"]: - item["headers"].append(os.path.join(base, f)) - headers.append(item) - - try: - with open(os.path.join(self.get_mgr().get_product_images_path(), "chipsetsdk_info.json"), "w") as f: - json.dump(headers, f, indent = 4) - except: - pass - - return headers - - def __check_chipsetsdk_indirect(self): - passed = True - for mod in self.__chipsetsdks: - for dep in mod["deps"]: - callee = dep["callee"] - - # Chipset SDK is OK - if callee["name"] in self.get_white_lists(): - continue - - # chipsetsdk_indirect module is OK - if self.__is_chipsetsdk_indirect(callee): - continue - - # Not correct - passed = False - self.error('Chipset SDK module %s should not depends on non Chipset SDK module %s in %s with "chipsetsdk_indirect"' % (mod["name"], callee["name"], callee["labelPath"])) - - return passed - - def __check_depends_on_chipsetsdk(self): - lists = self.get_white_lists() - - passed = True - - self.__chipsetsdks = [] - self.__modules_with_chipsetsdk_tag = [] - self.__modules_with_chipsetsdk_indirect_tag = [] - - # Check if any napi modules has dependedBy - for mod in self.get_mgr().get_all(): - # Collect all modules with chipsetsdk tag - if self.__is_chipsetsdk_tagged(mod): - self.__modules_with_chipsetsdk_tag.append(mod) - - # Collect all modules with chipsetsdk_indirect tag - if self.__is_chipsetsdk_indirect(mod): - self.__modules_with_chipsetsdk_indirect_tag.append(mod) - - # Check chipset modules only - if mod["path"].startswith("system"): - continue - - # Check chipset modules depends - for dep in mod["deps"]: - callee = dep["callee"] - - # If callee is chipset module, it is OK - if not callee["path"].startswith("system"): - continue - - # Add to list - if callee not in self.__chipsetsdks: - if "hdiType" not in callee or callee["hdiType"] != "hdi_proxy": - self.__chipsetsdks.append(callee) - - # If callee is in Chipset SDK white list module, it is OK - if callee["name"] in lists: - continue - - # If callee is asan library, it is OK - if callee["name"].endswith(".asan.so"): - continue - - # If callee is hdi proxy module, it is OK - if "hdiType" in callee and callee["hdiType"] == "hdi_proxy": - continue - - # Not allowed - passed = False - self.error("chipset module %s depends on non Chipset SDK module %s in %s" % (mod["name"], callee["name"], mod["labelPath"])) - - return passed - - - def __check_if_tagged_correctly(self): - passed = True - for mod in self.__chipsetsdks: - if not self.__is_chipsetsdk_tagged(mod): - #passed = False - self.warn('Chipset SDK module %s has no innerapi_tags with "chipsetsdk", add it in %s' % (mod["name"], mod["labelPath"])) + RULE_NAME = "ChipsetSDK" + + def __is_chipsetsdk_tagged(self, mod): + if not "innerapi_tags" in mod: + return False + if "chipsetsdk" in mod["innerapi_tags"]: + return True + return False + + def __is_chipsetsdk_indirect(self, mod): + if not "innerapi_tags" in mod: + return False + if "chipsetsdk_indirect" in mod["innerapi_tags"]: + return True + return False + + def __write_innerkits_header_files(self): + inner_kits_info = os.path.join(self.get_mgr().get_product_out_path(), "build_configs/parts_info/inner_kits_info.json") + with open(inner_kits_info, "r") as f: + info = json.load(f) + + headers = [] + for sdk in self.__chipsetsdks: + path = sdk["labelPath"][:sdk["labelPath"].find(":")] + target_name = sdk["labelPath"][sdk["labelPath"].find(":") + 1:] + item = {"name": sdk["componentName"] + ":" + target_name, "so_file_name": + sdk["name"], "path": sdk["labelPath"], "headers": []} + if sdk["componentName"] not in info: + headers.append(item) + continue + + for name, innerapi in info[sdk["componentName"]].items(): + if innerapi["label"] != sdk["labelPath"]: + continue + gotHeaders = True + base = innerapi["header_base"] + for f in innerapi["header_files"]: + item["headers"].append(os.path.join(base, f)) + headers.append(item) + + try: + with open(os.path.join(self.get_mgr().get_product_images_path(), "chipsetsdk_info.json"), "w") as f: + json.dump(headers, f, indent = 4) + except: + pass + + return headers + + def __check_chipsetsdk_indirect(self): + passed = True + for mod in self.__chipsetsdks: + for dep in mod["deps"]: + callee = dep["callee"] + + # Chipset SDK is OK + if callee["name"] in self.get_white_lists(): + continue + + # chipsetsdk_indirect module is OK + if self.__is_chipsetsdk_indirect(callee): + continue + + # Not correct + passed = False + self.error('Chipset SDK module %s should not depends on non Chipset SDK module \ + %s in %s with "chipsetsdk_indirect"' % (mod["name"], callee["name"], callee["labelPath"])) + + return passed + + def __check_depends_on_chipsetsdk(self): + lists = self.get_white_lists() + + passed = True + + self.__chipsetsdks = [] + self.__modules_with_chipsetsdk_tag = [] + self.__modules_with_chipsetsdk_indirect_tag = [] + + # Check if any napi modules has dependedBy + for mod in self.get_mgr().get_all(): + # Collect all modules with chipsetsdk tag + if self.__is_chipsetsdk_tagged(mod): + self.__modules_with_chipsetsdk_tag.append(mod) + + # Collect all modules with chipsetsdk_indirect tag + if self.__is_chipsetsdk_indirect(mod): + self.__modules_with_chipsetsdk_indirect_tag.append(mod) + + # Check chipset modules only + if mod["path"].startswith("system"): + continue + + # Check chipset modules depends + for dep in mod["deps"]: + callee = dep["callee"] + + # If callee is chipset module, it is OK + if not callee["path"].startswith("system"): + continue + + # Add to list + if callee not in self.__chipsetsdks: + if "hdiType" not in callee or callee["hdiType"] != "hdi_proxy": + self.__chipsetsdks.append(callee) + + # If callee is in Chipset SDK white list module, it is OK + if callee["name"] in lists: + continue + + # If callee is asan library, it is OK + if callee["name"].endswith(".asan.so"): + continue + + # If callee is hdi proxy module, it is OK + if "hdiType" in callee and callee["hdiType"] == "hdi_proxy": + continue + + # Not allowed + passed = False + self.error("chipset module %s depends on non Chipset SDK module %s in %s" + % (mod["name"], callee["name"], mod["labelPath"])) + + return passed + + + def __check_if_tagged_correctly(self): + passed = True + for mod in self.__chipsetsdks: + if not self.__is_chipsetsdk_tagged(mod): + self.warn('Chipset SDK module %s has no innerapi_tags with "chipsetsdk", add it in %s' + % (mod["name"], mod["labelPath"])) + + for mod in self.__modules_with_chipsetsdk_tag: + if mod["name"] not in self.get_white_lists(): + passed = False + self.error('non chipsetsdk module %s with innerapi_tags="chipsetsdk", %s' + % (mod["name"], mod["labelPath"])) - for mod in self.__modules_with_chipsetsdk_tag: - if mod["name"] not in self.get_white_lists(): - passed = False - self.error('non chipsetsdk module %s with innerapi_tags="chipsetsdk", %s' % (mod["name"], mod["labelPath"])) + for mod in self.__modules_with_chipsetsdk_indirect_tag: + if mod["name"] not in self.__indirects and mod["name"] not in self.get_white_lists(): + self.warn('non chipsetsdk_indirect module %s with innerapi_tags="chipsetsdk_indirect", %s' + % (mod["name"], mod["labelPath"])) - for mod in self.__modules_with_chipsetsdk_indirect_tag: - if mod["name"] not in self.__indirects and mod["name"] not in self.get_white_lists(): - #passed = False - self.warn('non chipsetsdk_indirect module %s with innerapi_tags="chipsetsdk_indirect", %s' % (mod["name"], mod["labelPath"])) + return passed - return passed + def __load_chipsetsdk_indirects(self): + self.__indirects = self.load_files("chipsetsdk_indirect") - def __load_chipsetsdk_indirects(self): - self.__indirects = self.load_files("chipsetsdk_indirect") + def check(self): + self.__load_chipsetsdk_indirects() - def check(self): - self.__load_chipsetsdk_indirects() + # Check if all chipset modules depends on chipsetsdk modules only + passed = self.__check_depends_on_chipsetsdk() + if not passed: + return passed - # Check if all chipset modules depends on chipsetsdk modules only - passed = self.__check_depends_on_chipsetsdk() - if not passed: - return passed + # Check if all chipsetsdk module depends on chipsetsdk or chipsetsdk_indirect modules only + passed = self.__check_chipsetsdk_indirect() + if not passed: + return passed - # Check if all chipsetsdk module depends on chipsetsdk or chipsetsdk_indirect modules only - passed = self.__check_chipsetsdk_indirect() - if not passed: - return passed + # Check if all ChipsetSDK modules are correctly tagged by innerapi_tags + passed = self.__check_if_tagged_correctly() + if not passed: + return passed - # Check if all ChipsetSDK modules are correctly tagged by innerapi_tags - passed = self.__check_if_tagged_correctly() - if not passed: - return passed + self.__write_innerkits_header_files() - self.__write_innerkits_header_files() - - return True + return True