-
Notifications
You must be signed in to change notification settings - Fork 99
Add cmake-format, and a pre-commit hook for it #1755
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
Conversation
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! Format suggestions:
.cmake-format.json
Outdated
"foo": { | ||
"flags": [ | ||
"BAR", | ||
"BAZ" | ||
], | ||
"kwargs": { | ||
"HEADERS": "*", | ||
"SOURCES": "*", | ||
"DEPENDS": "*" | ||
} | ||
} | ||
}, |
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.
Here we should list the functions that use CMake argument parsing
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.
Here I meant mostly uses of cmake_parse_arguments
, where the formatting tool can otherwise not differentiate between flags/kwargs and regular arguments
benchmark/CMakeLists.txt
Outdated
# \param name name for the executable to create (including type | ||
# suffix) \param use_lib_linops Boolean indicating if linking against | ||
# hipsparse/cusparse is necessary \param macro_def preprocessor macro name | ||
# that will be defined during building (to compile for a specific type) All | ||
# remaining arguments will be treated as source files |
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.
It destories the format
.pre-commit-config.yaml
Outdated
include/ginkgo/ginkgo.hpp | ||
) | ||
- repo: https://github.com/cheshirekow/cmake-format-precommit | ||
rev: 'v0.6.13' # The current latest release |
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 think it is kind of uncontinued project
benchmark/CMakeLists.txt
Outdated
# \param name base-name for the executable to create \param | ||
# use_lib_linops Boolean indicating if linking against hipsparse/cusparse is | ||
# necessary All remaining arguments will be treated as source files |
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.
format issue
cmake/CTestScript.cmake
Outdated
# dashboard. The supported runs are: + With or without coverage, requires the | ||
# gcov tool. + With or without address sanitizers. + With or without memory | ||
# sanitizers. + With or without thread sanitizers. + With or without leak | ||
# sanitizers. + With or without undefined behavior (UB) sanitizers. + With or |
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.
format issue
elseif((NOT CTEST_MEMORYCHECK_TYPE STREQUAL "NONE" AND NOT CTEST_MEMORYCHECK_TYPE STREQUAL "Valgrind") OR CTEST_BUILD_CONFIGURATION STREQUAL "COVERAGE") | ||
set(GINKGO_CONFIGURE_OPTIONS "-DGINKGO_DEVEL_TOOLS=OFF;-DGINKGO_BUILD_REFERENCE=ON;-DGINKGO_BUILD_OMP=ON;-DGINKGO_BUILD_CUDA=OFF;-DGINKGO_BUILD_HIP=OFF;-DGINKGO_BUILD_SYCL=OFF;-DCMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION}") | ||
set(GINKGO_CONFIGURE_OPTIONS | ||
"-DGINKGO_DEVEL_TOOLS=OFF;-DGINKGO_BUILD_REFERENCE=ON;-DGINKGO_BUILD_OMP=OFF;-DGINKGO_BUILD_CUDA=ON;-DGINKGO_BUILD_HIP=OFF;-DGINKGO_BUILD_SYCL=OFF;-DCMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION};-DCMAKE_CUDA_FLAGS=-lineinfo" |
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.
it does not follow column limit
cmake/build_helpers.cmake
Outdated
function(ginkgo_extract_dpcpp_version DPCPP_COMPILER GINKGO_DPCPP_VERSION | ||
MACRO_VAR | ||
) |
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.
a bit weird to me
cmake/build_helpers.cmake
Outdated
set(${GINKGO_DPCPP_VERSION} | ||
"${FOUND_DPCPP_VERSION}" | ||
PARENT_SCOPE | ||
) |
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.
it does not exceed 80 char
cmake/build_type_helpers.cmake
Outdated
STATUS | ||
"Skipping ${_LANG}, not supported by build_type_helpers.cmake script" |
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.
after STATUS, it has one more indentation, but it does not do that after STRING in line 160
cmake/install_helpers.cmake
Outdated
# | ||
# @param name the name of the target | ||
# @param ARGN any external dependencies path to be added | ||
# @param name the name of the target @param ARGN any external dependencies |
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.
wrong format
core/CMakeLists.txt
Outdated
# We separate the library as a workaround to solve this issue | ||
# To make ginkgo still be the major library, we make the original to ginkgo_core in MSVC/shared | ||
# TODO: should think another way to solve it like dllexport or def file | ||
# MSVC: LNK1189 issue CLANG in MSYS2 (MINGW): too many exported symbols We |
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.
wrong format
alternative one is https://github.com/BlankSpruce/gersemi |
6bcf51a
to
bb1c362
Compare
Gersemi is used now, as it also seems to provide a decent setup and has pre-commit support, in addition to being active. The comments needed to be guarded with |
Is there a way to prevent that from happening? Comments are a pretty important and frequent part of the code, and other formatters manage to not mess them up that badly 😁 |
Not all comments, but only the ones where we try to use multi-line doxygen style documentation comments. |
Turns out it is doing the right thing anyway, so disabling it 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.
It seems to preserve all string in ""
LGTM in general.
I still request changes just because I have some questions on that
"-DGINKGO_DEVEL_TOOLS=OFF;-DGINKGO_BUILD_REFERENCE=ON;-DGINKGO_BUILD_OMP=ON;-DGINKGO_BUILD_CUDA=OFF;-DGINKGO_BUILD_HIP=OFF;-DGINKGO_BUILD_SYCL=OFF;-DCMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION}" | ||
) |
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.
can't it follow the column limits?
more on the cmake question not formatter question
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 think it does not break single argument into multiple lines. It was the same before as well, so I think it should be okay.
9bde911
to
f37f975
Compare
|
This PR adds a pre-commit hook to format CMakeLists,txt files. The actual format can still be discussed. But currently, I just formatted all CMakeLists.txt files with the default style. If necessary, we can adjust the style in the
.cmake-format.json
file.Unfortunately, as develop does not have cmake-format hook, the current format job will not run the cmake-format pre-commit hook yet.