@@ -179,15 +179,19 @@ def _raise_libdep_lint_exception(self, message):
179179 else :
180180 raise LibdepLinterError (message )
181181
182- def _check_for_lint_tags (self , lint_tag , env = None ):
182+ def _check_for_lint_tags (self , lint_tag , env = None , inclusive_tag = False ):
183183 """
184184 Used to get the lint tag from the environment,
185185 and if printing instead of raising exceptions,
186186 will ignore the tags.
187187 """
188188
189- # ignore LIBDEP_TAGS if printing was selected
190- if self .__class__ .print_linter_errors :
189+ # If print mode is on, we want to make sure to bypass checking
190+ # exclusive tags so we can make sure the exceptions are not excluded
191+ # and are printed. If it's an inclusive tag, we want to ignore this
192+ # early return completely, because we want to make sure the node
193+ # gets included for checking, and the exception gets printed.
194+ if not inclusive_tag and self .__class__ .print_linter_errors :
191195 return False
192196
193197 target_env = env if env else self .env
@@ -202,6 +206,29 @@ def _get_deps_dependents(self, env=None):
202206 deps_dependents += target_env .get (Constants .ProgdepsDependents , [])
203207 return deps_dependents
204208
209+ @linter_rule
210+ def linter_rule_leaf_node_no_deps (self , libdep ):
211+ """
212+ LIBDEP RULE:
213+ Nodes marked explicitly as a leaf node should not have any dependencies,
214+ unless those dependencies are explicitly marked as allowed as leaf node
215+ dependencies.
216+ """
217+ if not self ._check_for_lint_tags ('lint-leaf-node-no-deps' , inclusive_tag = True ):
218+ return
219+
220+ # Ignore dependencies that explicitly exempt themselves.
221+ if self ._check_for_lint_tags ('lint-leaf-node-allowed-dep' , libdep .target_node .env ):
222+ return
223+
224+ target_type = self .target [0 ].builder .get_name (self .env )
225+ lib = os .path .basename (str (libdep ))
226+ self ._raise_libdep_lint_exception (
227+ textwrap .dedent (f"""\
228+ { target_type } '{ self .target [0 ]} ' has dependency '{ lib } ' and is marked explicitly as a leaf node,
229+ and '{ lib } ' does not exempt itself as an exception to the rule."""
230+ ))
231+
205232 @linter_rule
206233 def linter_rule_no_dups (self , libdep ):
207234 """
0 commit comments