Skip to content
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

Merged
merged 8 commits into from
Apr 30, 2018
Merged

Conversation

0xc0170
Copy link
Contributor

@0xc0170 0xc0170 commented Apr 10, 2018

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

@0xc0170 0xc0170 changed the title AStyle AStyle addition to travis Apr 10, 2018
@0xc0170 0xc0170 force-pushed the dev_astyle_only_changed branch 10 times, most recently from 4e76b2a to 5da1615 Compare April 11, 2018 07:46
@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 11, 2018

travis-ci/astyle — Passed, 2 warnings

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.
AStyle only checks files changed and suggests them to be corrected.

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)

@@ -25,3 +25,6 @@ SingletonPtr<PlatformMutex> AnalogIn::_mutex;
};

#endif

Copy link
Contributor Author

@0xc0170 0xc0170 Apr 11, 2018

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

@bcostm
Copy link
Contributor

bcostm commented Apr 11, 2018

Checking only files that has changed within the pull request.

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...

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 11, 2018

@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 - is file changed within the PR + is it not in astyle ignore file + is it h/c/cpp/hpp then it is checked

geky
geky previously approved these changes Apr 11, 2018
.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;
Copy link
Contributor

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)".

Copy link
Contributor Author

@0xc0170 0xc0170 Apr 11, 2018

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 ?

Copy link
Contributor

@geky geky Apr 11, 2018

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"? : )

Copy link
Contributor Author

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

Copy link
Contributor Author

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:

  1. we do astyle on master branch
  2. we do astyle on changes (as it is now here)
  3. we show these : master + PR astyle warnings (+/- only PR astyle warnings)

Is that correct?

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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)

@geky geky self-requested a review April 11, 2018 16:06
if [ "$PREV" -ne 0 ]
then
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)"
fi
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 13, 2018

@geky Added another step in after_success . Run astyle on the branch and that one used to compare with master, review please

@0xc0170 0xc0170 force-pushed the dev_astyle_only_changed branch 3 times, most recently from cefc2c2 to b48ff35 Compare April 13, 2018 11:59
@geky
Copy link
Contributor

geky commented Apr 16, 2018

image
@0xc0170!

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 16, 2018

Looks good to me ! +3 warnings will be eliminated once I remove those changes (should be done prior CI stage).

0xc0170 and others added 8 commits April 19, 2018 12:55
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.
@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 19, 2018

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

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 19, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Apr 19, 2018

Build : SUCCESS

Build number : 1802
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6590/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Apr 19, 2018

@mbed-ci
Copy link

mbed-ci commented Apr 19, 2018

@cmonr cmonr merged commit a1307d4 into ARMmbed:master Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants