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 12DIR=$1 13cd ${DIR} 14 15echo "Formatting code under $DIR/" 16 17if [ -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 30 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 37