Skip to content

Commit

Permalink
edtlib: Add build-time property name checking
Browse files Browse the repository at this point in the history
A warning will be issued if the node contains
property names with underscores during the
construction of node properties.

Signed-off-by: James Roy <[email protected]>
  • Loading branch information
rruuaanng committed Dec 28, 2024
1 parent 0e899c5 commit 5b741b1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/dts/python-devicetree/src/devicetree/edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,13 +1588,19 @@ def _check_undeclared_props(self) -> None:

for prop_name in self._node.props:
# Allow a few special properties to not be declared in the binding
if prop_name.endswith("-controller") or \
prop_name.startswith("#") or \
prop_name in {
if (prop_name.endswith("-controller")
or prop_name.startswith("#")
or prop_name in {
"compatible", "status", "ranges", "phandle",
"interrupt-parent", "interrupts-extended", "device_type"}:
"interrupt-parent", "interrupts-extended", "device_type"}):
continue

if '_' in prop_name:
_err(f"{prop_name}' should use hyphens instead of "
"underscores in the property name. "
f"The property names at '{self.edt.dts_path}' "
f"and '{self.binding_path}' must also be updated.")

if TYPE_CHECKING:
assert self._binding

Expand Down Expand Up @@ -2331,10 +2337,11 @@ def _init_luts(self) -> None:
if self._werror:
handler_fn: Any = _err
else:
handler_fn = _LOG.warning
handler_fn = _warn
handler_fn(
f"node '{node.path}' compatible '{compat}' "
f"has unknown vendor prefix '{vendor}'")
f"has unknown vendor prefix '{vendor}'"
)

for compat, nodes in self.compat2okay.items():
self.compat2nodes[compat].extend(nodes)
Expand Down Expand Up @@ -3221,11 +3228,14 @@ def _check_dt(dt: DT) -> None:
"(see the devicetree specification)")


# Logging object
_LOG = logging.getLogger(__name__)

def _err(msg) -> NoReturn:
raise EDTError(msg)

# Logging object
_LOG = logging.getLogger(__name__)
def _warn(msg) -> None:
_LOG.warning(msg)

# Regular expression for non-alphanumeric-or-underscore characters.
_NOT_ALPHANUM_OR_UNDERSCORE = re.compile(r'\W', re.ASCII)
Expand Down

0 comments on commit 5b741b1

Please sign in to comment.