]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make the indenting script and CI use clang-format
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 20 May 2018 15:21:29 +0000 (17:21 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 25 May 2018 07:56:19 +0000 (09:56 +0200)
.travis.yml
contrib/utilities/indent
doc/doxygen/headers/coding_conventions.h

index 0121779323260a3608c8e2459a91f92b7f52e3e2..42dadf52dbe80484d03735b3a3cedd9d001c5ef5 100644 (file)
@@ -13,7 +13,7 @@ cache:
     - programs
 
 install:
-    - ./contrib/utilities/setup_astyle.sh 
+    - ./contrib/utilities/download_clang_format
 
 script: 
     - ./contrib/utilities/check_indentation.sh 
index 41d744fd2857d814292b1b492b423dee66867b9f..ce6e3a1d951bbd31fbc684093eaedbf2713caf9a 100755 (executable)
@@ -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
index 900a35b04ae58fd304acba87fc57b9410c7503b2..b45b42374bf758502134a0c1c37a74aaddfd84e9 100644 (file)
@@ -32,23 +32,22 @@ code is written, without having to look up the exact definition of something.
 
 <h3>Notes on deal.II indentation</h3>
 
-<p>deal.II uses <code>astyle</code> 2.04 to normalize indentation. A
+<p>deal.II uses <code>clang-format</code> 6.0 to normalize indentation. A
 style file is provided at
 <code>
 <pre>
-  ./contrib/styles/astyle.rc
+  ${SOURCE_DIR}/.clang-format
 </pre>
 </code>
 
 <p>Before a commit, you should run
 <code>
 <pre>
-  astyle --options=&lt;SOURCE DIRECTORY&gt;/contrib/styles/astyle.rc &lt;file&gt;
+  clang-format -i &lt;file&gt;
 </pre>
 </code>
 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
 <code>
 <pre>
   make indent
@@ -73,10 +72,9 @@ source files.
   equivalents (i.e., use <code>&&</code>, <code>||</code>, and <code>!</code>
   instead of <code>and</code>, <code>or</code>, and <code>not</code>).
 
-<li> 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
+<li> 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.</li>
 
 <li> Whenever an integer variable can only assume nonnegative values,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.