1#!/usr/bin/env python 2#coding=utf-8 3 4# 5# Copyright (c) 2022 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 json 20 21from .base_rule import BaseRule 22 23 24class NapiRule(BaseRule): 25 RULE_NAME = "NO-Depends-On-NAPI" 26 27 def check(self): 28 return self.__check_depends_on_napi() 29 30 def __check_depends_on_napi(self): 31 lists = self.get_white_lists() 32 33 passed = True 34 35 # Check if any napi modules has dependedBy 36 for mod in self.get_mgr().get_all(): 37 if not mod["napi"]: 38 continue 39 40 if len(mod["dependedBy"]) == 0: 41 continue 42 43 target_name = mod["labelPath"][mod["labelPath"].find(":")+1:] 44 if target_name in lists: 45 continue 46 47 self.error("napi module %s depended by:" % mod["name"]) 48 for dep in mod["dependedBy"]: 49 caller = dep["caller"] 50 self.log(" module [%s] defined in [%s]" % (caller["name"], caller["labelPath"])) 51 passed = False 52 53 return passed 54