@@ -179,15 +179,19 @@ def _raise_libdep_lint_exception(self, message):
179
179
else :
180
180
raise LibdepLinterError (message )
181
181
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 ):
183
183
"""
184
184
Used to get the lint tag from the environment,
185
185
and if printing instead of raising exceptions,
186
186
will ignore the tags.
187
187
"""
188
188
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 :
191
195
return False
192
196
193
197
target_env = env if env else self .env
@@ -202,6 +206,29 @@ def _get_deps_dependents(self, env=None):
202
206
deps_dependents += target_env .get (Constants .ProgdepsDependents , [])
203
207
return deps_dependents
204
208
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
+
205
232
@linter_rule
206
233
def linter_rule_no_dups (self , libdep ):
207
234
"""
0 commit comments