From 0128014d4496e0df3744f2446b4bfac97ee62beb Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 25 Nov 2016 11:49:37 +0100 Subject: [PATCH] fix(cmake): Tidy and format commands --- .clang-tidy | 21 +++++++++++++++++++-- cmake/build/targets.cmake | 33 +++++++++++++++------------------ common/clang-format.sh | 19 +++++++++++++++++++ common/clang-tidy.sh | 23 +++++++++++++++++++++++ 4 files changed, 76 insertions(+), 20 deletions(-) create mode 100755 common/clang-format.sh create mode 100755 common/clang-tidy.sh diff --git a/.clang-tidy b/.clang-tidy index 72ee4be4..5da6bc80 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,23 @@ --- -Checks: 'clang-analyzer-core-*,clang-analyzer-nullability-*,clang-analyzer-unix-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*' -WarningsAsErrors: '' +Checks: '-*,performance-faster-string-find,performance-for-range-copy,readability-*,modernize-*,-modernize-raw-string-literal,-modernize-use-bool-literals,-readability-implicit-bool-cast,-readability-else-after-return,-readability-named-parameter' +CheckOptions: + - key: modernize-loop-convert.NamingStyle + value: lower_case + - key: readability-identifier-naming.GlobalConstantPrefix + value: 'g_' + - key: readability-identifier-naming.ClassCase + value: lower_case + - key: readability-identifier-naming.ClassConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.ClassMethodCase + value: lower_case + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.ProtectedMemberPrefix + value: 'm_' + - key: readability-identifier-naming.PrivateMemberPrefix + value: 'm_' HeaderFilterRegex: '' +WarningsAsErrors: '' AnalyzeTemporaryDtors: false ... diff --git a/cmake/build/targets.cmake b/cmake/build/targets.cmake index 1361a1f1..ca924a9b 100644 --- a/cmake/build/targets.cmake +++ b/cmake/build/targets.cmake @@ -24,27 +24,24 @@ add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake) # }}} -# Target: clang-format {{{ +# Target: codeformat (clang-format) {{{ -find_program(CLANG_FORMAT "clang-format") - -if(CLANG_FORMAT) - file(GLOB_RECURSE HEADERS ${PROJECT_SOURCE_DIR}/include/*.hpp) - file(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp) - add_custom_target(clang-format COMMAND ${CLANG_FORMAT} - -i -style=file ${HEADERS} ${SOURCES}) -endif() - -find_program(CLANG_TIDY "clang-tidy") +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) # }}} -# Target: clang-tidy {{{ +# Target: codecheck (clang-tidy) {{{ -if(CLANG_TIDY) - add_custom_target(clang-tidy - COMMAND ${CLANG_TIDY} -p - ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/src/main.cpp) -endif() +add_custom_target(codecheck) +add_custom_command(TARGET codecheck COMMAND + ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src) + +# }}} +# Target: codecheck-fix (clang-tidy + clang-format) {{{ + +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) # }}} diff --git a/common/clang-format.sh b/common/clang-format.sh new file mode 100755 index 00000000..b24db0a1 --- /dev/null +++ b/common/clang-format.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +main() { + if [ $# -lt 1 ]; then + echo "$0 DIR..." 1>&2 + exit 1 + fi + + search="${*:-.}" + + [ -d "$search" ] || search="$(dirname "$search")" + + # shellcheck disable=2086 + find $search -regex ".*.[c|h]pp" \ + -exec printf "\033[32;1m** \033[0mFormatting %s\n" {} \; \ + -exec clang-format -style=file -i {} \; +} + +main "$@" diff --git a/common/clang-tidy.sh b/common/clang-tidy.sh new file mode 100755 index 00000000..c6c2c791 --- /dev/null +++ b/common/clang-tidy.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +main() { + if [ $# -lt 2 ]; then + echo "$0 [build_path] [-fix] DIR..." 1>&2 + exit 1 + fi + + args="-p $1"; shift + + if [ "$1" = "-fix" ]; then + args="${args} -fix"; shift + fi + + # 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 {} \; +} + +main "$@"