Skip to content

Commit ecc1995

Browse files
Stick clang-format version to 11 and add back docker-format.sh (#45)
* Stick clang-format version to 11 and add back docker-format.sh ### Motivation Currently the code is formatted by `clang-format` 11. If it's formatted by other versions of `clang-format`, the style might be a little different. ### Modifications - Add back `docker-format.sh` and the associated `Dockerfile.format`. This script build the image with `python3` and `clang-format-11` installed and the entrypoint is formatting the code. - Explain the `clang-format` version in README. * Move Dockerfile and docker-format.sh to build-support
1 parent 872f8ab commit ecc1995

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ cd tests
222222

223223
## Requirements for Contributors
224224

225-
It's required to install [LLVM](https://llvm.org/builds/) for `clang-tidy` and `clang-format`. Pulsar C++ client use `clang-format` 6.0+ to format files. `make format` automatically formats the files.
225+
It's required to install [LLVM](https://llvm.org/builds/) for `clang-tidy` and `clang-format`. Pulsar C++ client use `clang-format` **11** to format files. `make format` automatically formats the files.
226+
227+
For Ubuntu users, you can install `clang-format-11` via `apt install clang-format-11`. For other users, run `./build-support/docker-format.sh` if you have Docker installed.
226228

227229
We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53.

build-support/Dockerfile.format

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
21+
FROM ubuntu:20.04
22+
23+
WORKDIR /app
24+
25+
RUN apt update -y && apt install -y python3 clang-format-11
26+
ENTRYPOINT ["python3", "./build-support/run_clang_format.py", \
27+
"clang-format-11", \
28+
"0", \
29+
"./build-support/clang_format_exclusions.txt", \
30+
"./lib", \
31+
"./perf", \
32+
"./examples", \
33+
"./tests", \
34+
"./include", \
35+
"./wireshark"]

build-support/docker-format.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
ROOT_DIR=$(git rev-parse --show-toplevel)
22+
cd $ROOT_DIR/build-support
23+
24+
IMAGE_NAME=apachepulsar/cpp-client-format
25+
docker image inspect apachepulsar/cpp-client-format 1>/dev/null 2>&1
26+
OK=$?
27+
set -e
28+
if [[ $OK -ne 0 ]]; then
29+
echo "The image $IMAGE_NAME doesn't exist, build it"
30+
docker build -t $IMAGE_NAME -f ./Dockerfile.format .
31+
fi
32+
docker run -v $ROOT_DIR:/app --rm $IMAGE_NAME

cmake_modules/FindClangTools.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ if (CLANG_FORMAT_VERSION)
8282
endif()
8383
else()
8484
find_program(CLANG_FORMAT_BIN
85-
NAMES clang-format-5
86-
clang-format-5.0
85+
NAMES clang-format-11
86+
clang-format-11.0
8787
clang-format
8888
PATHS ${CLANG_SEARCH_PATHS}
8989
NO_DEFAULT_PATH

0 commit comments

Comments
 (0)