Open Skylion007 opened 4 years ago
This is not a valid cmake file. This looks like a c header which is configured by cmake. Usually I see people name this with a .h.in
extension, rather than .h.cmake
extension... but in any case, I would not expect cmake-format
to do anything but exit with an error code in this case. It looks to me like correct behavior.
Edit: Ok well maybe the error message is a bit obtuse. "invalid cmake code" though is a bit hard to distinguish from other errors, which is why it's classified as an internal error. Perhaps a more helpful error message along the lines of "Is this file actually a cmake file?" could make sense.
@cheshirekow You may still want to tighten up the pre-commit hook a bit though.
A Brief Github Code Search reveals about 74K files that use the .h.cmake extension. I doubt very many of them are actually cmake files. 834 use configure.h.cmake
explicitly
tighten up the pre-commit hook a bit though.
What specifically are you suggesting?
Maybe add a [^.]
to the include regex so it won't accept anything would accept configure.cmake
as valid, but not configure.h.cmake
in the default pre-commit hook include.
Which regex are you referring to?
That's not my repository.
Oh whoops, yeah I see you are using the types in yours: https://github.com/cheshirekow/cmake-format-precommit/blob/master/.pre-commit-hooks.yaml#L4 so it's identify problem, not yours. In which, case just improving the error message should be sufficient.
FYI @Skylion007 , Github code search can be a bit misleading, as the filename
field unfortunately considers neither wildcards nor (unlike the extension
field) exact matches. Of the files whose last extension component is in
, 676 000 containh.in
, 276 000 contain cmake
, while there are 15 500 contain h.cmake.in
.
By contrast, of the files with the cmake
extension, 50 000 have the h.cmake
in the filename, 12 300 have in
somewhere in the filename (but the vast majority of those spot-checked aren't in.cmake
, but rather have it as part of the filename), and only 2279 have h.in.cmake
.
As to the implications for this use case, that's not for me to determine; just wanted to clear up that potential confusion.
I am trying to use cmake_format a pre-commit hook per your other repo, but when scanning the file posted above, it crashes. You should adjust the commit hook or the cmake_format accordingly.