From bd80d9453c3a2cdd6db2e9d131be6c014e1c9b10 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Mon, 17 Oct 2022 18:16:47 +0800 Subject: [PATCH 1/2] 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. --- Dockerfile.format | 35 ++++++++++++++++++++++++++++++ README.md | 4 +++- cmake_modules/FindClangTools.cmake | 4 ++-- docker-format.sh | 32 +++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.format create mode 100755 docker-format.sh diff --git a/Dockerfile.format b/Dockerfile.format new file mode 100644 index 00000000..92d53b03 --- /dev/null +++ b/Dockerfile.format @@ -0,0 +1,35 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +FROM ubuntu:20.04 + +WORKDIR /app + +RUN apt update -y && apt install -y python3 clang-format-11 +ENTRYPOINT ["python3", "./build-support/run_clang_format.py", \ + "clang-format-11", \ + "0", \ + "./build-support/clang_format_exclusions.txt", \ + "./lib", \ + "./perf", \ + "./examples", \ + "./tests", \ + "./include", \ + "./wireshark"] diff --git a/README.md b/README.md index 4cea378a..f6709c7e 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,8 @@ cd tests ## Requirements for Contributors -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. +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. + +For Ubuntu users, you can install `clang-format-11` via `apt install clang-format-11`. For other users, run `./docker-format.sh` if you have Docker installed. We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53. diff --git a/cmake_modules/FindClangTools.cmake b/cmake_modules/FindClangTools.cmake index 4b8fc18e..67128818 100644 --- a/cmake_modules/FindClangTools.cmake +++ b/cmake_modules/FindClangTools.cmake @@ -82,8 +82,8 @@ if (CLANG_FORMAT_VERSION) endif() else() find_program(CLANG_FORMAT_BIN - NAMES clang-format-5 - clang-format-5.0 + NAMES clang-format-11 + clang-format-11.0 clang-format PATHS ${CLANG_SEARCH_PATHS} NO_DEFAULT_PATH diff --git a/docker-format.sh b/docker-format.sh new file mode 100755 index 00000000..0930725e --- /dev/null +++ b/docker-format.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +ROOT_DIR=$(git rev-parse --show-toplevel) +cd $ROOT_DIR + +IMAGE_NAME=apachepulsar/cpp-client-format +docker image inspect apachepulsar/cpp-client-format 1>/dev/null 2>&1 +OK=$? +set -e +if [[ $OK -ne 0 ]]; then + echo "The image $IMAGE_NAME doesn't exist, build it" + docker build -t $IMAGE_NAME -f Dockerfile.format . +fi +docker run -v $PWD:/app --rm $IMAGE_NAME From e17157f14bc9648525f19713c36a0e36da44c968 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Fri, 21 Oct 2022 08:22:04 +0800 Subject: [PATCH 2/2] Move Dockerfile and docker-format.sh to build-support --- README.md | 2 +- Dockerfile.format => build-support/Dockerfile.format | 0 docker-format.sh => build-support/docker-format.sh | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename Dockerfile.format => build-support/Dockerfile.format (100%) rename docker-format.sh => build-support/docker-format.sh (89%) diff --git a/README.md b/README.md index f6709c7e..9701ac33 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,6 @@ cd tests 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. -For Ubuntu users, you can install `clang-format-11` via `apt install clang-format-11`. For other users, run `./docker-format.sh` if you have Docker installed. +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. We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53. diff --git a/Dockerfile.format b/build-support/Dockerfile.format similarity index 100% rename from Dockerfile.format rename to build-support/Dockerfile.format diff --git a/docker-format.sh b/build-support/docker-format.sh similarity index 89% rename from docker-format.sh rename to build-support/docker-format.sh index 0930725e..622a4f15 100755 --- a/docker-format.sh +++ b/build-support/docker-format.sh @@ -19,7 +19,7 @@ # ROOT_DIR=$(git rev-parse --show-toplevel) -cd $ROOT_DIR +cd $ROOT_DIR/build-support IMAGE_NAME=apachepulsar/cpp-client-format docker image inspect apachepulsar/cpp-client-format 1>/dev/null 2>&1 @@ -27,6 +27,6 @@ OK=$? set -e if [[ $OK -ne 0 ]]; then echo "The image $IMAGE_NAME doesn't exist, build it" - docker build -t $IMAGE_NAME -f Dockerfile.format . + docker build -t $IMAGE_NAME -f ./Dockerfile.format . fi -docker run -v $PWD:/app --rm $IMAGE_NAME +docker run -v $ROOT_DIR:/app --rm $IMAGE_NAME