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

Add CMake-format pre-commit hooks and linters #771

Merged
merged 43 commits into from Aug 31, 2020
Merged

Conversation

Skylion007
Copy link
Contributor

Motivation and Context

It ensures we enforce a consistent style across the cmake files in our repo. For the first round, I am only having it handle the code, and not handle any of the formatting of comments. This will also add .circleci check that ensures cmake edits confirm thanks to .circleci. It would also automatically format cmakefiles during commit. Let me know if I should further customize the style file any further.

How Has This Been Tested

I reformatted the code and all the build configs seemed to build just fine.

Types of changes

It adds a new linter. I am also going to do a big spellchecker PR that should fix all the misspellings in comments and code.

Checklist

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Aug 28, 2020
@Skylion007
Copy link
Contributor Author

Skylion007 commented Aug 28, 2020

Also wasn't sure if I should standardize to tabs of space 2 or tabs space size 4, thoughts? I noticed @mosra cmake seem to use tabs of space 4, so I went with that.

@Skylion007
Copy link
Contributor Author

Since I expect this to be controversial, we can set up a configuration like so. Suggestions welcome: https://cmake-format.readthedocs.io/en/latest/index.html

@bigbike
Copy link
Contributor

bigbike commented Aug 28, 2020

This is a very interesting PR. I like it. It makes the CMake related files nice and clean.

Any thoughts? @other reviewers.

# for slightly faster builds. If you need any of these, simply delete a line.
set(WITH_INTERCONNECT
OFF
CACHE BOOL "" FORCE)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what's the logic behind these aggressive line breaks for set arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this style is to accommodate comments on each argument, which makes sense.

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 could also give it control over formatting the cmake comments, but have opted not to for the first run.

gfx
scene
)
target_link_libraries(sensor PUBLIC core gfx scene)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of packing these onto one line. It's easier to notice additions/deletions in diffs when each list item is its own line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They only get packed onto one line if they are three or less arguments. I already lowered the threshold from the default of six.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there some middle ground between "aggressively packing everything with < 4 arguments onto a single line" and "aggressively expanding everything with >= 4 arguments onto several lines"? Something like "always expand target_link_libraries()" or "preserve whatever format was there for certain commands"?

Like, in this case I would prefer to have the args separated on multiple lines because it's very likely more libs will get added later, however with the set(thing CACHE BOOL "bla" OFF) it'll never happen that there will be more arguments and spreading it out like that just adds unnecessary congitive load as the WITH_ options etc are no longer nicely aligned under each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mosra There is, is there anything we should expand besides target_link_libraries?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about doing something similar to the set(bla_SOURCES many things here) commands but most of those lists could be put directly into add_library() / add_executable() ... and conditional sources later added with target_sources().

So maybe add add_executable() and target_sources() to the list as well, even though the latter is probably not used anywhere yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can just make a note to add those later once we use those features.

Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I left a couple comments. I don't feel strongly on style choices and I'm just glad we're gaining consistency here.

set(WITH_GLFWAPPLICATION OFF CACHE BOOL "WITH_GLFWAPPLICATION" FORCE)
set(WITH_EIGEN ON CACHE BOOL "WITH_EIGEN" FORCE) # Eigen integration
set(WITH_IMGUI ON CACHE BOOL "WITH_IMGUI" FORCE) # ImGui integration
set(WITH_TINYGLTFIMPORTER
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erikwijmans It's expressions like this that make prefer the default limit of 6 args per line instead of 3.

Copy link
Collaborator

@mosra mosra left a comment

Choose a reason for hiding this comment

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

General comment: I personally do not like autoformatters because the tool is never smart enough to actually preserve readability instead of just applying rigid rules (and making things worse in many cases).

But this is not my code, so please do not take my opinion too seriously ;)

@Skylion007
Copy link
Contributor Author

@mosra It can be disabled at any point if it really impacts readability. :)

@Skylion007 Skylion007 merged commit 211e4f7 into master Aug 31, 2020
@Skylion007 Skylion007 deleted the cmake_format branch August 31, 2020 19:24
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Make all ipynb work locally

* Add path classifiers to .lgtm

* Remove unncessary glob

* Update black and lint repo

* Sort yaml

* Enable flake8-bugbear plugin

* Fix a few more flake8-bugbear errors

* Attempt to add pre-commit hooks to .circleci

* Add job to .circleci

* Add system dependencies for pre-commit

* Skip system hooks

* fix typo

* Fix .circleci

* Black notebooks

* Remove unused variable and fix clang-format

* Remove another unused variable

* Fix bugs in AttributeManager

* Fix set comprehensions

* Fix EOF

* revert sim bindings

* Fix true false errors

* Ignore C408

* Ignore C402 and C403

* Meant C401 and C402

* Add cmake-format pre-commit hook and cicheck

* Commit cmake-format config

* Fix typos and add missing cmake-formats

* Update cmake-format to ignore Find CMake files

* Adjust cmake-format settings

* Simplify cmake-format to better match our preferences.

* Clean up .pre-commit and cmake-format

* enable autosort cmake-format feature

* Attempt to fix pre-commit hooks

* Changed config to mosra's specification

* always wrap add_library too

* reduce min indent to two

* always wrap find_package

* revert find_package

* final config tweaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants