Skip to content

Commit ed7f2e0

Browse files
pillo79danieldegrasse
authored andcommitted
scripts: dts: dtlib: preserve order of properties in DTS output
Ensure that the order of properties in the output DTS file matches the order in which they are defined in the DTS source files by moving props to the end of the dictionary when they are accessed. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 0a4e2e3 commit ed7f2e0

File tree

1 file changed

+4
-3
lines changed
  • scripts/dts/python-devicetree/src/devicetree

1 file changed

+4
-3
lines changed

scripts/dts/python-devicetree/src/devicetree/dtlib.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ def node_iter(self) -> Iterable['Node']:
179179

180180
def _get_prop(self, name: str) -> 'Property':
181181
# Returns the property named 'name' on the node, creating it if it
182-
# doesn't already exist
182+
# doesn't already exist. Move the entry to the end of the props
183+
# dictionary so the order is preserved in the output DTS file.
183184

184-
prop = self.props.get(name)
185+
prop = self.props.pop(name, None)
185186
if not prop:
186187
prop = Property(self, name)
187-
self.props[name] = prop
188+
self.props[name] = prop
188189
return prop
189190

190191
def _del(self) -> None:

0 commit comments

Comments
 (0)