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:
parent
da9372fb70
commit
72948dbc97
@ -25,12 +25,15 @@ add_custom_target(uninstall
|
||||
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) {{{
|
||||
|
||||
add_custom_target(codeformat)
|
||||
add_custom_command(TARGET codeformat
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh
|
||||
${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include)
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh ${CLANG_SEARCH_PATHS})
|
||||
|
||||
# }}}
|
||||
# Target: codecheck (clang-tidy) {{{
|
||||
@ -38,7 +41,7 @@ add_custom_command(TARGET codeformat
|
||||
add_custom_target(codecheck)
|
||||
add_custom_command(TARGET codecheck
|
||||
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) {{{
|
||||
@ -46,7 +49,7 @@ add_custom_command(TARGET codecheck
|
||||
add_custom_target(codecheck-fix)
|
||||
add_custom_command(TARGET codecheck-fix
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh
|
||||
${PROJECT_BINARY_DIR} -fix ${PROJECT_SOURCE_DIR}/src)
|
||||
${PROJECT_BINARY_DIR} -fix ${CLANG_SEARCH_PATHS})
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -2,16 +2,18 @@
|
||||
|
||||
main() {
|
||||
if [ $# -lt 1 ]; then
|
||||
printf "%s DIR...\n" "$0" 1>&2
|
||||
echo "$0 DIR..." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Search paths
|
||||
search="${*:-.}"
|
||||
|
||||
[ -d "$search" ] || search="$(dirname "$search")"
|
||||
echo "$0 in $search"
|
||||
|
||||
# shellcheck disable=2086
|
||||
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 {} \;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
main() {
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "$0 [build_path] [-fix] DIR..." 1>&2
|
||||
echo "$0 build_path [-fix] DIR..." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -12,12 +12,15 @@ main() {
|
||||
args="${args} -fix"; shift
|
||||
fi
|
||||
|
||||
# Search paths
|
||||
search="${*:-.}"
|
||||
|
||||
echo "$0 in $search"
|
||||
|
||||
# shellcheck disable=2086
|
||||
find "${@:-.}" -regex ".*.[c|h]pp" \
|
||||
-exec printf "\033[32;1m** \033[0mProcessing %s\n" {} \; \
|
||||
-exec clang-tidy $args {} \; \
|
||||
-exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \
|
||||
-exec clang-format -style=file -i {} \;
|
||||
find $search -iname "*.cpp" \
|
||||
-exec printf "\\033[32;1m** \\033[0mProcessing %s\\n" {} \; \
|
||||
-exec clang-tidy $args {} \;
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user