-
Notifications
You must be signed in to change notification settings - Fork 3k
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
AStyle addition to travis #6590
Conversation
4e76b2a
to
5da1615
Compare
See travis status, info about how many files changed within this pull request are not conforming to our code style. I added 2 files changed for showcase, will revert once this is approved. With this PR , we should be able to add this check and start checking the incoming files for code style. And starting updating our user facing API to conform (few more PR will come) |
drivers/AnalogIn.cpp
Outdated
@@ -25,3 +25,6 @@ SingletonPtr<PlatformMutex> AnalogIn::_mutex; | |||
}; | |||
|
|||
#endif | |||
|
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.
These changes are only to showcase that the script is running properly - only changed files are being checked.
Will be removed prior integration
Good idea but we need a way to skip folders and files from this check. Typically for ST, all the HAL driver files that we copy/paste from ST Cube packages. And the coding style in those files is different from the one in mbed... |
@bcostm The ignore folders are defined in https://github.com/ARMmbed/mbed-os/pull/6590/files#diff-4ed9365cd7635d05b5f90eab986b7a93 (astyleignore file). At the moment targets folder is excluded from the check thus wont affect any HAL/drivers. The rule at the moment is - |
.travis.yml
Outdated
- astyle --version | ||
script: | ||
# only changed files to be checked for astyle | ||
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle.out; |
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.
So master will always say "Passed, 0 warnings".
We could also run the astyle branch on the current commit without printing the warnings so the status says "Passed, 204 warnings" on master. On the PR we can make it say "Passed, 204 warnings (+3 warnings)".
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.
Is that necessary ? Master files are going to be cleaned up all of them (once this is approved, I'll start module by module). Thus master should be always 0. Only PR that modifies the files can be >0. Or?
What is the suggestion ?
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.
The problem is this code will say "Passed, 0 warnings" even if there are 100 warnings.
More PR will come later to start updating the code base
So we don't have 0 warnings yet. Am I wrong?
If we merge this your future PRs aren't going to be very impressive. What will they say? "I removed 50 astyle warnings, reducing the total from 0 warnings to 0 warnings"? : )
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 see your point. This is the first step, master has warnings now.
Your first proposal would be fine. We have a baseline - master - lets say 205 warnings. If PR introduces new ones, would do (+ 10 warnings). That would work until we get 0 on master ! I'll look at changes needed
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.
Still not completely certain about the solution but would it be:
- we do astyle on master branch
- we do astyle on changes (as it is now here)
- we show these : master + PR astyle warnings (+/- only PR astyle warnings)
Is that correct?
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.
Oh! There status script will grab whatever number you have on master and automatically compare with that.
The only thing that needs to change is that CURR is set to the the total number of warnings.
So you probably just need to run astyle again without the changes.
Note we don't need to print out all of the warnings, the diff is more useful.
if [ "$PREV" -ne 0 ] | ||
then | ||
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)" | ||
fi |
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.
As is, once master has an astyle status, PRs will say "Passed, 4 warnings (+4 warnings)". We should probably remove this script from here if we don't want to compare with master.
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.
Why would we not want to compare with master? I would think that having warning delta would be useful, and part of this PR's intent.
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.
See above comment for what's needed to compare with master. As is this is currently broken. (The "+4 warnings" is not a comparison)
if [ "$PREV" -ne 0 ] | ||
then | ||
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)" | ||
fi |
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.
Why would we not want to compare with master? I would think that having warning delta would be useful, and part of this PR's intent.
@@ -0,0 +1,34 @@ | |||
# Mbed OS code style definition file for astyle |
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.
Asking for clarification. Some of these flags and comments sound like they modify the files themselves. Is this actually the case?
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.
modify the files? can you elaborate?
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.
Do flags such as convert-tabs
and indent-cases
modify files?
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.
Yes, they do as any other flags there. astyle runs, changes files according to this style definition.
b264218
to
5f87fe6
Compare
@geky Added another step in after_success . Run astyle on the branch and that one used to compare with master, review please |
5f87fe6
to
e894365
Compare
cefc2c2
to
b48ff35
Compare
Looks good to me ! +3 warnings will be eliminated once I remove those changes (should be done prior CI stage). |
This follows what is in the codebase in most cases (K&R with few exceptions). This should follow also how online compiler formats the code.
Fetch 3.1 astyle from website (install from ubuntu contains old 2.05). Print version to verify and run on our codebase
This should reflect these rules that we have defined since mbed 2: ``` Indentation - 4 spaces. Please do not use tabs. Braces - K&R (see the exception 1 TBS below) 1 TBS -use braces for statements if, else, while, for (exception from K&R) Reference: http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS One line per statement Preprocessor macro starts at the beginning of a new line, the code inside is indented accordingly the code above it Cases within switch are indented (exception from K&R) Space after statements if, while, for, switch, same applies to binary and ternary operators Each line has preferably at most 120 characters For pointers, '*' is adjacent to a data name (analogin_t *obj) or a function name (analog_t *get_analogin_object()) Don't leave trailing spaces at the end of lines Empty lines should have no trailing spaces Unix line endings are default option for files Use capital letters for macros A file should have an empty line at the end ```
To compare to master, use entire branch, not only files changed.
b48ff35
to
c12ee10
Compare
Rebased (latest master) and removed the changes that were testing the script (visible output above in the screen shot #6590 (comment)). time to test this one |
/morph build |
Build : SUCCESSBuild number : 1802 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1450 |
Test : SUCCESSBuild number : 1611 |
Description
This is a new feature - be on master to check the code and be part of Mbed OS 5.9 when most of our codebase actually is conforming to the style.
Checking only files that has changed within the pull request. More PR will come later to start updating the code base
Pull request type
[ ] Fix
[ ] Refactor
[ ] New target
[X] Feature
[ ] Breaking change