blob: 9b639105b1313162148852539100777792767e94 [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
Andrew Jeffery0cce8482018-04-30 11:37:01 +093015set -e
16
Andrew Geissler9b0105c2018-01-10 10:58:35 -080017echo "Formatting code under $DIR/"
Andrew Geissler9b0105c2018-01-10 10:58:35 -080018
Patrick Venture30ec0c42018-10-22 11:56:27 -070019if [[ -f "setup.cfg" ]]; then
Adriana Kobylakbcee22b2018-01-10 16:58:27 -060020 pycodestyle --show-source .
21 rc=$?
Patrick Venture30ec0c42018-10-22 11:56:27 -070022 if [[ ${rc} -ne 0 ]]; then
Adriana Kobylakbcee22b2018-01-10 16:58:27 -060023 exit ${rc}
24 fi
25fi
26
William A. Kennington III078c3b52018-10-04 19:44:31 -070027# Allow called scripts to know which clang format we are using
28export CLANG_FORMAT="clang-format-6.0"
29
Patrick Venture30ec0c42018-10-22 11:56:27 -070030if [[ -f ".clang-format" ]]; then
Adriana Kobylakbcee22b2018-01-10 16:58:27 -060031 find . -regextype sed -regex ".*\.[hc]\(pp\)\?" -not -name "*mako*" -print0 |\
William A. Kennington III078c3b52018-10-04 19:44:31 -070032 xargs -0 "${CLANG_FORMAT}" -i
Adriana Kobylakbcee22b2018-01-10 16:58:27 -060033 git --no-pager diff --exit-code
34fi
Andrew Jeffery457b6d12018-03-09 15:28:14 +103035
36# Sometimes your situation is terrible enough that you need the flexibility.
37# For example, phosphor-mboxd.
Patrick Venture30ec0c42018-10-22 11:56:27 -070038if [[ -f "format-code.sh" ]]; then
Andrew Jeffery457b6d12018-03-09 15:28:14 +103039 ./format-code.sh
40 git --no-pager diff --exit-code
41fi