uncrustify: add auto uncrustify with blacklist#8519
uncrustify: add auto uncrustify with blacklist#8519kaspar030 merged 3 commits intoRIOT-OS:masterfrom
Conversation
|
we might need to tune again the cfg file though... |
|
Does this have any kind of safety check so that uncrustify does not overwrite local working tree changes? |
dist/tools/uncrustify/check.sh
Outdated
| RIOTBASE=$(git rev-parse --show-toplevel) | ||
| CURDIR=$(cd $(dirname $0) && pwd) | ||
| BLACKLIST=$CURDIR/blacklist.txt | ||
| FILES=$(git ls-tree -r HEAD --name-only --full-tree | grep -E '.*\.(c$|cpp$|h$|hpp$)' | grep -vf $BLACKLIST) |
There was a problem hiding this comment.
if possible, please re-use dist/tools/ci/changed_files.sh
There was a problem hiding this comment.
ah, sure! Didn't know such file existed
that will be the hard part. ;) |
Maybe I could add something that prevents the execution if there are changes (e.g output with |
dist/tools/uncrustify/check.sh
Outdated
| FILES=$(git ls-tree -r HEAD --name-only --full-tree | grep -E '.*\.(c$|cpp$|h$|hpp$)' | grep -vf $BLACKLIST) | ||
| for F in $FILES | ||
| do | ||
| OUT=$(diff $RIOTBASE/$F <(uncrustify -c $CURDIR/uncrustify-riot.cfg -f $RIOTBASE/$F 2>/dev/null)) |
dist/tools/uncrustify/uncrustify.sh
Outdated
| FILES=$(git ls-tree -r HEAD --name-only --full-tree | grep -E '.*\.(c$|cpp$|h$|hpp$)' | grep -vf $BLACKLIST) | ||
| for F in $FILES | ||
| do | ||
| uncrustify -c $CURDIR/uncrustify-riot.cfg --no-backup $RIOTBASE/$F |
There was a problem hiding this comment.
Indentation should be 4 spaces (here and above)
|
@aabadie solved |
|
@jia200x Could you please run your shell scripts through shellcheck? I can enumerate the issues as a review for you if you have trouble using shellcheck. |
|
@bergzand cool! Ran OK. I'm fixing those issues. |
|
@bergzand done. Thanks for the tip! |
dist/tools/uncrustify/uncrustify.sh
Outdated
| BLACKLIST=$CURDIR/blacklist.txt | ||
|
|
||
| . "$RIOTBASE"/dist/tools/ci/changed_files.sh | ||
| FILES=$(changed_files | grep -vf "$BLACKLIST") |
There was a problem hiding this comment.
changed files allows it's own blacklist. Sth like this should be equivalent:
FILES=$(EXCLUDE="(/vendor/|/core/)" changed_files)
edit: fixed regex
There was a problem hiding this comment.
I proposed to provide a separate blacklist.txt file because I think it's easier to add/remove entries from there. Since there might be several blacklisted entries, I thought it was a good idea. What do you think?
There was a problem hiding this comment.
What do you think?
Ok! Then I'd suggest removing "vendor", as that should be filtered by changed_files' defaults.
Anyone reading this, next one who needs a blacklist file needs to add generic support for that to changed_files.sh! ;)
|
@kaspar030 @haukepetersen anything else to blackilist besides core files? |
|
(If this get merged, the uncrustify process should come in a further PR) |
Well, as is uncrustify would change ~24k lines, with many of them unwanted changes. That IMO shows that the config file needs some tuning... I think it'll take some time util we can actually force uncrustify, even for new files. Thus whether core is blacklisted or not is pretty much irrelevant... |
Could you point to some unwanted changes? ;) I can do my best to address them. EDIT: It seems there are still tabs being inserted by the cfg file, I will check |
|
@kaspar030 well, assuming files in upstream are in good shape, I wil try to find the config that minimizes the number of changed files |
|
This is from the first diff uncrustify.sh does on this PR's branch: The alignment is removed here. |
I see.. I will play a little bit with the cfg file |
|
This tool seems a proper way to automate the burden of code style review. Can we advance to make this production ready for
|
|
good luck :-) All the previous attempts to make this work over the last years have failed - but it would be nice to get somewhere this time! I'd say, if applying uncrustify to our codebase yields somwhere < 1000 changes, we are on a good path... |
|
I'm sure @jia200x and others will have energy to make this work: efforts most likely will be honored by a huge burden of labor taken off reviewers shoulders. |
|
Check this gist to see the how the whole RIOT repo (without core files) get's uncrustified. |
|
As discussed offline, let's go with an iterative approach here. One way would be:
Then, successively, add more options from uncrustify-riot.cfg. Probably best would be one per PR to make the discussions both manageable and parallelizable. |
|
@jia200x ready for the first deployment step as outlined by @kaspar030 ? |
|
@kaspar030 are you still interested in this PR? |
yes! I want this to enforce uncrustify once #10867 is in. |
|
#10867 is merged. |
Sure! |
|
ping @jia200x, I have review time tomorrow! |
|
done! |
|
Side note: In another open source project I'm working as a volunteer we are using a linter and a code beautifier. Both are for python code (black and pylint) but the experience has been quite nice. The CI complains if the developer didn't run "black" (beautifier) but also if the linter detect issues (pylint). So I think this can live in harmony with Vera++ |
|
LGTM, please squash! |
|
squashed! |
|
CI passed on compilation but failed on (still set) "needs squashing". re-triggering. |
|
@jia200x I found an issue: the whitelist contains paths, but should contain regexps. Also, each line should match a whole path, not a substring. This patch should fix the issue (adds "-x" for line based patterns to the filter, and fixes the core regexps): |
Co-authored-by: Kaspar Schleiser <[email protected]>
|
fixed, and squashed directly. Thanks for the patch! |
|
does this require Murdock? Can't we add the |
Contribution description
Here is a proposal for the discussion in #4363.
check.shthat could be used from CI. Checks if files in a branch have been uncrustified (close to a automatic style check).To use this tool, simply run either
uncrustify.shfor applying the configuration orcheck.shto check if files have been uncrustified.Does it make sense? Please feel free to give feedback.
Issues/PRs references
#4363