-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add format
compilation target that applies clang-format
to whitelisted modules
#3188
Conversation
One thing to consider: different versions of (Note that I use the verb may. From my past experience some versions were fully compatible (or at least did not expose incompatibilities on my projects), whereas some were not. We will need to check empirically I'm afraid.) I guess the only way out is to make the "official" formatter version(s) an explicit part of the style definition. CMake thus has to check if the version that the user has is compatible. |
So, I decided to check it out. For future reference, I'm detailing the broad changes between different versions of clang-format since I didn't find them after a cursory search.
This means we can choose any version after 6 based on the default version available on the systems we are targeting preferentially. I leave the final choice to you. And yes, it does make sense to say: this |
Given your discoveries I would keep the requirement loose: version >= 6.0, until we're required to change it again. |
Wow, thanks for the research. I agree with @SergioRAgostinho, let's require >= 6.0. Another question you've raised is which files we should format. I think we should exclude |
5854fd7
to
06b900e
Compare
PTAL. Should work on alpine, ubuntu both. |
Let's stay with 3.5, we don't want to drop support for Ubuntu 16.04 yet. PCL has an utility function to filter a list by regex. |
OK. Got it. I need to exclude a regex, so the utility function doesn't help but steers me towards the right direction. Thanks |
I've made a bunch of changes as suggested. I'll try to remove any errors tomorrow. Just pushed a trial version. |
A meta-comment: please don't squash/force-push without need. It makes incremental reviewing harder since it's not clear what has been changed in between now and the last time I reviewed. When we are done with preparing the PR we will have an opportunity to reshape the history to our liking before merging. |
@taketwo @SergioRAgostinho PTAL. Test matrix:
Sorry about the rebase+force before. |
Since my comments got lost, I will re-add them again. |
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.
Great, thanks for applying the changes. I think the scripts are in a pretty good shape now!
Let's discuss the next steps. This format
target is of no use until the repository is reformatted to the style. Question is when we are going to do this. Before/after release? We have a bunch of pending PRs which we probably don't want to screw up with reformatting.
One idea that I had is to introduce formatting gradually. That is, pick a module that currently has no pending changes and add it to the formatting "white-list". Format it. Then we can start experimenting with CI job that checks formatting (but only in that module). Such an approach will allow us to move forward and try things without an enormous reformatting upfront. What do you guys think?
How about any future PR needs to be formatted correctly? By creating a separate branch called
Maybe I can modify the script to add multiple targets.
How to do this should be the focus. If this is not automated and done in parts, it'll be an uphill battle. |
Well if you are on Windows you just use/need Visual Studio and then you may want to use Visual Studio Code. As you already find out, they both offer I'm stuck with VS 15.6.7, so I don't have |
I'd say let's move on with a shell script. We only have limited resources and a truly cross-platform solution would require too much effort. In future VS will certainly update to a newer |
I've added a script (There's a spurious echo and an exit statement, which I'll remove after I'm done testing on ubuntu-16 and ubuntu-18). PTAL |
dev/format.sh
Outdated
) | ||
local PCL_DIR="${PCL_DIR:-${guess_PCL_DIR}}" | ||
|
||
local formatter_versions="9 9.0 8 8.0 7 7.0 6 6.0" |
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.
Could you elaborate what's the purpose of this block? The formatter executable is passed as $1
to the script, why don't we use it directly?
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 added this despite the FindClangFormat.cmake because
- cmake will inform developers nicely about the missing version
- for just formatting, there's no need to run cmake. This script is self sufficient, allowing it to be run without installing dependencies required by cmake. Possible scenario can be CI/CD or a format based hot-fix to a PR from a machine with limited dev-tools
dev/format.sh
Outdated
# don't use a directory with whitespace | ||
local whitelist="2d cuda gpu ml simulation stereo tracking" | ||
|
||
local guess_PCL_DIR="$(dirname "$0")/../" |
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.
What about passing PCL_DIR
as an argument to the script? Then no need to cd/pwd and guessing.
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.
2 separate reasons:
- reducing confusion and checking for mixing
clang-format-path
andpcl-source-path
- technically, the guess is very good except a corner case (soft-links along the
dirname $0
)
Only power users need to provide the PCL_DIR as input args or env var, and I figured the env var would be less confusing.
The change to cli arg input is easy I had that before I moved to env var based backup
I understand your idea of making it possible to run The reason why I'm sort of against these guesses is that it duplicates functionality and increases maintenance burden. We now have |
No problem. I've made the changes and also added cuda. As per clang-format output, it should be okay in the future too. |
Great, thanks. One last thing (promise 😄) that I want to discuss is the location of the script. Generally, at the top level of our directory hierarchy are modules (aka libraries: |
I'm totally fine with |
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 to finish this off I propose to add the final formatting config and regroup commits:
- add clang-format config
- add shell script
- add cmake target
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 expected, works well with Ninja.
I updated the PR description (i.e. the first comment) with a summary and links to the issues you mentioned (this will make sure that they are closed automatically once this one is merged). |
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.
LGTM. Thank you all. I will just give it a quick test and merge if everything goes well.
format
compilation target to apply clang-format
to whitelisted modules
format
compilation target to apply clang-format
to whitelisted modulesformat
compilation target to apply clang-format
to whitelisted modules
format
compilation target to apply clang-format
to whitelisted modulesformat
compilation target that applies clang-format
to whitelisted modules
.clang-format
file added from details gleaned via website. PTALTODO:
Compile and test on:
Please run
cmake
and check ifmake format
is correct as per the standards.It modifies all the files, including
doc
,tools
,test
,outofcore
,examples
, ....*/3rd_party
so that might not be the desired behavior or whatever reason. Though we do own all code in the repo and it should be ok to format it as per the guidelines.Executive summary
This PR adds:
clang-format
. This is not intended to be used by developers directly.format
that formats PCL codebase. This is to be used by developers.At the moment formatting will only be applied to a selected list of PCL modules. This while listing will be removed after the "testing period" is over.
Closes #3190, #2106, and #2376 (obsoleted).