mirror of
https://gitlab.com/prpl-foundation/prplmesh/prplMesh.git
synced 2025-12-20 01:21:22 +08:00
When running clang-format (both in docker and natively), it would segfault under certain circumstances which made it impossible to run it locally (it never failed this way in CI). After a short investigation, it turns out it would always segfault on the same (generated) file: CMakeFiles/3.15.5/CompilerIdC/CMakeCCompilerId.c We could adapt the find command used in the top-level clang-format to exclude CMakeFiles directories. However, it would still potentially run on many other generated files, while we're really only interested in formatting the files we track with git. Use git-ls-files to get the list of tracked files, filter it to keep only the file extensions we're interested in, and run clang-format on them. Since the prplmesh-runner image does not include git, we have to adapt tools/docker/clang-format.sh to run with the prplmesh-builder image. Note that the clang-format job that runs in CI was already using the prplmesh-builder image. While we're at it, fix shellcheck issues in both clang-format.sh scripts. Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
19 lines
483 B
Bash
Executable File
19 lines
483 B
Bash
Executable File
#! /bin/sh
|
|
# cd to the script directory:
|
|
cd "${0%/*}" || { echo "Couldn't cd to ${0%/*}!"; exit 1; }
|
|
CLANG_FORMAT="clang-format"
|
|
if ! [ -x "$(command -v ${CLANG_FORMAT})" ]; then
|
|
echo "{$CLANG_FORMAT} not found. skipping..."
|
|
exit 1
|
|
fi
|
|
|
|
IGNORE_FILE=".clang-ignore"
|
|
filter="grep ."
|
|
if test -f "$IGNORE_FILE"; then
|
|
filter="grep -v -E -f .clang-ignore"
|
|
else
|
|
filter="grep ."
|
|
fi
|
|
|
|
git ls-files -- '*.c' '*.cpp' '*.h' '*.hpp' '*.cc' | $filter | xargs clang-format -i -style=file
|