From cbb0b0428ebeb6140812c4a9267b461187e970a4 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 17 Oct 2021 22:22:49 +0100 Subject: [PATCH] Hide the clang-tidy behind a build option --- .clang-format | 16 ++++++++++++++++ CMakeLists.txt | 6 ++++-- builder | 10 ++++++++-- scripts/pre-commit | 3 ++- src/libserene/CMakeLists.txt | 3 +++ src/serene-repl/CMakeLists.txt | 3 +++ src/serenec/CMakeLists.txt | 3 +++ 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.clang-format b/.clang-format index 032d6f0..be520e2 100644 --- a/.clang-format +++ b/.clang-format @@ -15,4 +15,20 @@ AlignConsecutiveBitFields: Consecutive AlignEscapedNewlines: Left AlwaysBreakTemplateDeclarations: Yes IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^"(serene)/' + Priority: 1 + SortPriority: 1 + CaseSensitive: true + - Regex: '^<(llvm|llvm-c|clang|clang-c|mlir)/' + Priority: 3 + SortPriority: 3 + CaseSensitive: true + - Regex: '<[[:alnum:].]+>' + Priority: 5 + - Regex: '.*' + Priority: 2 + SortPriority: 0 +SortIncludes: true +SortUsingDeclarations: true ... diff --git a/CMakeLists.txt b/CMakeLists.txt index af5be4d..af3c8e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ option(SERENE_BUILD_TESTING "Enable tests" OFF) option(SERENE_ENABLE_BUILDID "Enable build id." OFF) option(SERENE_ENABLE_THINLTO "Enable ThisLTO." ON) option(SERENE_ENABLE_DOCS "Enable document generation" OFF) +option(SERENE_ENABLE_TIDY "Enable clang tidy check" OFF) option(SERENE_DISABLE_CCACHE "Disable automatic ccache integration" OFF) # libserene @@ -60,8 +61,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) - set(CMAKE_CXX_CLANG_TIDY clang-tidy) - set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE include-what-you-use) + if(SERENE_ENABLE_TIDY) + find_program(CLANG_TIDY_PATH NAMES clang-tidy REQUIRED) + endif() # Let's ensure -std=c++xx instead of -std=g++xx set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/builder b/builder index 6ecfe4b..517fe9a 100755 --- a/builder +++ b/builder @@ -34,7 +34,7 @@ BUILD_DIR=$ROOT_DIR/build ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P) CMAKEARGS_DEBUG=" -DCMAKE_BUILD_TYPE=Debug -DSERENE_WITH_MLIR_CL_OPTION=ON" -CMAKEARGS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSERENE_CCACHE_DIR=${HOME}/.ccache" +CMAKEARGS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSERENE_CCACHE_DIR=$HOME/.ccache" # The scan-build utility scans the build for bugs checkout the man page scanbuild="scan-build --force-analyze-debug-code --use-analyzer=$(which clang)" @@ -71,7 +71,7 @@ function compile() { } function build() { - build-gen + build-gen "$@" pushed_build cmake --build . popd_build @@ -144,6 +144,12 @@ case "$command" in mkdir -p "$BUILD_DIR" build "${@:2}" ;; + "build-tidy") + clean + mkdir -p "$BUILD_DIR" + build "-DSERENE_ENABLE_TIDY=ON" "${@:2}" + ;; + "build-20") clean mkdir -p "$BUILD_DIR" diff --git a/scripts/pre-commit b/scripts/pre-commit index 93b3d03..bd5b558 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -1,5 +1,7 @@ #! /bin/bash +set -e + function get_changed_files() { local add_modified local renamed @@ -41,7 +43,6 @@ function git_add_changes() { then git add $files fi - } diff --git a/src/libserene/CMakeLists.txt b/src/libserene/CMakeLists.txt index 708a482..785dafc 100644 --- a/src/libserene/CMakeLists.txt +++ b/src/libserene/CMakeLists.txt @@ -78,6 +78,9 @@ set_target_properties(serene PROPERTIES # LTO support INTERPROCEDURAL_OPTIMIZATION TRUE) +if(SERENE_ENABLE_TIDY) + set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) +endif() # Do we need to build serene as a shared lib? default is "yes" if(SERENE_SHARED_LIB) diff --git a/src/serene-repl/CMakeLists.txt b/src/serene-repl/CMakeLists.txt index 78996b5..7b917f0 100644 --- a/src/serene-repl/CMakeLists.txt +++ b/src/serene-repl/CMakeLists.txt @@ -26,6 +26,9 @@ set_target_properties(serene-repl PROPERTIES # LTO support INTERPROCEDURAL_OPTIMIZATION TRUE) +if(SERENE_ENABLE_TIDY) + set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) +endif() if (CPP_20_SUPPORT) target_compile_features(serene-repl PRIVATE cxx_std_20) diff --git a/src/serenec/CMakeLists.txt b/src/serenec/CMakeLists.txt index 1edfc6d..e5307d0 100644 --- a/src/serenec/CMakeLists.txt +++ b/src/serenec/CMakeLists.txt @@ -25,6 +25,9 @@ set_target_properties(serenec PROPERTIES # LTO support INTERPROCEDURAL_OPTIMIZATION TRUE) +if(SERENE_ENABLE_TIDY) + set_target_properties(serenec PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) +endif() if (CPP_20_SUPPORT) target_compile_features(serenec PRIVATE cxx_std_20)