diff --git a/.circleci/config.yml b/.circleci/config.yml index b64e36e97ed..e3cef735211 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,6 +48,16 @@ jobs: - run: ./ci/install_bazelisk.sh - run: ./ci/do_ci.sh bazel.asan + format: + resource_class: xlarge + docker: + - image: ubuntu:18.04 + steps: + - checkout + - run: ./ci/setup_ci_environment.sh + - run: ./ci/install_format_tools.sh + - run: ./ci/do_ci.sh format + osx_test: macos: xcode: "11.0.0" @@ -72,5 +82,6 @@ workflows: - gcc_48_test - bazel_test - bazel_asan + - format - osx_test - windows diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 00000000000..1c2a64ae254 --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,4 @@ +# If comment markup is enabled, don't reflow the first comment block in +# eachlistfile. Use this to preserve formatting of your +# copyright/licensestatements. +first_comment_is_literal = True diff --git a/ci/Dockerfile b/ci/Dockerfile index 78a0373894f..ffce3429d6c 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -6,8 +6,10 @@ ADD setup_ci_environment.sh /setup-ci ADD setup_cmake.sh /setup-ci ADD install_gcc48.sh /setup-ci ADD install_bazelisk.sh /setup-ci +ADD install_format_tools.sh /setup-ci RUN /setup-ci/setup_ci_environment.sh \ && /setup-ci/setup_cmake.sh \ && /setup-ci/install_gcc48.sh \ - && /setup-ci/install_bazelisk.sh + && /setup-ci/install_bazelisk.sh \ + && /setup-ci/install_format_tools.sh diff --git a/ci/README.md b/ci/README.md index 40519d8d863..c86a2e7d44d 100644 --- a/ci/README.md +++ b/ci/README.md @@ -2,5 +2,7 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do_ci.sh ` where the targets are * `cmake.test` build cmake targets and run tests * `bazel.test` build bazel targets and run tests +* `bazel.asan` build bazel targets and run tests with AddressSanitizer +* `format` use `tools/format.sh` to enforce text formatting Additionally, `./ci/run_docker.sh` can be invoked with no arguments to get a docker shell where tests can be run manually. diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f47ac84bd7e..ba6210a7930 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -24,7 +24,16 @@ elif [[ "$1" == "bazel.test" ]]; then elif [[ "$1" == "bazel.asan" ]]; then bazel test --config=asan $BAZEL_TEST_OPTIONS //... exit 0 -else - echo "Invalid do_ci.sh target, see ci/README.md for valid targets." - exit 1 +elif [[ "$1" == "format" ]]; then + tools/format.sh + CHANGED="$(git ls-files --modified)" + if [[ ! -z "$CHANGED" ]]; then + echo "The following files have changes:" + echo "$CHANGED" + exit 1 + fi + exit 0 fi + +echo "Invalid do_ci.sh target, see ci/README.md for valid targets." +exit 1 diff --git a/ci/install_format_tools.sh b/ci/install_format_tools.sh new file mode 100755 index 00000000000..5e8bccda945 --- /dev/null +++ b/ci/install_format_tools.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +apt install -y clang-format-8 python3-pip golang git +pip3 install cmake_format==0.6.5 +go get github.com/bazelbuild/buildtools/buildifier diff --git a/tools/format.sh b/tools/format.sh index f06dc3cd047..5280715be78 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -41,9 +41,15 @@ else echo " pip install --user cmake_format" fi -if which buildifier >/dev/null; then - echo "Running buildifier." - buildifier $($FIND -name WORKSPACE -print -o -name BUILD -print -o \ +if [[ -z "$BUILDIFIER" ]]; then + BUILDIFIER="$HOME/go/bin/buildifier" + if ! which "$BUILDIFIER" >/dev/null; then + BUILDIFIER=buildifier + fi +fi +if which "$BUILDIFIER" >/dev/null; then + echo "Running $BUILDIFIER" + "$BUILDIFIER" $($FIND -name WORKSPACE -print -o -name BUILD -print -o \ -name '*.bzl' -print) else echo "Can't find buildifier. It can be installed with:"