1#!/usr/bin/env python 2#coding=utf-8 3 4# 5# Copyright (c) 2025 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import json 21 22from .base_rule import BaseRule 23 24 25class BaseInnerapiRule(BaseRule): 26 RULE_NAME = "BaseInnerApi" 27 28 def __init__(self, mgr, args): 29 super().__init__(mgr, args) 30 self.__ignored_tags = ["platformsdk", "sasdk", "platformsdk_indirect", "ndk"] 31 self.__valid_system_tags = ["llndk", "chipsetsdk", "chipsetsdk_indirect", "chipsetsdk_sp" 32 "chipsetsdk_sp_indirect"] + self.__ignored_tags 33 self.__valid_vendor_tags = ["chipsetsdk", "chipsetsdk_sp", "llndk", "passthrough", 34 "passthrough_indirect"] + self.__ignored_tags 35 36 def is_only(self, ignored_tags, mod): 37 # check mod belongs to system module or vendor module 38 if mod["path"].startswith("system"): 39 return "system" 40 else: 41 return "vendor" 42 43 def check(self): 44 passed = True 45 46 for mod in self.get_mgr().get_all(): 47 innerapi_tags = mod["innerapi_tags"] 48 # mod is system only scene 49 if self.is_only(self.__ignored_tags, mod) == "system" and \ 50 all(item in self.__valid_system_tags for item in innerapi_tags): 51 for dep in mod["deps"]: 52 callee = dep["callee"] 53 callee_innerapi_tags = callee["innerapi_tags"] 54 if self.is_only(self.__ignored_tags, callee) == "system" or \ 55 all(item in self.__valid_system_tags for item in callee_innerapi_tags): 56 continue 57 else: 58 self.warn("NEED MODIFY: system only module %s depends on wrong module as %s in %s, dep module path is %s" 59 %(mod["name"], callee["name"], mod["labelPath"], callee["path"])) 60 passed = True 61 # mod is vendor only scene 62 elif self.is_only(self.__ignored_tags, mod) == "vendor" and \ 63 all(item in self.__valid_vendor_tags for item in innerapi_tags): 64 for dep in mod["deps"]: 65 callee = dep["callee"] 66 callee_innerapi_tags = callee["innerapi_tags"] 67 if self.is_only(self.__ignored_tags, callee) == "vendor" or \ 68 all(item in self.__valid_vendor_tags for item in callee_innerapi_tags): 69 continue 70 else: 71 self.error("NEED MODIFY: system only module %s depends on wrong module as %s in %s, dep module path is %s" 72 %(mod["name"], callee["name"], mod["labelPath"], callee["path"])) 73 passed = True 74 return passed