Add script for auto-formatting and validating board lists in Makefiles#10111
Add script for auto-formatting and validating board lists in Makefiles#10111x3ro wants to merge 7 commits intoRIOT-OS:masterfrom
Conversation
|
@MrKevinWeiss @kaspar030 In regards to the "one board per line" vs. "80 characters per line" question, I favor one board per line because it results in much cleaner diffs. For example, in the 80 characters per line case, if I wanted to change the first board in a list, this would likely change all following lines of the list in the diff. |
|
I agree with one line per list item in general for the improved readability in the diffs. |
|
Should we first merge #9965? In master not everything is structured in the same way so I had to manually edit some things. I only stalled because nobody seemed to want one item per line. |
|
I ran my script against the PR with your changes from #9983, and my script would make some additional changes to board lists that fit on one line. You've left them as one line entries, whereas my script is strict in that it only allows one board per line no matter the length. Either way I see no harm in merging that PR first :D |
|
#9983 is right, don't know where I got that number from... |
|
Ya a few that I missed (one liners). Hopefully I can get this pushed through if this is the way we want to go. |
|
Looks like we should merge your script with all the changes that it does. I can do a review when you are ready! |
|
Tiny formatting changes that I would like to discuss: so instead of: BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove \
arduino-uno \
nucleo-f031k6we would get: BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-uno \
nucleo-f031k6 \
# end BOARD_INSUFFICIENT_MEMORY |
|
Okay, the script now formats all three variables. A couple of corner cases popped up, however: Handling comments after a specific board would make the script quite a bit more complex, so I'm kinda hoping there's a way around it :D In such a case I suppose it'd be easy to just put it on the preceding line: These here are a tad more complicated I suppose: But could maybe be formatted as: Finally, there are cases where the list is terminated with a line such as the following, presumably to have a cleaner diff in case the last board is modified. Here the question is if we'd want to introduce this everywhere, or remove it where we're currently doing it: |
|
If we manually fix the corner cases would that make things easier. From what I saw there aren't that many of them and hopefully once they are fixed they stay fixed. At least that is what the review process should enforce. |
|
True, my question was also along the lines of "do we need these corner cases". But I suppose that is a "no", meaning the script would simply not allow comments on board list lines? |
|
@gebart I'm fine with that, I just tried to adapt the script to the most common way currently in use. Who would need to be involved in a discussion to make more serious modifications to the current format? |
|
I also found this one BOARD_PROVIDES_NETIF |
|
Yep, I've put some more work into this, but moving the variables around in the Makefile has a bunch of annoying corner cases that I need to deal with, so its not yet ready for prime time. I'll try to get it done next week once I'm back from vacation :D |
jcarrano
left a comment
There was a problem hiding this comment.
I'm not too familiar with how the static test scrips work, so I'll leave the review as a comment.
|
|
||
| def chdir_to_riot_root(): | ||
| SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
| RIOT_DIR = os.path.realpath(SCRIPT_DIR + "/../../..") |
There was a problem hiding this comment.
I'd prefer a script that does not need to live in a specific location in order to work properly.
There was a problem hiding this comment.
The thought behind this is that I the script is working-directory agnostic. I'm happy with adding an argument that specifies the target directory if that seems useful to anyone, but the default mode of operation, in my opinion, should be "just run it and it will do the correct thing". Given that the script is pretty quick, it's also not a problem to always run it over the entirety of the RIOT code base.
There was a problem hiding this comment.
To expand a bit more: in the case of a general-purpose script, i.e. one that is not intended to live in a particular directory in the RIOT source tree, I'd agree with you. In this case, however, I personally value "it does the right thing automatically" higher than the potential flexibility of being able to pass the target directory.
Furthermore, being able to pass the target directory would make the script potentially more complicated with questions such as "does it also have to work in a directory that is not part of a git repository" or, if the answer is no, checking if I'm in a git repository, ...
| return prefix + (" \\\n" + spacing).join(self.boards) | ||
|
|
||
|
|
||
| def get_affected_filenames(target_variable): |
There was a problem hiding this comment.
Is it acceptable to have both the formatting logic and the file selection logic here?
There was a problem hiding this comment.
I don't think I understand the comment, could you elaborate?
There was a problem hiding this comment.
What happens if I want to auto-format a single Makefile? For example, I want to fix a file before committing it.
There was a problem hiding this comment.
Ah I see. I've been simply running it over the entire code base. It's not too slow, so it hasn't been bothering me. Also has the added benefit of me not being able to forget any Makefile I might've touched 😅
There was a problem hiding this comment.
There are several static checks with the same issue, so it's not a huuuge problem if this script does the same, though at some point it would be nice to have them fixed, but that's an issue for another PR.
|
@x3ro Anything I can do to help the progress? |
It's mostly done, I need to find time to clean it up. Should be feasible sometime this week. |
022aaf5 to
7837b27
Compare
|
@MrKevinWeiss @jcarrano changes made and applied to #10130 |
|
I like the output, if the inline comment and multiple += instead of := / are handled manually (as there are only two cases) then I think at least everyone can agree on the output of it. |
|
@x3ro ping |
|
As a worst case I would like #10130 fixed and merged. |
|
Apologies for the delay, I haven't had time and motivation to pick this up in the last weeks, but I still want to get it merged. I'm aiming for before / at the next Hack 'n' Ack. |
|
@x3ro Yup, just let me know if you need something from me! |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
I would still like to see this or something like this in. If you don't want it I can take over? |
|
Yep I haven't been able to work on it in quite a while. I'll be at Hack'n'Ack this month, and will do my best to get it merged on that day. |
7837b27 to
4f1110d
Compare
|
So I've rebased and gone over the output again. The following seem to be the only files that are not formatted correctly yet:
I'll try to come up with a good fix for inline comments and propose to then go ahead and merge this PR, subsequently update #10130 and get that merged as well. |
|
Very nice, thanks. This is back on my radar! |
3df875e to
ffbab26
Compare
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
Add script for auto-formatting
BOARD_INSUFFICIENT_MEMORYlists, as proposed in #9965. I'll add the finishing touches to this once there is a consensus that this is the desired format. A follow-up PR could then format all boards and add a check to Murdock.I did not end up using @vincent-d's solution proposed in #6818 because I'm terrified of awk scripts 😅
Testing procedure
Run the script with either
validateorformatas parameter.Todo
Issues/PRs references
Fixes #9965
Fixes #6818
Related to #9983