Skip to content

Commit a63cb8e

Browse files
pillo79kartben
authored andcommitted
dtlib: fix double empty line before root node
The root node is the first node in the DTS string representation, and is currently separated from the headers by two empty lines. Adjust the spacing so that only one line is printed in all situations. A small adjustment is added to the test suite to keep the current expected outputs unchanged. Signed-off-by: Luca Burelli <[email protected]>
1 parent afdb62d commit a63cb8e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,15 @@ def __str__(self):
945945
Returns a DTS representation of the devicetree. Called automatically if
946946
the DT instance is print()ed.
947947
"""
948-
s = "/dts-v1/;\n\n"
948+
s = "/dts-v1/;\n"
949949

950950
if self.memreserves:
951+
s += "\n"
951952
for labels, address, offset in self.memreserves:
952953
# List the labels in a consistent order to help with testing
953954
for label in labels:
954955
s += f"{label}: "
955956
s += f"/memreserve/ {address:#018x} {offset:#018x};\n"
956-
s += "\n"
957957

958958
return s + str(self.root)
959959

scripts/dts/python-devicetree/tests/test_dtlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def uncomment(dts):
3030
'''Trim added comments from a DT string.'''
3131

3232
# remove node comments, including leading empty line
33+
# but keep the one before the root node
3334
dts = re.sub(r'\n\n[ \t]*/\*.*?\*/\n', '\n', dts, flags=re.DOTALL)
35+
dts = re.sub(r'\n/ {\n', r'\n\n/ {\n', dts)
3436

3537
# remove property comments
3638
dts = re.sub(r'[ \t]*/\*.*?\*/\n', '\n', dts)

0 commit comments

Comments
 (0)