-
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
scripts: dts: Output paths relative to $ZEPHYR_BASE #19444
Conversation
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.
Tested and works! See inline.
scripts/dts/edtlib.py
Outdated
for bdir in bindings_dirs: | ||
for bpath in _binding_paths(bdir): | ||
self._binding_paths.append(bpath) | ||
relpaths.append(os.path.relpath(bpath, bdir)) |
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.
This part of the code is confusing because there are not just two but three parts involved in the paths here:
- ZEPHYR_BASE
dts/bindings
some/dir/file.yaml
I think I remember what this particular relpath() does but barely and that's after me having designed, written and thoroughly tested the first version of this in PR #19333! So imagine someone new to this code...
=> this deserves: - either more comments clarifying what is relative to what (some dts/bindings
example wouldn't hurt); - or super-smart variable names, much more elaborated than these. Adding comments seems obviously faster and easier ("If I Had More Time, I Would Have Written a Shorter Letter - Blaise Pascal)
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.
Lengthened the variable names and added a comment. The relpath()
is to remove the path to the binding directory, turning e.g. path/to/zephyr/dts/bindings/sub/foo.yaml
into sub/foo.yaml
.
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. |
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.
While the other fix is really under-commented, maybe this one is a bit over-commented?
Also why no pydoc syntax? (if anything)
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 usually do doc comments unless it's part of the API for some library. Another way of marking it internal, kinda. If it was an internal part of a library (gen_defines.py
is just a script), I'd put _
before the name too.
Not saying that's the one true way to do it, but there's a method to the madness. ;)
46cb409
to
78884ff
Compare
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 think replacing a path prefix that matches ${ZEPHYR_BASE}
with ${ZEPHYR_BASE}
(with or without braces) is a good idea, for privacy as well as reproducibility.
But ${DTS_ROOT_BINDINGS}
may contain several directories, and the same compatible may appear in multiple locations (e.g. when being overridden for an application or a board). The current tooling appears to mishandle this (#19536).
This patch also removes everything but the relative path, losing the information about exactly which file provided the binding for the compatible. That's not really acceptable, IMO.
So, +1 for the ${ZEPHYR_BASE}
piece, -1 for the relpath piece. We should get:
/* Directories with bindings: $ZEPHYR_BASE/dts/bindings */
...
/* Binding (...): $ZEPHYR_BASE/dts/bindings/interrupt-controller/arm,v7m-nvic.yaml */
Wonder how to deal with binding directories outside One thing I considered was making it Not guaranteed to be unique either I guess. |
Hmm... seems the Think I'll move it all to |
From a build reproducibility perspective (= the initial rationale for this), anything that generates the exact same files when building from two different git clones is acceptable. For instance, no comment at all is acceptable ;-) |
I would prefer that to providing misleading/incomplete information, even though it makes the system less usable. I guess it's a question of whether build reproducibility is a more important criterion than "providing information that's helpful to the developer". Another approach would be to provide a hook for a post-processing step that strips out irrelevant differences when performing a build that must be "reproducible". |
78884ff
to
7901ffd
Compare
Updated it to do the thing @pabigot suggested (just stripping That makes it deterministic as long as there are no binding directories outside @marc-hb |
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]>
7901ffd
to
2ecd481
Compare
I will test and get back to you.
Some sort of WEST_TOP (#19440) would be a great next step. Beyond that would be even better but I'm not looking that far TBH. Fixing everything inside ZEPHYR_BASE will already make a huge difference. |
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.
works4me
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.
This seems to do what's expected on the multi-directory test case I have.
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:
After: