summaryrefslogtreecommitdiff
path: root/ci/calamaresstyle
blob: ecbd798c58af16ab11439a849c903150906526a2 (plain)
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
#!/bin/sh
#
# Calls astyle with settings matching Calamares coding style
# Requires astyle >= 2.04 and clang-format-7
#
# You can pass in directory names, in which case the files
# in that directory (NOT below it) are processed.
#
LANG=C
LC_ALL=C
LC_NUMERIC=C
export LANG LC_ALL LC_NUMERIC

AS=$( which astyle )

for _cf in clang-format-7 clang-format-8 clang-format70 clang-format80 clang-format
do
	# Not an error if this particular clang-format isn't found
	CF=$( which $_cf || true )
	test -n "$CF" && break
done

test -n "$AS" || { echo "! No astyle found in PATH"; exit 1 ; }
test -n "$CF" || { echo "! No clang-format-7 found in PATH"; exit 1 ; }
test -x "$AS" || { echo "! $AS is not executable."; exit 1 ; }
test -x "$CF" || { echo "! $CF is not executable."; exit 1 ; }

set -e

any_dirs=no
for d in "$@"
do
	test -d "$d" && any_dirs=yes
done

style_some()
{
	$AS --options=$(dirname $0)/astylerc --quiet "$@"
	$CF -i -style=file "$@"
}

if test "x$any_dirs" = "xyes" ; then
	for d in "$@"
	do
		if test -d "$d"  ; then
			style_some $( find "$d" -maxdepth 1 -type f -name '*.cpp' -o -name '*.h' )
		else
			style_some "$d"
		fi
	done
else
	style_some "$@"
fi