From 1a6f0cfa69a009c63eb90d4f125e73e17623794f Mon Sep 17 00:00:00 2001 From: handyohos Date: Sun, 12 Feb 2023 09:55:12 +0800 Subject: [PATCH] Feature: add innerapi info for deps_guard 1) add innerapi info for deps_guard Signed-off-by: handyohos Change-Id: I3dd2e9ee3426ae93ee2fcd8bbf5e50808ed9ed4a #I6EH2F --- tools/deps_guard/elf_file_mgr/elf_file_mgr.py | 1 + .../elf_file_mgr/innerapi/__init__.py | 4 +++ .../elf_file_mgr/innerapi/innerapi.py | 33 +++++++++++++++++++ .../module_info/compile_info_loader.py | 20 +++++------ tools/deps_guard/rules_checker/chipsetsdk.py | 4 +-- 5 files changed, 49 insertions(+), 13 deletions(-) create mode 100755 tools/deps_guard/elf_file_mgr/innerapi/__init__.py create mode 100755 tools/deps_guard/elf_file_mgr/innerapi/innerapi.py diff --git a/tools/deps_guard/elf_file_mgr/elf_file_mgr.py b/tools/deps_guard/elf_file_mgr/elf_file_mgr.py index c505628..87caf5d 100755 --- a/tools/deps_guard/elf_file_mgr/elf_file_mgr.py +++ b/tools/deps_guard/elf_file_mgr/elf_file_mgr.py @@ -57,6 +57,7 @@ class Dependency(dict): from .module_info import CompileInfoLoader from .hdi import HdiParser from .sa import SAParser +from .innerapi import InnerAPILoader class ElfFileMgr(object): def __init__(self, product_out_path=None, elfFileClass=None, dependenceClass = None): diff --git a/tools/deps_guard/elf_file_mgr/innerapi/__init__.py b/tools/deps_guard/elf_file_mgr/innerapi/__init__.py new file mode 100755 index 0000000..78622a6 --- /dev/null +++ b/tools/deps_guard/elf_file_mgr/innerapi/__init__.py @@ -0,0 +1,4 @@ +#! /usr/bin/env python +#coding=utf-8 + +from .innerapi import InnerAPILoader diff --git a/tools/deps_guard/elf_file_mgr/innerapi/innerapi.py b/tools/deps_guard/elf_file_mgr/innerapi/innerapi.py new file mode 100755 index 0000000..aa4709e --- /dev/null +++ b/tools/deps_guard/elf_file_mgr/innerapi/innerapi.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python +#coding=utf-8 + +import os +import json + +class InnerAPILoader(object): + @staticmethod + def load(mgr, product_out_path): + print("Loading innerapis now ...") + try: + innerapis = InnerAPILoader.__load_innerapi_modules(product_out_path) + except: + innerapis = [] + + if not mgr: + return + + for elf in mgr.get_all(): + if elf["labelPath"] in innerapis: + elf["innerapi_declared"] = True + + def __load_innerapi_modules(product_out_path): + inner_kits_info = os.path.join(product_out_path, "build_configs/parts_info/inner_kits_info.json") + with open(inner_kits_info, "r") as f: + info = json.load(f) + + innerapis = [] + for name, component in info.items(): + for mod_name, innerapi in component.items(): + innerapis.append(innerapi["label"]) + + return innerapis diff --git a/tools/deps_guard/elf_file_mgr/module_info/compile_info_loader.py b/tools/deps_guard/elf_file_mgr/module_info/compile_info_loader.py index a927fba..ee300fe 100755 --- a/tools/deps_guard/elf_file_mgr/module_info/compile_info_loader.py +++ b/tools/deps_guard/elf_file_mgr/module_info/compile_info_loader.py @@ -30,9 +30,8 @@ class CompileInfoLoader(object): else: #print("%s has no label" % info["name"]) info["labelPath"] = "" - pos = info["labelPath"].find("(") - if pos > 0: - info["labelPath"] = info["labelPath"][:pos] + if info["labelPath"].find("(") > 0: + info["labelPath"] = info["labelPath"][:info["labelPath"].find("(")] if "subsystem_name" in item: info["subsystem"] = item["subsystem_name"] else: @@ -57,14 +56,11 @@ class CompileInfoLoader(object): info["chipset"] = False info["napi"] = False info["innerapi"] = False + info["innerapi_declared"] = False if "shlib_type" in item: info["shlib_type"] = item["shlib_type"] - if "innerapi" == info["shlib_type"]: - info["innerapi"] = True if "innerapi_tags" in item: - info["innerapi_tags"] = ",".join(item["innerapi_tags"]) - if "chipsetsdk" in item["innerapi_tags"] or "platformsdk" in item["innerapi_tags"]: - info["innerapi"] = True + info["innerapi_tags"] = item["innerapi_tags"] info["sa_id"] = 0 res.append(info) return res @@ -80,12 +76,13 @@ class CompileInfoLoader(object): "third_party": False, "chipset": False, "napi": False, - "innerapi": False, "sa_id": 0, "labelPath": "", "version_script": "", "shlib_type": "", - "innerapi_tags": "" + "innerapi": False, + "innerapi_tags": [], + "innerapi_declared": False } if info: @@ -126,7 +123,7 @@ class CompileInfoLoader(object): if "shlib_type" not in elf: elf["shlib_type"] = "" if "innerapi_tags" not in elf: - elf["innerapi_tags"] = "" + elf["innerapi_tags"] = [] if elf["labelPath"].startswith("//third_party/"): elf["third_party"] = True @@ -186,6 +183,7 @@ class CompileInfoLoader(object): else: caller["deps_external"].append(dep) callee["dependedBy_external"].append(dep) + callee["innerapi"] = True dep["external"] = True callee["modGroup"] = "innerapi_cc" # Cross component diff --git a/tools/deps_guard/rules_checker/chipsetsdk.py b/tools/deps_guard/rules_checker/chipsetsdk.py index 88f3bcd..425b238 100755 --- a/tools/deps_guard/rules_checker/chipsetsdk.py +++ b/tools/deps_guard/rules_checker/chipsetsdk.py @@ -14,7 +14,7 @@ class ChipsetSDKRule(BaseRule): return False if "ndk" in mod["innerapi_tags"]: return True - if mod["innerapi_tags"].endswith("chipsetsdk") or "chipsetsdk," in mod["innerapi_tags"]: + if "chipsetsdk" in mod["innerapi_tags"]: return True return False @@ -80,7 +80,7 @@ class ChipsetSDKRule(BaseRule): # 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 -- Gitee