Debian Codegraph @

contrib/utilities/indent

raw
1 #!/bin/bash
2 ## ------------------------------------------------------------------------
3 ##
4 ## SPDX-License-Identifier: LGPL-2.1-or-later
5 ## Copyright (C) 2014 - 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 does the same thing as contrib/utilities/indent-all but only
18 # reformats files which have changed (or have been added but neither
19 # staged/committed) since the last merge commit to the master branch.
20 #
21 # The script needs to be executed as
22 # ./contrib/utilities/indent
23 # from the top-level directory of the source tree, or via
24 # make indent
25 # from a build directory.
26 #
27 # The script can be invoked with DEAL_II_CLANG_FORMAT to change
28 # the default version of clang-format. For example:
29 # DEAL_II_CLANG_FORMAT=clang-format-16.0 ./contrib/utilities/indent
30 # or,
31 # make DEAL_II_CLANG_FORMAT="clang-format-16.0" indent
32 #
33 # Note: If the script is invoked with REPORT_ONLY=true set,
34 # REPORT_ONLY=true ./contrib/utilities/indent
35 # or,
36 # make REPORT_ONLY=true indent
37 # then indentation errors will only be reported without any actual file
38 # changes.
39 #
40
41 if [ ! -f contrib/utilities/indent ]; then
42 echo "*** This script must be run from the top-level directory of deal.II."
43 exit 1
44 fi
45
46 if [ ! -f contrib/utilities/indent_common.sh ]; then
47 echo "*** This script requires contrib/utilities/indent_common.sh."
48 exit 1
49 fi
50
51 source contrib/utilities/indent_common.sh
52
53 #
54 # Run sanity checks:
55 #
56
57 checks
58
59 #
60 # Process all source and header files:
61 #
62
63 process_changed "tests include source module examples cmake/scripts contrib/python-bindings" ".*\.(cc|ccm|h)" format_file
64 process_changed "source" ".*\.inst.in" format_inst
65 process_changed "tests include source examples contrib" ".*\.py" format_python_file
66
67 #
68 # Fix permissions and convert to unix line ending if necessary:
69 #
70
71 process_changed "tests include source examples cmake/scripts contrib/python-bindings" \
72 ".*\.(cc|h|inst.in|output.*|cmake)" fix_permissions
73
74 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" fix_permissions
75
76 process_changed "tests include source examples cmake/scripts contrib/python-bindings" \
77 ".*\.(cc|h|inst.in|cmake)" dos_to_unix
78
79 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" dos_to_unix
80
81 process_changed "tests include source examples contrib" ".*\.py" dos_to_unix
82
83 #
84 # Removing trailing whitespace
85 #
86
87 process_changed "tests include source examples cmake/scripts contrib/python-bindings doc" \
88 ".*\.(cc|h|html|dox|txt)" remove_trailing_whitespace
89
90 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" remove_trailing_whitespace
91
92 process_changed "tests include source examples contrib" ".*\.py" remove_trailing_whitespace
93
94 #
95 # Ensure only a single newline at end of files
96 #
97
98 process_changed "tests include source examples cmake/scripts contrib/python-bindings doc" \
99 ".*\.(cc|h|html|dox|txt)" ensure_single_trailing_newline
100
101 process_changed "doc/news/*/*" "doc/news/.*/.*/[0-9].*" ensure_single_trailing_newline
102
103 process_changed "tests include source examples contrib" ".*\.py" ensure_single_trailing_newline