This GitLab instance will be migrated to gitlab.mel.vin before 2020-06-01 and will lose the shared runners, setup your own runners if needed.

Commit c514e46b authored by Stefan Schrijvers's avatar Stefan Schrijvers

Merge branch '87-move-clang_format-script-to-cicd-style-repo' into 'master'

Resolve "move clang_format script to cicd/style repo"

Closes #87

See merge request !94
parents 17458717 ae2d8c5e
#!/bin/bash
set -e
shopt -s globstar
shopt -s nullglob
case "$1" in
'check')
;;
'format')
;;
*)
printf '%s\n' \
"usage: $0 check|format [clang-tidy path]
always call from root of repo
check
check sources and report replacements
format
format sources in place
[clang-tidy path]
path to clang-tidy, defaults to searching path
EXIT CODE
0 [check] no replacements
[format] completed ok
1 [check] found replacements
2 internal error
* when any commands fails because of 'set -e'"
exit 2
;;
esac
if [[ $2 ]]
then
clang_format="$2"
else
clang_format="$(which clang-format)"
fi
# set targets
targets=({src,include,test}/**/*.{c,h,cpp,hpp})
# run format if requested
if [[ $1 == 'format' ]]
then
"$clang_format" -i -style=file "${targets[@]}"
exit 0
fi
# checking logic otherwise
xml="$("$clang_format" -output-replacements-xml -style=file "${targets[@]}")"
# do not fail when no replacements
set +e
replacements="$(echo "$xml" | grep -cv \
-e "^<?xml version='1.0'?>\$" \
-e "^<replacements xml:space='preserve' incomplete_format='false'>\$" \
-e "^</replacements>\$")"
case $? in
0)
printf '%i replacement(s)\n' "$replacements"
printf '%s\n' "$xml"
exit 1
;;
1)
exit 0
;;
*)
printf 'internal error\n'
exit 2
;;
esac
Subproject commit 71a5e562be2603d0243eee9ce1c59f33d71a9a5f
Subproject commit 383262f4896d258a555886be07f5790d5d092d03
......@@ -9,10 +9,10 @@ message(STATUS "Found clang-format: ${CLANG_FORMAT_PATH}")
add_custom_target(format
COMMENT "Formatting source code"
COMMAND ./cicd/clang_format.sh format "${CLANG_FORMAT_PATH}"
COMMAND ./cicd/style/clang_format.sh format "${CLANG_FORMAT_PATH}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_custom_target(format_check
COMMENT "Running format check"
COMMAND WERROR=${WERROR} ./cmake/format_check.sh
COMMAND WERROR=${WERROR} ./cmake/format_check.sh "${CLANG_FORMAT_PATH}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
......@@ -9,6 +9,6 @@ SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
[[ $WERROR == "ON" ]] && set -e
# call clang_format.sh to check repo
"$SCRIPT_DIR/../cicd/clang_format.sh" check
"$SCRIPT_DIR/../cicd/style/clang_format.sh" check "$1"
exit 0
......@@ -12,10 +12,10 @@ When also configuring with ``-DWERROR:BOOL=ON`` a nonzero exit code will be
returned if at least one line does not pass the checks while invoking
``format_check``.
The script invoked is ``/cicd/clang_format.sh`` and can also be used to check
source files, reporting replacements in XML.
The script invoked is ``/cicd/style/clang_format.sh`` and can also be used to
check source files, reporting replacements in XML.
.. code-block:: console
# always call script from root of the repo
./cicd/clang_format.sh --help
./cicd/style/clang_format.sh --help
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment