-
Notifications
You must be signed in to change notification settings - Fork 0
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
clang-tidy: allow target to be disabled #109
Conversation
This is one of the things I tried when writing this module but had to change it because of the idiotic way To get around the git thing we just add |
Also if you really want a custom .clang-tidy you can use the LegayClangTidy module which doesn't so any autogeneration of config |
There seemed to be a command line option to pass in a config in the parallel clang-tidy script. |
Why do we need to generate the .clang-tidy? Just to have it the same across all repos? I think we could turn off the auto generate and still use this module (but check in a copy of the generated .clang-tidy). If there's a benefit to doing it that way? |
That's what used to happen but there were constant problems where someone would make a change to (of course if we can flatten everything down this becomes much less of a problem.....) |
There isn't such an option for plain old |
@woodfell Thanks for clarifying the state of play here, ideally we'd like to get libswiftnav where it doesn't modify itself during compilation, do you have a recommendation here? |
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.
Maybe this is over-complicating things but it's possible we could add an optional parameter to the clang tidy module that allows the user to specify the directory it gets written to (defaults to CMAKE_SOURCE_DIR).
We add an option to libswiftnav (i.e. -DCLANG_TIDY_DIR
) that defaults to CMAKE_SOURCE_DIR
, so that we don't break local dev workflows.
Then in libswiftnav-rs we could add a CMakeLists.txt
that overrides this to CMAKE_BINARY_DIR
, (or as a cmake arg in the rust build scripts).
I was thinking we could take the approach we've taken in other places with generated content that has to live "in tree", which is to require that changes/updates must be intentionally staged and committed. That is:
So, if clang-tidy was updated, this would require all bumps to the cmake module to include an update to the generated We could also optionally enable this behavior (only for repos that care about this behavior)-- so the "generate and git diff" dance would only happen if the @isaactorz @woodfell thoughts? |
Yeah that sounds like it would work. But what's the problem with using |
It triggers this check when attempting to release/package Example:
|
But we can get around this by making the directory the clang-tidy file gets written to variable (my suggestion above). That would be a lot more lightweight change to implement to this module than your suggestion above. We also wouldn't need to patch every repo using this module every time we make a change to it. Are there any other big advantages for having the |
I see. Another way could be to add a command line flag to complete disable the ClangTidy module. We then use than flag from |
Yeah, the simplicity of your suggestion is a big upside. However, I don't think we should build this change without the "explicit enable" part, that is, you'd be required to check-in a copy of
The benefit is just the "out of the box" factor, if anyone else is consuming the repo, they don't need to know about our cmake stuff to prevent it from modifying the source tree. |
Yeah, that would work too (don't need clang-tidy targets for a wrapped build). |
I ported over the ability to disable the |
So, this is probably the best option, seems this is already something we were using in this module: https://github.com/swift-nav/swiftnav-rs/blob/master/swiftnav-sys/build.rs#L20 -- this was probably broken when the new clang-tidy module was introduced. |
ClangTidy.cmake
Outdated
# Global clang-tidy enable option, influences the default project specific enable option | ||
option(ENABLE_CLANG_TIDY "Enable auto-linting of code using clang-tidy globally" ON) | ||
if(NOT ENABLE_CLANG_TIDY) | ||
early_exit(STATUS "auto-linting is disabled globally") |
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.
Early exit is a macro that's not defined in this module (defined in OldClangTidy.cmake
).
Might want to test these changes in a branch of libswiftnav.
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 did test this and it seemed to work?
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.
Ah ok I see why it didn't break.
I guess macros get global scope once they're defined. This works because it's picking up the version of this macro that's defined in ClangFormat.cmake
, because that module gets included before hand (bit like relying on a transitive include in C/C++).
It's a nit but these things break sometimes when shuffling around build files and then it's a pain to track them down after the fact.
The best thing would be to define these common helper macros and functions in a common file, but for now it would be sufficient to just define the macro in the places it gets used.
Co-authored-by: Isaac Torres <[email protected]>
Kudos, SonarCloud Quality Gate passed! |
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
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!
When attempting to package
libswiftnav
as part ofswiftnav-rs
, the automation forclang-tidy
that generates a common config for all of our repos causes a validation check incargo publish
to fail, this attempts to verify that builds don't modify themselves, see: https://github.com/rust-lang/cargo/blob/50d52ebf0ef91f392f47b4d9b9e954bb25c60aca/src/cargo/ops/cargo_package.rs#L815Example:
To work around this we are re-introducing the ability to disable the
clang-tidy
targets in the "modern"clang-tidy
cmake module. This is ported over from theOldClangTidy.cmake
module.Testing here: https://github.com/swift-nav/libswiftnav/commits/silverjam/disable-clang-tidy (and here for Rust: https://github.com/swift-nav/swiftnav-rs/commits/silverjam/disable-clang-tidy).
With
❯ cmake -B build -S . -DENABLE_CLANG_TIDY=OFF
:With
❯ cmake -B build -S . -Dlibswiftnav_ENABLE_CLANG_TIDY=OFF
: