blob: bc42c071b835edabb97cc37b69e6768a1533a604 [file] [log] [blame]
Andrew Geissler9b0105c2018-01-10 10:58:35 -08001#!/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
12DIR=$1
13cd ${DIR}
14
15echo "Formatting code under $DIR/"
Andrew Geissler9b0105c2018-01-10 10:58:35 -080016
Adriana Kobylakbcee22b2018-01-10 16:58:27 -060017if [ -f "setup.cfg" ]; then
18 pycodestyle --show-source .
19 rc=$?
20 if [ ${rc} -ne 0 ]; then
21 exit ${rc}
22 fi
23fi
24
25if [ -f ".clang-format" ]; then
26 find . -regextype sed -regex ".*\.[hc]\(pp\)\?" -not -name "*mako*" -print0 |\
27 xargs -0 "clang-format-5.0" -i
28 git --no-pager diff --exit-code
29fi
Andrew Jeffery457b6d12018-03-09 15:28:14 +103030
31# Sometimes your situation is terrible enough that you need the flexibility.
32# For example, phosphor-mboxd.
33if [ -f "format-code.sh" ]; then
34 ./format-code.sh
35 git --no-pager diff --exit-code
36fi