diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2018-03-09 15:27:03 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2018-03-19 10:56:22 +1030 |
commit | f34db31d768e38c3add58a83cd943609771fd212 (patch) | |
tree | 659f3f17e8405f5edd7000f251345f5c889d5a22 /format-code.sh | |
parent | 25eca77fabceb86e10ac4eb0cbe32484cbf21c14 (diff) | |
download | phosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.tar.gz phosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.zip |
Format C++ files according to OpenBMC style guide
We don't touch the C yet as upstream hasn't got such a change in place.
Change-Id: Ie6cab4bf99df520bb6655b9b00ae31e762e3c57b
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'format-code.sh')
-rwxr-xr-x | format-code.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/format-code.sh b/format-code.sh new file mode 100755 index 0000000..a824ad1 --- /dev/null +++ b/format-code.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -euo + +set -x + +[ -f .clang-format ] && rm .clang-format + +CLANG_FORMAT="$(which clang-format-5.0)" + +# phosphor-mboxd is a fork of mboxbridge, the reference mbox daemon +# implementation. mboxbridge is C written with the style of the Linux kernel. +# +# phosphor-mboxd extended the reference in C++, and used the OpenBMC C++ style. +# +# To remain compliant with the C++ style guide *and* preserve source +# compatibility with the upstream reference implementation, use two separate +# styles. +# +# Further, clang-format supports describing styles for multiple languages in +# the one .clang-format file, but *doesn't* make a distinction between C and +# C++. So we need two files. It gets worse: the -style parameter doesn't take +# the path to a configuration file as an argument, you instead specify the +# literal 'file' and it goes looking for a .clang-format or _clang-format file. +# So now we need to symlink different files in place before calling +# ${CLANG_FORMAT}. Everything is terrible. +# +# ln -sf .clang-format-c .clang-format +# git ls-files | grep '\.[ch]$' | xargs "${CLANG_FORMAT}" -i -style=file + +ln -sf .clang-format-c++ .clang-format +git ls-files | grep '\.[ch]pp$' | xargs "${CLANG_FORMAT}" -i -style=file + +rm .clang-format |