|
5 | 5 | # SPDX-License-Identifier: Apache-2.0 |
6 | 6 |
|
7 | 7 | import copy |
| 8 | +import logging |
8 | 9 | import os |
9 | 10 | import re |
10 | 11 | import sys |
|
18 | 19 | "Please install the ply package using your workstation's\n" |
19 | 20 | "package manager or the 'pip' tool.") |
20 | 21 |
|
| 22 | +_logger = logging.getLogger('twister') |
| 23 | + |
21 | 24 | reserved = { |
22 | 25 | 'and' : 'AND', |
23 | 26 | 'or' : 'OR', |
@@ -233,20 +236,55 @@ def ast_expr(ast, env, edt): |
233 | 236 | if alias in node.aliases and node.status == "okay": |
234 | 237 | return True |
235 | 238 | return False |
| 239 | + elif ast[0] == "dt_enabled_alias_with_parent_compat": |
| 240 | + # Checks if the DT has an enabled alias node whose parent has |
| 241 | + # a given compatible. For matching things like gpio-leds child |
| 242 | + # nodes, which do not have compatibles themselves. |
| 243 | + # |
| 244 | + # The legacy "dt_compat_enabled_with_alias" form is still |
| 245 | + # accepted but is now deprecated and causes a warning. This is |
| 246 | + # meant to give downstream users some time to notice and |
| 247 | + # adjust. Its argument order only made sense under the (bad) |
| 248 | + # assumption that the gpio-leds child node has the same compatible |
| 249 | + |
| 250 | + alias = ast[1][0] |
| 251 | + compat = ast[1][1] |
| 252 | + |
| 253 | + return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, |
| 254 | + compat) |
236 | 255 | elif ast[0] == "dt_compat_enabled_with_alias": |
237 | 256 | compat = ast[1][0] |
238 | 257 | alias = ast[1][1] |
239 | | - for node in edt.nodes: |
240 | | - if node.status == "okay" and alias in node.aliases and node.matching_compat == compat: |
241 | | - return True |
242 | | - return False |
| 258 | + |
| 259 | + _logger.warning('dt_compat_enabled_with_alias("%s", "%s"): ' |
| 260 | + 'this is deprecated, use ' |
| 261 | + 'dt_enabled_alias_with_parent_compat("%s", "%s") ' |
| 262 | + 'instead', |
| 263 | + compat, alias, alias, compat) |
| 264 | + |
| 265 | + return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, |
| 266 | + compat) |
243 | 267 | elif ast[0] == "dt_chosen_enabled": |
244 | 268 | chosen = ast[1][0] |
245 | 269 | node = edt.chosen_node(chosen) |
246 | 270 | if node and node.status == "okay": |
247 | 271 | return True |
248 | 272 | return False |
249 | 273 |
|
| 274 | +def ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, compat): |
| 275 | + # Helper shared with the now deprecated |
| 276 | + # dt_compat_enabled_with_alias version. |
| 277 | + |
| 278 | + for node in edt.nodes: |
| 279 | + parent = node.parent |
| 280 | + if parent is None: |
| 281 | + continue |
| 282 | + if (node.status == "okay" and alias in node.aliases and |
| 283 | + parent.matching_compat == compat): |
| 284 | + return True |
| 285 | + |
| 286 | + return False |
| 287 | + |
250 | 288 | mutex = threading.Lock() |
251 | 289 |
|
252 | 290 | def parse(expr_text, env, edt): |
|
0 commit comments