-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative and deterministic DT comments #19333
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
# edtlib. This will keep this script simple. | ||
|
||
import argparse | ||
import os | ||
from pathlib import Path | ||
import sys | ||
|
||
import edtlib | ||
|
@@ -40,7 +42,20 @@ 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), | ||
|
||
zbase = Path(os.environ["ZEPHYR_BASE"]) | ||
shorter_bdirs = {} | ||
for d in args.bindings_dirs: | ||
try: | ||
shorter_bdirs[d] = Path(d).relative_to(zbase) | ||
except ValueError: | ||
# leave as is when outside ZEPHYR_BASE | ||
shorter_bdirs[d] = Path(d) | ||
|
||
out_comment("Directories with bindings: " + | ||
", ".join([ str("ZEPHYR_BASE" / d) | ||
for d in shorter_bdirs.values() | ||
]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Poked around for a while and came up with a helper function that might be handy here: 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(map(relativize, args.bindings_dirs)),
blank_before=False) Definition (I put it after 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.
if "ZEPHYR_BASE" not in os.environ:
return path
try:
return str("$ZEPHYR_BASE" /
Path(path).relative_to(os.environ["ZEPHYR_BASE"]))
except ValueError:
# Not within ZEPHYR_BASE
return path Has the advantage that Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also do: zbase = os.environ.get("ZEPHYR_BASE")
if not zbase:
return path
... / Path(path).relative_to(zbase) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, bit neater. |
||
blank_before=False) | ||
|
||
active_compats = set() | ||
|
@@ -53,7 +68,7 @@ def main(): | |
continue | ||
|
||
out_comment("Device tree node: " + dev.path) | ||
out_comment("Binding (compatible = {}): {}".format( | ||
out_comment("DTS Binding (compatible = {}): {}".format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remembered that |
||
dev.matching_compat, dev.binding_path), | ||
blank_before=False) | ||
out_comment("Binding description: " + dev.description, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tinkered a bit and came up with a
dict
-less version.zip()
is for iterating both lists at the same time.binding_paths()
would be similar to the old version:Thoughts?
It seems to indirectly remove the
./
at the start of paths too, so would need a test suite update.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is better than a dict but why not, LGTM.
One of things I liked about the dict is that... it could be done in a small number of changed lines which is easier to rebase constantly. Not the best of reasons, granted :-)