From 2f2f46cd3c83b903e13edd5e0b31c0d56df65dec Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Sat, 23 Jun 2018 13:00:01 +0200 Subject: [PATCH] Choose the clang-format version --- contrib/utilities/indent | 8 +++++++- contrib/utilities/indent-all | 6 ++++++ contrib/utilities/indent_common.sh | 15 +++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/contrib/utilities/indent b/contrib/utilities/indent index 9cd6790c8a..ca889f7fcd 100755 --- a/contrib/utilities/indent +++ b/contrib/utilities/indent @@ -15,7 +15,7 @@ ## --------------------------------------------------------------------- # -# This script does the same thing as contrib/utilities/indent but only +# This script does the same thing as contrib/utilities/indent-all but only # reformats files which have changed (or have been added but neither # staged/commited) since the last merge commit to the master branch. # @@ -25,6 +25,12 @@ # make indent # from a build directory. # +# The script can be invoked with DEAL_II_CLANG_FORMAT to change +# the default version of clang-format. For example: +# DEAL_II_CLANG_FORMAT=clang-format-6.0 ./contrib/utilities/indent +# or, +# make DEAL_II_CLANG_FORMAT="clang-format-6.0" indent +# # Note: If the script is invoked with REPORT_ONLY=true set, # REPORT_ONLY=true ./contrib/utilities/indent # or, diff --git a/contrib/utilities/indent-all b/contrib/utilities/indent-all index f8dfeca48d..8682646ac6 100755 --- a/contrib/utilities/indent-all +++ b/contrib/utilities/indent-all @@ -29,6 +29,12 @@ # make indent-all # from a build directory. # +# The script can be invoked with DEAL_II_CLANG_FORMAT to change +# the default version of clang-format. For example: +# DEAL_II_CLANG_FORMAT=clang-format-6.0 ./contrib/utilities/indent +# or, +# make DEAL_II_CLANG_FORMAT="clang-format-6.0" indent +# # Note: If the script is invoked with REPORT_ONLY=true set, # REPORT_ONLY=true ./contrib/utilities/indent-all # or, diff --git a/contrib/utilities/indent_common.sh b/contrib/utilities/indent_common.sh index df786bc42a..81cf5370f1 100644 --- a/contrib/utilities/indent_common.sh +++ b/contrib/utilities/indent_common.sh @@ -24,6 +24,13 @@ # to ensure that the rest of the indentation pipeline makes sense. # +# +# DEAL_II_CLANG_FORMAT can be used to change the default version of +# clang-format +# + +export DEAL_II_CLANG_FORMAT="${DEAL_II_CLANG_FORMAT:-clang-format}" + checks() { if test ! -d source -o ! -d include -o ! -d examples ; then echo "*** This script must be run from the top-level directory of deal.II." @@ -35,7 +42,7 @@ checks() { CLANG_FORMAT_PATH="$(cd "$(dirname "$0")" && pwd)/programs/clang-6/bin" export PATH="${CLANG_FORMAT_PATH}:${PATH}" - if ! [ -x "$(command -v clang-format)" ]; then + if ! [ -x "$(command -v ${DEAL_II_CLANG_FORMAT})" ]; then echo "*** No clang-format program found." echo "***" echo "*** You can run the './contrib/utilities/download_clang_format'" @@ -46,7 +53,7 @@ checks() { # Make sure to have the right version. We know that clang-6.0.0 # and clang-6.0.1 work. Hence, test for clang-6.0. - CLANG_FORMAT_VERSION="$(clang-format --version)" + CLANG_FORMAT_VERSION="$(${DEAL_II_CLANG_FORMAT} --version)" CLANG_FORMAT_MAJOR_VERSION=$(echo "${CLANG_FORMAT_VERSION}" | sed 's/^[^0-9]*\([0-9]*\).*$/\1/g') CLANG_FORMAT_MINOR_VERSION=$(echo "${CLANG_FORMAT_VERSION}" | sed 's/^[^0-9]*[0-9]*\.\([0-9]*\).*$/\1/g') @@ -103,7 +110,7 @@ format_file() file="${1}" tmpfile="$(mktemp "${TMPDIR}/$(basename "$1").tmp.XXXXXXXX")" - clang-format "${file}" > "${tmpfile}" + "${DEAL_II_CLANG_FORMAT}" "${file}" > "${tmpfile}" fix_or_report "${file}" "${tmpfile}" "file indented incorrectly" rm -f "${tmpfile}" } @@ -131,7 +138,7 @@ format_inst() # picks up and uses the .clang-format style-sheet in the current # directory. # - clang-format < "${tmpfile}" > "${tmpfile}new" + "${DEAL_II_CLANG_FORMAT}" < "${tmpfile}" > "${tmpfile}new" sed -i -e 's#{ // namespace#\\{#g' "${tmpfile}new" sed -i -e 's#}[ ]*// namespace.*#\\}#g' "${tmpfile}new" -- 2.39.5