dts: edtlib: Turn edt.required_by()/depends_on() into Node attributes
Turns edt.required_by(node) edt.depends_on(node) into node.required_by node.depends_on which might be a bit more readable. One drawback is that @property hides that there's some slight overhead in accessing them, but I suspect it won't be meaningful. Caching could be added if it ever turns out to be. Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
cffb9ad7c6
commit
2e1d2889e2
3 changed files with 24 additions and 20 deletions
|
@ -161,18 +161,6 @@ class EDT:
|
|||
return "<EDT for '{}', binding directories '{}'>".format(
|
||||
self.dts_path, self.bindings_dirs)
|
||||
|
||||
def required_by(self, node):
|
||||
"""
|
||||
Returns a list of Nodes that have direct dependencies on 'node'.
|
||||
"""
|
||||
return self._graph.required_by(node)
|
||||
|
||||
def depends_on(self, node):
|
||||
"""
|
||||
Returns a list of Nodes on which 'node' directly depends.
|
||||
"""
|
||||
return self._graph.depends_on(node)
|
||||
|
||||
def scc_order(self):
|
||||
"""
|
||||
Returns a list of lists of Nodes where all elements of each list
|
||||
|
@ -655,6 +643,12 @@ class Node:
|
|||
The ordinal is defined for all Nodes including those that are not
|
||||
'enabled', and is unique among nodes in its EDT 'nodes' list.
|
||||
|
||||
required_by:
|
||||
A list with the nodes that directly depend on the node
|
||||
|
||||
depends_on:
|
||||
A list with the nodes that the node directly depends on
|
||||
|
||||
enabled:
|
||||
True unless the node has 'status = "disabled"'
|
||||
|
||||
|
@ -771,6 +765,16 @@ class Node:
|
|||
return {name: self.edt._node2enode[node]
|
||||
for name, node in self._node.nodes.items()}
|
||||
|
||||
@property
|
||||
def required_by(self):
|
||||
"See the class docstring"
|
||||
return self.edt._graph.required_by(self)
|
||||
|
||||
@property
|
||||
def depends_on(self):
|
||||
"See the class docstring"
|
||||
return self.edt._graph.depends_on(self)
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
"See the class docstring"
|
||||
|
|
|
@ -70,16 +70,16 @@ Directories with bindings:
|
|||
continue
|
||||
|
||||
requires_text = ""
|
||||
if edt.depends_on(node):
|
||||
if node.depends_on:
|
||||
requires_text = "Requires:\n"
|
||||
for depends in edt.depends_on(node):
|
||||
for depends in node.depends_on:
|
||||
requires_text += " {} {}\n".format(depends.dep_ordinal, depends.path)
|
||||
requires_text += "\n"
|
||||
|
||||
supports_text = ""
|
||||
if edt.required_by(node):
|
||||
if node.required_by:
|
||||
supports_text = "Supports:\n"
|
||||
for required in edt.required_by(node):
|
||||
for required in node.required_by:
|
||||
supports_text += " {} {}\n".format(required.dep_ordinal, required.path)
|
||||
supports_text += "\n"
|
||||
|
||||
|
|
|
@ -225,10 +225,10 @@ warning: "#cells:" in test-bindings/deprecated.yaml is deprecated and will be re
|
|||
|
||||
verify_eq(edt.get_node("/").dep_ordinal, 0)
|
||||
verify_eq(edt.get_node("/in-dir-1").dep_ordinal, 1)
|
||||
if edt.get_node("/") not in edt.depends_on(edt.get_node("/in-dir-1")):
|
||||
fail("/ depends-on /in-dir-1")
|
||||
if edt.get_node("/in-dir-1") not in edt.required_by(edt.get_node("/")):
|
||||
fail("/in-dir-1 required-by /")
|
||||
if edt.get_node("/") not in edt.get_node("/in-dir-1").depends_on:
|
||||
fail("/ should be a direct dependency of /in-dir-1")
|
||||
if edt.get_node("/in-dir-1") not in edt.get_node("/").required_by:
|
||||
fail("/in-dir-1 should directly depend on /")
|
||||
|
||||
print("all tests passed")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue