lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | find sw hw \ |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 7 | \( -name '*.cpp' \ |
| 8 | -o -name '*.cc' \ |
| 9 | -o -name '*.c' \ |
| 10 | -o -name '*.h' \) \ |
| 11 | -exec clang-format -i {} \; |
| 12 | |
| 13 | # Report on missing curly braces for loops and control statements. |
| 14 | # clang-format cannot fix them for us, so this requires manual work. |
Sam Elliott | 61c707b | 2020-05-11 15:04:21 +0100 | [diff] [blame] | 15 | # |
| 16 | # This does not cope with `do { ... } while (cond)` as used in macros (without |
| 17 | # the semicolon). |
| 18 | # |
| 19 | # This rule does not use the `.clang-format` file so vendor must be excluded. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 20 | braces_missing=$( |
| 21 | find sw hw \ |
Sam Elliott | 61c707b | 2020-05-11 15:04:21 +0100 | [diff] [blame] | 22 | -not \( -path '*/vendor/*' -prune \) \ |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 23 | \( -name '*.cpp' \ |
| 24 | -o -name '*.cc' \ |
| 25 | -o -name '*.c' \ |
| 26 | -o -name '*.h' \) \ |
| 27 | -exec grep -Hn -P '(^|\s)((if|while|for) \(.+\)|else\s*)$' {} \; |
| 28 | ) |
| 29 | if [ ! -z "$braces_missing" ]; then |
| 30 | echo ERROR: Curly braces are missing from the following control or loop |
| 31 | echo statements. Please add them manually and re-run this script. |
| 32 | echo |
| 33 | echo "$braces_missing" |
| 34 | exit 1 |
| 35 | fi |