Format.cmake
Format.cmake copied to clipboard
Exclude paths/files from being formatted
We use kind of mono repo and thus our repo consists of a mix of languages such as C++, Python, Go and Java. The tree is somewhat akin to this.
How do we exclude certain paths and files from being formatted? Alternatively, is there a way to include only certain paths?
$ tree -a
.
├── .clang-format
├── .cmake-format
├── CMakeLists.txt
├── cpp1
│  └── main.cpp
├── cpp2
│  └── main.cpp
├── go1
│  └── main.go
├── go2
│  └── main.go
├── java1
│  └── Main.java
├── java2
│  └── Main.java
├── proto
│  ├── Message.proto
│  └── Service.proto
├── python1
│  └── main.py
└── python2
└── main.py
See https://clang.llvm.org/docs/ClangFormat.html#clang-format-ignore
I think the python script in this repo is overriding it. See:
/tmp/repo (main)$ clang-format --version
Ubuntu clang-format version 18.1.3 (1ubuntu1)
/tmp/repo (main)$
/tmp/repo (main)$ ll .clang-format*
-rw-r--r-- 1 arun arun 1110 Mar 12 16:20 .clang-format
-rw-r--r-- 1 arun arun 10 Mar 12 16:25 .clang-format-ignore
/tmp/repo (main)$
/tmp/repo (main)$ cat .clang-format-ignore
java*
go*
/tmp/repo (main)$ cd build
/tmp/repo/build (main)$
/tmp/repo/build (main)$ ninja fix-format
[1/2] cd /tmp/repo && /bin/python3 /tmp/repo/build/_deps/format.cmake-src/git-clang-format.py --binary=/bin/clang-format 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -f
FAILED: _deps/format.cmake-build/CMakeFiles/fix-clang-format /tmp/repo/build/_deps/format.cmake-build/CMakeFiles/fix-clang-format
cd /tmp/repo && /bin/python3 /tmp/repo/build/_deps/format.cmake-src/git-clang-format.py --binary=/bin/clang-format 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -f
Configuration file(s) do(es) not support Java: /tmp/repo/.clang-format
error: `/bin/clang-format -lines=1:5 java1/Main.java` failed
[2/2] cd /tmp/repo && /usr/bin/cmake -DGIT_PROGRAM=/bin/git -DCMAKE_FORMAT_PROGRAM=/bin/cmak...e-build -DCMAKE_FORMAT_EXCLUDE= -P /tmp/repo/build/_deps/format.cmake-src/cmake-format.cmake ninja: build stopped: subcommand failed.
/tmp/repo/build (main)$
I think the python script in this repo is overriding it
I know, that's the problem with this cmake module!
Try:
git ls-files ::*.cpp ::*.json | xargs clang-format -i
I know how to run clang-format. The bug report is about this cmake module. So explicit clang-format invocation is not the solution.
see https://github.com/TheLartians/Format.cmake/issues/41
The implementation is not as good as it should with an old local copy of the clang-format.py script.
That is the real problem.