-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_source.sh
executable file
·50 lines (39 loc) · 1.13 KB
/
format_source.sh
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
#!/bin/bash
#
# Apply source code formatting.
#
# Get the directory containing this script
pushd $(dirname $0) > /dev/null
base=$(pwd -P)
popd > /dev/null
# Check executables
unexe=$(which uncrustify)
if [ "x${unexe}" = "x" ]; then
echo "Cannot find the \"uncrustify\" executable. Is it in your PATH?"
exit 1
fi
blkexe=$(which black)
if [ "x${blkexe}" = "x" ]; then
echo "Cannot find the \"black\" executable. Is it in your PATH?"
exit 1
fi
# The uncrustify config file
uncfg="${base}/uncrustify.cfg"
# Uncrustify runtime options per file
unrun="-c ${uncfg} --replace --no-backup"
# Uncrustify test options
untest="-c ${uncfg} --check"
# Black runtime options
blkrun="-l 88"
# Black test options
blktest="--check"
# Directories to process
cppdirs="s4sim"
pydirs="s4sim"
for cppd in ${cppdirs}; do
find "${base}/${cppd}" -name "*.hpp" -not -path '*pybind11/*' -exec ${unexe} ${unrun} '{}' \;
find "${base}/${cppd}" -name "*.cpp" -not -path '*pybind11/*' -exec ${unexe} ${unrun} '{}' \;
done
for pyd in ${pydirs}; do
find "${base}/${pyd}" -name "*.py" -not -path '*pybind11/*' -exec ${blkexe} ${blkrun} '{}' \;
done