Add `tools/format-cpp` script
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 15 Dec 2020 15:36:15 +0000 (10:36 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 31 Aug 2021 18:55:52 +0000 (14:55 -0400)
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>
CONTRIBUTING.adoc
Makefile.am
tools/format-cpp [new file with mode: 0755]

index b9f26eb11bb5c626cbb40e5b3dfe380156fad028..7052f2e8e232714565579f60112f8462bf20c195 100644 (file)
@@ -1689,7 +1689,14 @@ file.
 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
index 90007da2aa9c90f5487474df348b4b28fd33a527..ec8ba78b8b147f7d3d35224317bafc40855c848e 100644 (file)
@@ -25,4 +25,5 @@ EXTRA_DIST = \
        LICENSES/LGPL-2.1 \
        LICENSES/MIT \
        std-ext-lib.txt \
+       tools/format-cpp \
        version
diff --git a/tools/format-cpp b/tools/format-cpp
new file mode 100755 (executable)
index 0000000..48703c2
--- /dev/null
@@ -0,0 +1,12 @@
+#!/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 '{}' ';'
This page took 0.026212 seconds and 4 git commands to generate.