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