fix(clang): Search for files in right places

Before, because of [ -d "$search" ] || search="$(dirname "$search")",
clang-format.sh would search for files to format in the whole repo
(even in the build directory and the submodules)

This now also looks for source files in the tests folder

I have removed the clang-format from clang-tidy.sh because one may want
to run clang-tidy without reformatting
This commit is contained in:
patrick96 2018-05-01 17:49:22 +02:00 committed by NBonaparte
parent da9372fb70
commit 72948dbc97
3 changed files with 21 additions and 13 deletions

View File

@ -25,12 +25,15 @@ add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake) COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake)
# }}} # }}}
# folders where the clang tools should operate
set(CLANG_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/tests)
# Target: codeformat (clang-format) {{{ # Target: codeformat (clang-format) {{{
add_custom_target(codeformat) add_custom_target(codeformat)
add_custom_command(TARGET codeformat add_custom_command(TARGET codeformat
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh ${CLANG_SEARCH_PATHS})
${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include)
# }}} # }}}
# Target: codecheck (clang-tidy) {{{ # Target: codecheck (clang-tidy) {{{
@ -38,7 +41,7 @@ add_custom_command(TARGET codeformat
add_custom_target(codecheck) add_custom_target(codecheck)
add_custom_command(TARGET codecheck add_custom_command(TARGET codecheck
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh
${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src) ${PROJECT_BINARY_DIR} ${CLANG_SEARCH_PATHS})
# }}} # }}}
# Target: codecheck-fix (clang-tidy + clang-format) {{{ # Target: codecheck-fix (clang-tidy + clang-format) {{{
@ -46,7 +49,7 @@ add_custom_command(TARGET codecheck
add_custom_target(codecheck-fix) add_custom_target(codecheck-fix)
add_custom_command(TARGET codecheck-fix add_custom_command(TARGET codecheck-fix
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh
${PROJECT_BINARY_DIR} -fix ${PROJECT_SOURCE_DIR}/src) ${PROJECT_BINARY_DIR} -fix ${CLANG_SEARCH_PATHS})
# }}} # }}}

View File

@ -2,16 +2,18 @@
main() { main() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
printf "%s DIR...\n" "$0" 1>&2 echo "$0 DIR..." 1>&2
exit 1 exit 1
fi fi
# Search paths
search="${*:-.}" search="${*:-.}"
[ -d "$search" ] || search="$(dirname "$search")" echo "$0 in $search"
# shellcheck disable=2086 # shellcheck disable=2086
find $search -regex ".*.[c|h]pp" \ find $search -regex ".*.[c|h]pp" \
-exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \ -exec printf "\\033[32;1m** \\033[0mFormatting %s\\n" {} \; \
-exec clang-format -style=file -i {} \; -exec clang-format -style=file -i {} \;
} }

View File

@ -2,7 +2,7 @@
main() { main() {
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
echo "$0 [build_path] [-fix] DIR..." 1>&2 echo "$0 build_path [-fix] DIR..." 1>&2
exit 1 exit 1
fi fi
@ -12,12 +12,15 @@ main() {
args="${args} -fix"; shift args="${args} -fix"; shift
fi fi
# Search paths
search="${*:-.}"
echo "$0 in $search"
# shellcheck disable=2086 # shellcheck disable=2086
find "${@:-.}" -regex ".*.[c|h]pp" \ find $search -iname "*.cpp" \
-exec printf "\033[32;1m** \033[0mProcessing %s\n" {} \; \ -exec printf "\\033[32;1m** \\033[0mProcessing %s\\n" {} \; \
-exec clang-tidy $args {} \; \ -exec clang-tidy $args {} \;
-exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \
-exec clang-format -style=file -i {} \;
} }
main "$@" main "$@"