From 9bfa2aa7c7054496ad2efffdcd3882e288b9388b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 30 Aug 2024 15:52:37 -0400 Subject: [PATCH] clang-format: ignore generated files MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Two auto-generated files cause clang-format < v17 to hang when they are being formatted. I have not looked into the root-cause, but formatting them is useless anyhow. Adding them to .clang-format-ignore works around the problem for the moment. Since clang-format 14 does not support ignore files, their support is crudely emulated here using grep to filter out find's results. Signed-off-by: Jérémie Galarneau Change-Id: I1cd10349ef1a66b1d595105b0ec1a4beef9dcc9a --- .clang-format-ignore | 2 ++ format-cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .clang-format-ignore diff --git a/.clang-format-ignore b/.clang-format-ignore new file mode 100644 index 000000000..d0ccb24fe --- /dev/null +++ b/.clang-format-ignore @@ -0,0 +1,2 @@ +extras/bindings/swig/python/lttng_wrap.c +src/common/filter/filter-parser.cpp diff --git a/format-cpp b/format-cpp index 17275de77..a3943ae57 100755 --- a/format-cpp +++ b/format-cpp @@ -6,6 +6,8 @@ expected_formatter_major_version=14 +SCRIPT_DIR=$(dirname "$0")/ + # Runs the formatter, making sure it's the expected version. format_cpp() { local formatter=$1 @@ -35,10 +37,14 @@ format_cpp() { # Using xargs to fail as soon as the formatter fails (`-exec` # won't stop if its subprocess fails). # + # Since clang-format 14 does not support ignore files, their + # support is crudely emulated here. + # # shellcheck disable=SC2086 find "$root_dir" -path './src/vendor' -prune \ -o -type f \( -name '*\.h' -o -name '*\.hpp' -o -name '*\.c' -o -name '*\.cpp' \) \ - -not -path '*/\.*' -print0 | xargs -P$(nproc) -n1 -0 $formatter -i --style=file --fallback-style=none + -not -path '*/\.*' -print0 | grep -zv -f "$SCRIPT_DIR"/.clang-format-ignore | \ + xargs -P"$(nproc)" -n1 -0 $formatter -i --style=file --fallback-style=none } if [[ -n "$FORMATTER" ]]; then -- 2.34.1