]> git.ipfire.org Git - thirdparty/pdns.git/blob - build-scripts/format-code
Merge pull request #8505 from rgacogne/dnsdist-lua-ffi
[thirdparty/pdns.git] / build-scripts / format-code
1 #!/bin/sh
2
3 #
4 # Reformat code, but do not touch if no changes.
5 #
6
7 if [ "$0" != "./build-scripts/format-code" -a "$0" != "build-scripts/format-code" ]; then
8 echo "Please run me from the root checkout dir"
9 exit 1
10 fi
11
12 if [ $# = 0 ]; then
13 echo usage: $0 file...
14 echo
15 echo format C++ files, does not touch non-regular files
16 exit 0
17 fi
18 if [ ! -e .clang-format ]; then
19 echo "No .clang-format file found in .";
20 exit 1
21 fi
22
23 verbose=0
24 if [ -t 1 ]; then
25 verbose=1
26 fi
27 if [ x$CIRCLECI = xtrue ]; then
28 verbose=0
29 fi
30
31 for file in "${@}"; do
32 if [ -h "$file" -o ! -f "$file" ]; then
33 if [ $verbose = 1 ]; then
34 echo "$file: skipped, not a regular file or unreadable"
35 fi
36 continue
37 fi
38 tmp=$(mktemp "$file.XXXXXXXX")
39 if ! clang-format -style=file "$file" > "$tmp"; then
40 rm "$tmp"
41 else
42 if ! cmp -s "$file" "$tmp"; then
43 echo "$file: reformatted"
44 mv "$tmp" "$file"
45 else
46 if [ $verbose = 1 ]; then
47 echo "$file: already formatted to perfection"
48 fi
49 rm "$tmp"
50 fi
51 fi
52 done
53