The new `format-cpp` script uses `clang-format -i` to inline-format all
the C++ files except `src/cpp-common/optional/optional.hpp` and
`src/cpp-common/string_view/string_view.hpp`.
You can run it from any directory: it always runs `clang-format -i` for
the whole project.
By default, the script runs `clang-format -i`; you can override this
with the `FORMATTER` environment variable, for example:
$ FORMATTER='clang-format-10 -i' ./tools/format-cpp
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1049eabf8da71ce5c1d8443e1e2cdc9a73f4b4d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4592
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
To automatically format all the project's {cpp} files, run:
----
-$ find -iname '*.cpp' -o -iname '*.hpp' -exec clang-format -i '{}' ';'
+$ ./tools/format-cpp
+----
+
+Use the `FORMATTER` environment variable to override the default
+formatter (`clang-format{nbsp}-i`):
+
+----
+$ FORMATTER='clang-format-10 -i' ./tools/format-cpp
----
==== Naming
LICENSES/LGPL-2.1 \
LICENSES/MIT \
std-ext-lib.txt \
+ tools/format-cpp \
version
--- /dev/null
+#!/bin/bash
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
+
+FORMATTER="${FORMATTER:-clang-format -i}"
+root_dir="$(dirname "${BASH_SOURCE[0]}")/.."
+find "$root_dir" \( -name '*.cpp' -o -name '*.hpp' \) \
+ ! -wholename '*/cpp-common/optional.hpp' \
+ ! -wholename '*/cpp-common/string_view.hpp' \
+ -exec $FORMATTER '{}' ';'