From bea3570fc25905493c5b8f08f0b89c12a0977a00 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sun, 20 May 2018 17:21:29 +0200 Subject: [PATCH] Make the indenting script and CI use clang-format --- .travis.yml | 2 +- contrib/utilities/indent | 39 ++++++++++++------------ doc/doxygen/headers/coding_conventions.h | 16 +++++----- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0121779323..42dadf52db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ cache: - programs install: - - ./contrib/utilities/setup_astyle.sh + - ./contrib/utilities/download_clang_format script: - ./contrib/utilities/check_indentation.sh diff --git a/contrib/utilities/indent b/contrib/utilities/indent index 41d744fd28..ce6e3a1d95 100755 --- a/contrib/utilities/indent +++ b/contrib/utilities/indent @@ -35,27 +35,28 @@ if test ! -d source -o ! -d include -o ! -d examples ; then exit 1 fi -# Add the location 'setup_astyle.sh' installs astyle to to the local PATH. -ASTYLE_PATH="$(cd "$(dirname "$0")" && pwd)/programs/astyle/bin" -export PATH=$ASTYLE_PATH:$PATH +# Add the location 'download_clang_format' or 'compile_clang_format' +# installs clang-format to to the local PATH. +CLANG_FORMAT_PATH="$(cd "$(dirname "$0")" && pwd)/programs/clang-6/bin" +export PATH="${CLANG_FORMAT_PATH}:${PATH}" -if test ! -f contrib/styles/astyle.rc ; then - echo "*** No style file contrib/styles/astyle.rc found." - exit 1 -fi - -if test -z "$(command -v astyle)" ; then - echo "*** No astyle program found." +if ! [ -x "$(command -v clang-format)" ]; then + echo "*** No clang-format program found." echo "***" - echo "*** You can download astyle from http://astyle.sourceforge.net/" - echo "*** Note that you will need exactly version 2.04 (no newer or" - echo "*** older version will yield the correct indentation)." - echo "*** You can run the 'setup_astyle.sh' script for that." + echo "*** You can run the 'download_clang_format' script or the" + echo "*** 'compile_clang_format' script for obtaining a compatible" + echo "*** binary and installing to an appropriate directory." exit 1 fi -if test "$(astyle --version 2>&1)" != "Artistic Style Version 2.04" ; then - echo "*** Found a version of astyle different than the required version 2.04." +# 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_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') + +if [ "${CLANG_FORMAT_MAJOR_VERSION}" -ne 6 ] || [ "${CLANG_FORMAT_MINOR_VERSION}" -ne 0 ]; then + echo "*** Found a version of clang-format different than the required version 6.0." exit 1 fi @@ -63,7 +64,7 @@ fi # collect all header and source files and process them in batches of 50 files # with up to 10 in parallel -find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 astyle --options=contrib/styles/astyle.rc +find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 clang-format -i # use the same process to set file permissions for all source files find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 chmod 644 @@ -81,14 +82,14 @@ export -f dos_to_unix find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 1 -P 10 -I {} bash -c 'dos_to_unix "$@"' _ {} # format .inst.in files. We need to replace \{ and \} because it confuses -# astyle. +# clang-format format_inst() { f=$1 cp "$f" "$f.tmp" sed -i.orig 's#\\{#{ //#g' "$f.tmp" sed -i.orig 's#\\}#} //#g' "$f.tmp" - astyle --options=none --quiet "$f.tmp" + clang-format -i "$f.tmp" sed -i.orig 's#{ //#\\{#g' "$f.tmp" sed -i.orig 's#} //#\\}#g' "$f.tmp" if ! diff -q "$f" "$f.tmp" >/dev/null diff --git a/doc/doxygen/headers/coding_conventions.h b/doc/doxygen/headers/coding_conventions.h index 900a35b04a..b45b42374b 100644 --- a/doc/doxygen/headers/coding_conventions.h +++ b/doc/doxygen/headers/coding_conventions.h @@ -32,23 +32,22 @@ code is written, without having to look up the exact definition of something.

Notes on deal.II indentation

-

deal.II uses astyle 2.04 to normalize indentation. A +

deal.II uses clang-format 6.0 to normalize indentation. A style file is provided at

-  ./contrib/styles/astyle.rc
+  ${SOURCE_DIR}/.clang-format
 

Before a commit, you should run

-  astyle --options=<SOURCE DIRECTORY>/contrib/styles/astyle.rc <file>
+  clang-format -i <file>
 
on each of your files. This will make sure indentation is conforming to the -style guidelines outlined in this page. Alternatively, if you are using a recent -version of the library, you can run +style guidelines outlined in this page. Alternatively, you can run
   make indent
@@ -73,10 +72,9 @@ source files.
   equivalents (i.e., use &&, ||, and !
   instead of and, or, and not).
 
-
  • In the implementation files, after each function, at least three - empty lines are expected to - enable better readability. One empty line occurs in functions to - group blocks of code, two empty lines are not enough to visibly +
  • In the implementation files, after each function, three empty lines are + expected to enable better readability. One empty line occurs in functions to + group blocks of code, since two empty lines are not enough to visibly distinguish sufficiently that the code belongs to two different functions.
  • Whenever an integer variable can only assume nonnegative values, -- 2.39.5