Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -euo |
| 4 | |
| 5 | set -x |
| 6 | |
| 7 | [ -f .clang-format ] && rm .clang-format |
| 8 | |
Andrew Jeffery | 7a03b07 | 2018-09-05 17:34:49 +0930 | [diff] [blame] | 9 | for cf in clang-format-6.0 clang-format-5.0 |
| 10 | do |
| 11 | CLANG_FORMAT="$(which ${cf})" |
| 12 | if [ -n "${CLANG_FORMAT}" ] |
| 13 | then |
| 14 | break; |
| 15 | fi |
| 16 | done |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 17 | |
| 18 | # phosphor-mboxd is a fork of mboxbridge, the reference mbox daemon |
| 19 | # implementation. mboxbridge is C written with the style of the Linux kernel. |
| 20 | # |
| 21 | # phosphor-mboxd extended the reference in C++, and used the OpenBMC C++ style. |
| 22 | # |
| 23 | # To remain compliant with the C++ style guide *and* preserve source |
| 24 | # compatibility with the upstream reference implementation, use two separate |
| 25 | # styles. |
| 26 | # |
| 27 | # Further, clang-format supports describing styles for multiple languages in |
| 28 | # the one .clang-format file, but *doesn't* make a distinction between C and |
| 29 | # C++. So we need two files. It gets worse: the -style parameter doesn't take |
| 30 | # the path to a configuration file as an argument, you instead specify the |
| 31 | # literal 'file' and it goes looking for a .clang-format or _clang-format file. |
| 32 | # So now we need to symlink different files in place before calling |
| 33 | # ${CLANG_FORMAT}. Everything is terrible. |
| 34 | # |
| 35 | # ln -sf .clang-format-c .clang-format |
| 36 | # git ls-files | grep '\.[ch]$' | xargs "${CLANG_FORMAT}" -i -style=file |
| 37 | |
| 38 | ln -sf .clang-format-c++ .clang-format |
| 39 | git ls-files | grep '\.[ch]pp$' | xargs "${CLANG_FORMAT}" -i -style=file |
| 40 | |
| 41 | rm .clang-format |