| 1 |
#!/bin/bash |
| 2 |
## ------------------------------------------------------------------------ |
| 3 |
## |
| 4 |
## SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
## Copyright (C) 2012 - 2025 by the deal.II authors |
| 6 |
## |
| 7 |
## This file is part of the deal.II library. |
| 8 |
## |
| 9 |
## Part of the source code is dual licensed under Apache-2.0 WITH |
| 10 |
## LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 11 |
## governing the source code and code contributions can be found in |
| 12 |
## LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 13 |
## |
| 14 |
## ------------------------------------------------------------------------ |
| 15 |
|
| 16 |
# |
| 17 |
# This script indents all source files of deal.II according to our usual |
| 18 |
# code formatting standards. It is used to ensure that our code base looks |
| 19 |
# uniform, as uniformity helps make code easier to read. |
| 20 |
# |
| 21 |
# While we're already touching every file, this script also makes |
| 22 |
# sure we set permissions correctly and checks for correct unix-style line |
| 23 |
# endings. |
| 24 |
# |
| 25 |
# The script needs to be executed as |
| 26 |
# ./contrib/utilities/indent-all |
| 27 |
# from the top-level directory of the source tree, or via |
| 28 |
# make indent-all |
| 29 |
# from a build directory. |
| 30 |
# |
| 31 |
# The script can be invoked with DEAL_II_CLANG_FORMAT to change |
| 32 |
# the default version of clang-format. For example: |
| 33 |
# DEAL_II_CLANG_FORMAT=clang-format-16.0 ./contrib/utilities/indent-all |
| 34 |
# or, |
| 35 |
# make DEAL_II_CLANG_FORMAT="clang-format-16.0" indent-all |
| 36 |
# |
| 37 |
# Note: If the script is invoked with REPORT_ONLY=true set, |
| 38 |
# REPORT_ONLY=true ./contrib/utilities/indent-all |
| 39 |
# or, |
| 40 |
# make REPORT_ONLY=true indent-all |
| 41 |
# then indentation errors will only be reported without any actual file |
| 42 |
# changes. |
| 43 |
# |
| 44 |
|
| 45 |
if [ ! -f contrib/utilities/indent-all ]; then |
| 46 |
echo "*** This script must be run from the top-level directory of deal.II." |
| 47 |
exit 1 |
| 48 |
fi |
| 49 |
|
| 50 |
if [ ! -f contrib/utilities/indent_common.sh ]; then |
| 51 |
echo "*** This script requires contrib/utilities/indent_common.sh." |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
source contrib/utilities/indent_common.sh |
| 56 |
|
| 57 |
# |
| 58 |
# Run sanity checks: |
| 59 |
# |
| 60 |
|
| 61 |
checks |
| 62 |
|
| 63 |
# |
| 64 |
# Process all source and header files: |
| 65 |
# |
| 66 |
|
| 67 |
process "tests include source module examples contrib/python-bindings" ".*\.(cc|ccm|h)" format_file |
| 68 |
process "source" ".*\.inst.in" format_inst |
| 69 |
process "tests include source examples contrib" ".*\.py" format_python_file |
| 70 |
|
| 71 |
# |
| 72 |
# Fix permissions and convert to unix line ending if necessary: |
| 73 |
# |
| 74 |
|
| 75 |
process "tests include source examples cmake/scripts contrib/python-bindings" \ |
| 76 |
".*\.(cc|h|inst.in|output.*|cmake)" fix_permissions |
| 77 |
|
| 78 |
process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" fix_permissions |
| 79 |
|
| 80 |
process "tests include source examples cmake/scripts contrib/python-bindings" \ |
| 81 |
".*\.(cc|h|inst.in|cmake)" dos_to_unix |
| 82 |
|
| 83 |
process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" dos_to_unix |
| 84 |
|
| 85 |
process "tests include source examples contrib" ".*\.py" dos_to_unix |
| 86 |
|
| 87 |
# |
| 88 |
# Removing trailing whitespace |
| 89 |
# |
| 90 |
|
| 91 |
process "tests include source examples cmake/scripts contrib/python-bindings doc" \ |
| 92 |
".*\.(cc|h|html|dox|txt)" remove_trailing_whitespace |
| 93 |
|
| 94 |
process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" remove_trailing_whitespace |
| 95 |
|
| 96 |
process "tests include source examples contrib" ".*\.py" remove_trailing_whitespace |
| 97 |
|
| 98 |
# |
| 99 |
# Ensure only a single newline at end of files |
| 100 |
# |
| 101 |
|
| 102 |
process "tests include source examples cmake/scripts contrib/python-bindings doc" \ |
| 103 |
".*\.(cc|h|html|dox|txt)" ensure_single_trailing_newline |
| 104 |
|
| 105 |
process "doc/news/*/*" "doc/news/.*/.*/[0-9].*" ensure_single_trailing_newline |
| 106 |
|
| 107 |
process "tests include source examples contrib" ".*\.py" ensure_single_trailing_newline |