Skip to content

Commit d080f83

Browse files
committed
Make check-style.sh work on stock macOS
./tools/check-style.sh fails on stock OS X currently; this fixes it: - use pipes directly rather than exec redirection (macOS's ancient version of bash fails with the latter) - macOS's ancient bash doesn't support '\e' escapes in `echo -e`; replace with \033 instead - BSD grep doesn't support GREP_COLORS, but does allow GREP_COLOR. Adding both doesn't hurt GNU grep: GREP_COLOR is deprecated, and won't be used when GREP_COLORS is set. - BSD grep doesn't collapse multiple /'s in the listed filename, so failures under `include/` would should up as `include//pybind11/whatever.h`. This removes the / from the include directory argument. Minor other changes: - The CRLF detection runs with -l, so GREP_COLORS wasn't doing anything; removed it. - The trailing whitespace test would trigger on CRLFs, but the CR would result in messed up output. Changed the test to just match trailing spaces and tabs, rather than all whitespace.
1 parent 404bcf2 commit d080f83

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

tools/check-style.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ errors=0
1919
IFS=$'\n'
2020
found=
2121
# The mt=41 sets a red background for matched tabs:
22-
exec 3< <(GREP_COLORS='mt=41' grep $'\t' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
23-
while read -u 3 f; do
22+
GREP_COLORS='mt=41' GREP_COLOR='41' grep $'\t' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always |
23+
while read f; do
2424
if [ -z "$found" ]; then
25-
echo -e '\e[31m\e[01mError: found tabs instead of spaces in the following files:\e[0m'
25+
echo -e '\033[31m\033[01mError: found tabs instead of spaces in the following files:\033[0m'
2626
found=1
2727
errors=1
2828
fi
@@ -31,11 +31,10 @@ while read -u 3 f; do
3131
done
3232

3333
found=
34-
# The mt=41 sets a red background for matched MS-DOS CRLF line endings
35-
exec 3< <(GREP_COLORS='mt=41' grep -IUlr $'\r' include/ tests/*.{cpp,py,h} docs/*.rst --color=always)
36-
while read -u 3 f; do
34+
grep -IUlr $'\r' include tests/*.{cpp,py,h} docs/*.rst --color=always |
35+
while read f; do
3736
if [ -z "$found" ]; then
38-
echo -e '\e[31m\e[01mError: found CRLF characters in the following files:\e[0m'
37+
echo -e '\033[31m\033[01mError: found CRLF characters in the following files:\033[0m'
3938
found=1
4039
errors=1
4140
fi
@@ -45,10 +44,10 @@ done
4544

4645
found=
4746
# The mt=41 sets a red background for matched trailing spaces
48-
exec 3< <(GREP_COLORS='mt=41' grep '\s\+$' include/ tests/*.{cpp,py,h} docs/*.rst -rn --color=always)
49-
while read -u 3 f; do
47+
GREP_COLORS='mt=41' GREP_COLOR='41' grep '[[:blank:]]\+$' include tests/*.{cpp,py,h} docs/*.rst -rn --color=always |
48+
while read f; do
5049
if [ -z "$found" ]; then
51-
echo -e '\e[31m\e[01mError: found trailing spaces in the following files:\e[0m'
50+
echo -e '\033[31m\033[01mError: found trailing spaces in the following files:\033[0m'
5251
found=1
5352
errors=1
5453
fi
@@ -57,10 +56,10 @@ while read -u 3 f; do
5756
done
5857

5958
found=
60-
exec 3< <(grep '\<\(if\|for\|while\|catch\)(\|){' include/ tests/*.{cpp,py,h} -rn --color=always)
61-
while read -u 3 line; do
59+
grep '\<\(if\|for\|while\|catch\)(\|){' include tests/*.{cpp,py,h} -rn --color=always |
60+
while read line; do
6261
if [ -z "$found" ]; then
63-
echo -e '\e[31m\e[01mError: found the following coding style problems:\e[0m'
62+
echo -e '\033[31m\033[01mError: found the following coding style problems:\033[0m'
6463
found=1
6564
errors=1
6665
fi
@@ -69,10 +68,10 @@ while read -u 3 line; do
6968
done
7069

7170
found=
72-
exec 3< <(GREP_COLORS='mt=41' grep '^\s*{\s*$' include/ docs/*.rst -rn --color=always)
73-
while read -u 3 f; do
71+
GREP_COLORS='mt=41' GREP_COLOR='41' grep '^\s*{\s*$' include docs/*.rst -rn --color=always |
72+
while read f; do
7473
if [ -z "$found" ]; then
75-
echo -e '\e[31m\e[01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files: \e[0m'
74+
echo -e '\033[31m\033[01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files: \033[0m'
7675
found=1
7776
errors=1
7877
fi

0 commit comments

Comments
 (0)