• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23class NapiRule(BaseRule):
24	RULE_NAME = "NO-Depends-On-NAPI"
25
26	def __check_depends_on_napi(self):
27		lists = self.get_white_lists()
28
29		passed = True
30
31		# Check if any napi modules has dependedBy
32		for mod in self.get_mgr().get_all():
33			if not mod["napi"]:
34				continue
35
36			if len(mod["dependedBy"]) == 0:
37				continue
38
39			targetName = mod["labelPath"][mod["labelPath"].find(":")+1:]
40			if targetName in lists:
41				continue
42
43			self.error("napi module %s depended by:" % mod["name"])
44			for dep in mod["dependedBy"]:
45				caller = dep["caller"]
46				self.log("   module [%s] defined in [%s]" % (caller["name"], caller["labelPath"]))
47			passed = False
48
49		return passed
50
51	def check(self):
52		return self.__check_depends_on_napi()
53