blob: 5eeaf29155f4bca895a0c7d18e456a93d618be80 [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001#!/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
6find sw hw \
lowRISC Contributors802543a2019-08-31 12:12:56 +01007 \( -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 Elliott61c707b2020-05-11 15:04:21 +010015#
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 Contributors802543a2019-08-31 12:12:56 +010020braces_missing=$(
21 find sw hw \
Sam Elliott61c707b2020-05-11 15:04:21 +010022 -not \( -path '*/vendor/*' -prune \) \
lowRISC Contributors802543a2019-08-31 12:12:56 +010023 \( -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)
29if [ ! -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
35fi