-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathformatSourceCode.sh
More file actions
executable file
·65 lines (58 loc) · 1.76 KB
/
formatSourceCode.sh
File metadata and controls
executable file
·65 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# (use "chmod +rx scriptname" to make script executable)
#
# For use on any Unix system, including Mac OS X and Linux
#
# Execute this script with "git" as default directory to
# automatically reformat all C++ code in the SKIRT project
#
# Requires clang-format version 18.1 to be installed
# in the default path.
#
# --------------------------------------------------------------------
# Look for clang-format-18 or clang-format
CLANGFORMATPATH="$(which clang-format-18)"
if [ "$CLANGFORMATPATH" == "" ]
then
CLANGFORMATPATH="$(which clang-format)"
fi
# Exit with an error if we don't find it
if [ "$CLANGFORMATPATH" == "" ]
then
echo
echo Fatal error: there is no clang-format in the default path
echo
exit
fi
# Verify the clang-format version
CLANGFORMATVERSION=$($CLANGFORMATPATH -version)
if ! [[ $CLANGFORMATVERSION == *"18.1."* ]]
then
echo
echo Fatal error: $CLANGFORMATPATH is not version 18.1 but
echo $CLANGFORMATVERSION
echo
exit
fi
# Verify that we are probably in the SKIRT git directory
if ! [[ -f "makeSKIRT.sh" ]]
then
echo
echo Fatal error: the current directory does not seem to be the SKIRT git directory
echo
exit
fi
# Format all .hpp and .cpp files, which skips third-party source code because it has a different filename extension
# (we use xargs so that multiple invocations of clang-format can run in parallel)
echo Using $CLANGFORMATPATH -- $CLANGFORMATVERSION...
find . \( -name '*.hpp' -or -name '*.cpp' \) -print0 | xargs -0L1 -P0 $CLANGFORMATPATH -style=file -i 2> formaterror.txt
# If the error file is nonempty, show its contents before removing it
if [ -s formaterror.txt ]
then
cat formaterror.txt
rm -f formaterror.txt
echo Failed!
else
rm -f formaterror.txt
echo Done
fi