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 <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
ab91eef23b
commit
178f16f9e9
1 changed files with 22 additions and 2 deletions
|
@ -19,6 +19,8 @@
|
|||
# edtlib. This will keep this script simple.
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import edtlib
|
||||
|
@ -40,7 +42,8 @@ def main():
|
|||
|
||||
out_comment("Generated by gen_defines.py", blank_before=False)
|
||||
out_comment("DTS input file: " + args.dts, blank_before=False)
|
||||
out_comment("Directories with bindings: " + ", ".join(args.bindings_dirs),
|
||||
out_comment("Directories with bindings: " +
|
||||
", ".join(map(relativize, args.bindings_dirs)),
|
||||
blank_before=False)
|
||||
|
||||
active_compats = set()
|
||||
|
@ -54,7 +57,8 @@ def main():
|
|||
|
||||
out_comment("Devicetree node: " + node.path)
|
||||
out_comment("Binding (compatible = {}): {}".format(
|
||||
node.matching_compat, node.binding_path),
|
||||
node.matching_compat,
|
||||
relativize(node.binding_path)),
|
||||
blank_before=False)
|
||||
out_comment("Binding description: " + node.description,
|
||||
blank_before=False)
|
||||
|
@ -111,6 +115,22 @@ def parse_args():
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def relativize(path):
|
||||
# If 'path' is within $ZEPHYR_BASE, returns it relative to $ZEPHYR_BASE,
|
||||
# with a "$ZEPHYR_BASE/..." hint at the start of the string. Otherwise,
|
||||
# returns 'path' unchanged.
|
||||
|
||||
zbase = os.getenv("ZEPHYR_BASE")
|
||||
if zbase is None:
|
||||
return path
|
||||
|
||||
try:
|
||||
return str("$ZEPHYR_BASE" / pathlib.Path(path).relative_to(zbase))
|
||||
except ValueError:
|
||||
# Not within ZEPHYR_BASE
|
||||
return path
|
||||
|
||||
|
||||
def write_regs(node):
|
||||
# Writes address/size output for the registers in the node's 'reg' property
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue