File size: 1,933 Bytes
2c3c408 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #!/bin/bash
#
# Licensed 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.
#
# Runs clang format in the given directory
# Arguments:
# $1 - Path to the source tree
# $2 - Path to the clang format binary
# $3 - Apply fixes (will raise an error if false and not there where changes)
# $ARGN - Files to run clang format on
#
SOURCE_DIR=$1
shift
CLANG_FORMAT=$1
shift
APPLY_FIXES=$1
shift
echo "Running clang-format version:" `$CLANG_FORMAT --version`
# clang format will only find its configuration if we are in
# the source tree or in a path relative to the source tree
pushd $SOURCE_DIR
src=$SOURCE_DIR
SOURCE_PATHS=($src/tiledb)
FIND_FILES=(-name "*.cc" -or -name "*.c" -or -name "*.h")
if [ "$APPLY_FIXES" == "1" ]; then
find "${SOURCE_PATHS[@]}" \( "${FIND_FILES[@]}" \) -print0 | xargs -0 -P8 $CLANG_FORMAT -i
else
NUM_CORRECTIONS=`find "${SOURCE_PATHS[@]}" \( "${FIND_FILES[@]}" \) -print0 | xargs -0 -P8 $CLANG_FORMAT -output-replacements-xml | grep offset | wc -l`
if [ "$NUM_CORRECTIONS" -gt "0" ]; then
echo "clang-format suggested changes"
# If running on CI, print out the change-set
if [ "$CI" = true ]; then
echo "-------- see list of files to update below --------"
find "${SOURCE_PATHS[@]}" "${FIND_FILES[@]}" -print0 | xargs -P8 -0 $CLANG_FORMAT -i
git diff --name-only
echo "-------- see diff below --------"
git diff
fi
# Fail the job
exit 1
fi
fi
popd
|