scripts: edtlib: Forbid multiple bindings with the same compatible

Previously, if two bindings had the same 'compatible:'/'parent-bus:'
values, the binding that happened to be loaded last would get used.

Turn it into an error instead. This avoids tricking people into thinking
that bindings get loaded in a defined order.

Maybe overriding bindings could be allowed later, if we need it.

Fixes: #19536

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
Ulf Magnusson 2019-10-14 17:45:45 +02:00 committed by Carles Cufí
commit e311380584

View file

@ -222,8 +222,19 @@ class EDT:
binding = self._merge_included_bindings(binding, binding_path)
self._check_binding(binding, binding_path)
self._compat2binding[binding_compat, _binding_bus(binding)] = \
(binding, binding_path)
bus = _binding_bus(binding)
# Do not allow two different bindings to have the same
# 'compatible:'/'parent-bus:' combo
old_binding = self._compat2binding.get((binding_compat, bus))
if old_binding:
msg = "both {} and {} have 'compatible: {}'".format(
old_binding[1], binding_path, binding_compat)
if bus is not None:
msg += " and 'parent-bus: {}'".format(bus)
_err(msg)
self._compat2binding[binding_compat, bus] = (binding, binding_path)
def _binding_compat(self, binding, binding_path):
# Returns the string listed in 'compatible:' in 'binding', or None if