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

Switch to clang-format #410

Merged
merged 17 commits into from
May 30, 2018
Merged

Switch to clang-format #410

merged 17 commits into from
May 30, 2018

Conversation

julianoes
Copy link
Collaborator

@julianoes julianoes commented May 24, 2018

While the clang-format style tries to reflect the previous astyle style
as close as possible, there is, unfortuntately, still a considerable diff.

Fixes #358.

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me as soon as the tests pass!

@hamishwillee
Copy link
Collaborator

@julianoes We mention astyle here: https://docs.dronecore.io/en/contributing/code_style.html

Obviously we're now using clang.

  • What are the style settings defined by (previously it said astyle settings defined by astylerc).
  • Is it still called by make fix_style?
  • Are the explanations accurate? (other than typo "Large enough TO allow ...)

I will have to remove astyle from the dependencies - e.g. : https://docs.dronecore.io/en/contributing/build.html#linux
What do have to add for Clang?

@@ -111,7 +111,7 @@ MAVLinkParameters::do_work()
_state = State::SET_PARAM_BUSY;

char param_id[PARAM_ID_LEN] = {};
STRNCPY(param_id, set_param_work->param_name.c_str(), sizeof(param_id));
STRNCPY(param_id, set_param_work->param_name.c_str(), sizeof(param_id)-1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get that :-/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, forget it, that's in the commit description 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 8 doesn't like the fact that we could potentially copy 17 chars without null termination into param_id. At that point param_id would not be null terminated. That's how I understand it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking, why don't we a hire a local std::string for doing this. Applicable elsewhere in such scenarios as well. Makes sense ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shakthi-prashanth-m I don't think I understand what you mean.

@julianoes
Copy link
Collaborator Author

julianoes commented May 29, 2018

@hamishwillee
@julianoes We mention astyle here: https://docs.dronecore.io/en/contributing/code_style.html

Yes, we are switching.

Obviously we're now using clang.

  • What are the style settings defined by (previously it said astyle settings defined by astylerc).

The settings are defined in .clang-format (added in 7269ce5)

  • Is it still called by make fix_style?

Yes, the usage is the same.

Are the explanations accurate? (other than typo "Large enough TO allow ...)

Yes, that's still the same.

I will have to remove astyle from the dependencies - e.g. : https://docs.dronecore.io/en/contributing/build.html#linux
What do have to add for Clang?

Correct. Developers need to have clang-format version >= 6.

For Ubuntu 16.04: (https://github.com/dronecore/DroneCore/blob/switch-to-clang-format/docker/Dockerfile-Ubuntu-16.04#L37-L42)

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
sudo apt-get update
sudo apt-get install -y clang-format-6.0
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 1000

Ubuntu 18.04: (https://github.com/dronecore/DroneCore/blob/switch-to-clang-format/docker/Dockerfile-Ubuntu-18.04#L21)

sudo apt-get install clang-format
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 1000

Fedora 28: (https://github.com/dronecore/DroneCore/blob/switch-to-clang-format/docker/Dockerfile-Fedora-28#L14)

sudo dnf install clang

Copy link
Contributor

@shakthi-prashanth-m shakthi-prashanth-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many new changes 👍 Code looks clean now :-)

_ground_speed_ned_rate_hz(0.0),
_position_rate_hz(-1.0)
TelemetryImpl::TelemetryImpl(System &system)
: PluginImplBase(system), _position_mutex(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some places like these (constructor member initialization), I feel old style is better readable. But, thats unavoidable I think.

Copy link
Collaborator Author

@julianoes julianoes May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I was going to look at the changes and figure out how to prevent some of them.

julianoes and others added 17 commits May 30, 2018 10:54
This is an attempt to come up with the config for clang-format 6 which
matches our current format as close as possible.

Some options for clang-format 7 are currently commented out.
The destination needs to be 1 char longer than the num of chars that are
copied in order to make sure the resulting string at the destination is
null-terminated.
This means that we can generate the binaries for multiple distro
versions.
We switched from astyle to clang-format. Even though we tried to match
the previous style as much as possible, there are still a few changes
needed.
@julianoes
Copy link
Collaborator Author

@shakthi-prashanth-m @JonasVautherin I changed some of the clang-format options to match the previous style closer. Have another look please if you see anything too ugly.

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@julianoes julianoes merged commit 3fcc9da into develop May 30, 2018
@julianoes julianoes deleted the switch-to-clang-format branch May 30, 2018 16:20
rt-2pm2 pushed a commit to rt-2pm2/DronecodeSDK that referenced this pull request Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Its time to switch Coding style to Clang format
4 participants