Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script reformats source files using the clang-format utility. |
| 4 | # |
| 5 | # Files are changed in-place, so make sure you don't have anything open in an |
| 6 | # editor, and you may want to commit before formatting in case of awryness. |
| 7 | # |
| 8 | # This must be run on a clean repository to succeed |
| 9 | # |
| 10 | # Input parmameter must be full path to git repo to scan |
| 11 | |
| 12 | DIR=$1 |
| 13 | cd ${DIR} |
| 14 | |
Andrew Jeffery | 0cce848 | 2018-04-30 11:37:01 +0930 | [diff] [blame] | 15 | set -e |
| 16 | |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 17 | echo "Formatting code under $DIR/" |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 18 | |
Adriana Kobylak | bcee22b | 2018-01-10 16:58:27 -0600 | [diff] [blame] | 19 | if [ -f "setup.cfg" ]; then |
| 20 | pycodestyle --show-source . |
| 21 | rc=$? |
| 22 | if [ ${rc} -ne 0 ]; then |
| 23 | exit ${rc} |
| 24 | fi |
| 25 | fi |
| 26 | |
| 27 | if [ -f ".clang-format" ]; then |
| 28 | find . -regextype sed -regex ".*\.[hc]\(pp\)\?" -not -name "*mako*" -print0 |\ |
Patrick Venture | 52164fd | 2018-08-28 16:12:47 -0700 | [diff] [blame] | 29 | xargs -0 "clang-format-6.0" -i |
Adriana Kobylak | bcee22b | 2018-01-10 16:58:27 -0600 | [diff] [blame] | 30 | git --no-pager diff --exit-code |
| 31 | fi |
Andrew Jeffery | 457b6d1 | 2018-03-09 15:28:14 +1030 | [diff] [blame] | 32 | |
| 33 | # Sometimes your situation is terrible enough that you need the flexibility. |
| 34 | # For example, phosphor-mboxd. |
| 35 | if [ -f "format-code.sh" ]; then |
| 36 | ./format-code.sh |
| 37 | git --no-pager diff --exit-code |
| 38 | fi |