Skip to content

Commit 178f16f

Browse files
ulfalizergalak
authored andcommitted
scripts: dts: Output paths relative to $ZEPHYR_BASE
Requested by Marc Herbert. Makes the output deterministic as long as all binding directories are within $ZEPHYR_BASE (and a bit less spammy too). Example output for header: Before: /* Directories with bindings: /home/ulf/z/z/dts/bindings */ ... /* Binding (...): /home/ulf/.../arm,v7m-nvic.yaml */ After: /* Directories with bindings: $ZEPHYR_BASE/dts/bindings */ ... /* Binding (...): $ZEPHYR_BASE/dts/.../arm,v7m-nvic.yaml */ Signed-off-by: Ulf Magnusson <[email protected]>
1 parent ab91eef commit 178f16f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

scripts/dts/gen_defines.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# edtlib. This will keep this script simple.
2020

2121
import argparse
22+
import os
23+
import pathlib
2224
import sys
2325

2426
import edtlib
@@ -40,7 +42,8 @@ def main():
4042

4143
out_comment("Generated by gen_defines.py", blank_before=False)
4244
out_comment("DTS input file: " + args.dts, blank_before=False)
43-
out_comment("Directories with bindings: " + ", ".join(args.bindings_dirs),
45+
out_comment("Directories with bindings: " +
46+
", ".join(map(relativize, args.bindings_dirs)),
4447
blank_before=False)
4548

4649
active_compats = set()
@@ -54,7 +57,8 @@ def main():
5457

5558
out_comment("Devicetree node: " + node.path)
5659
out_comment("Binding (compatible = {}): {}".format(
57-
node.matching_compat, node.binding_path),
60+
node.matching_compat,
61+
relativize(node.binding_path)),
5862
blank_before=False)
5963
out_comment("Binding description: " + node.description,
6064
blank_before=False)
@@ -111,6 +115,22 @@ def parse_args():
111115
return parser.parse_args()
112116

113117

118+
def relativize(path):
119+
# If 'path' is within $ZEPHYR_BASE, returns it relative to $ZEPHYR_BASE,
120+
# with a "$ZEPHYR_BASE/..." hint at the start of the string. Otherwise,
121+
# returns 'path' unchanged.
122+
123+
zbase = os.getenv("ZEPHYR_BASE")
124+
if zbase is None:
125+
return path
126+
127+
try:
128+
return str("$ZEPHYR_BASE" / pathlib.Path(path).relative_to(zbase))
129+
except ValueError:
130+
# Not within ZEPHYR_BASE
131+
return path
132+
133+
114134
def write_regs(node):
115135
# Writes address/size output for the registers in the node's 'reg' property
116136

0 commit comments

Comments
 (0)