From 81e6721905a7ded4ee52c26dabbc071cd1bc5c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20W=C3=B6lzer?= <martin@libclapp.org> Date: Mon, 16 Sep 2024 20:49:10 +0200 Subject: [PATCH] .ci/format/apply_clang_format.sh: introduced file --- .ci/format/apply_clang_format.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 .ci/format/apply_clang_format.sh diff --git a/.ci/format/apply_clang_format.sh b/.ci/format/apply_clang_format.sh new file mode 100755 index 00000000..29c3ac0c --- /dev/null +++ b/.ci/format/apply_clang_format.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ -z "${CLANG_FORMAT_BIN}" ]; then + if [ -z "${CLANG_COMPILER_VERSION}" ]; then + echo "ERROR: Please either set the environment variable CLANG_COMPILER_VERSION or CLANG_FORMAT_BIN accordingly" + exit 1 + fi + + CLANG_FORMAT_BIN="clang-format-${CLANG_COMPILER_VERSION}" +fi + +if ! command -v "${CLANG_FORMAT_BIN}" >/dev/null 2>&1; then + echo "ERROR: Binary '${CLANG_FORMAT_BIN}' does not exist, please either set the environment variable CLANG_FORMAT_BIN or CLANG_COMPILER_VERSION to the correct clang-format version." + exit 1 +fi + +format_command="${CLANG_FORMAT_BIN} -i" + +apply_format_script="$(dirname "${BASH_SOURCE[0]}")/apply_format.sh" + +files_regex=".*\.(c|h)(pp)?$" + +if ! "${apply_format_script}" --format-command "${format_command}" --files-regex "${files_regex}" "$@"; then + echo "ERROR: Executing '${apply_format_script}' failed." + exit 1 +fi -- GitLab