diff --git a/.ci.yml b/.ci.yml index d0c913c..a5d633f 100644 --- a/.ci.yml +++ b/.ci.yml @@ -16,10 +16,15 @@ steps: commands: - cmake --version - ./builder build -- name: Lint + +- name: Clang Tidy image: rg.fr-par.scw.cloud/serene/llvm:15-8 commands: - - pre-commit clang-tidy -a - - pre-commit cppcheck -a - - pre-commit include-what-you-use -a - - pre-commit shell-lint -a + - ./builder build-tidy + +- name: Linters + image: rg.fr-par.scw.cloud/serene/llvm:15-8 + commands: + - pre-commit run cppcheck -a + - pre-commit run include-what-you-use -a + - pre-commit run shell-lint -a diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 439e0c0..a0dda21 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,15 +17,21 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: mixed-line-ending + + - repo: local + hooks: + - id: include-fixer + name: Fixing 'serene' includes + language: script + entry: ./scripts/include-fixer.sh + files: ".*.(h|cpp)" + - repo: https://github.com/pocc/pre-commit-hooks rev: v1.3.5 hooks: - id: clang-format - #- id: clang-tidy - #- id: oclint - id: cppcheck - args: ['--project=compile_commands.json'] - #- id: cpplint + args: ['--project=compile_commands.json', '-j 4'] - id: include-what-you-use - repo: https://github.com/detailyang/pre-commit-shell rev: 1.0.5 diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/builder b/builder index 0b08e52..2c14bf8 100755 --- a/builder +++ b/builder @@ -160,7 +160,7 @@ function build-20() { ## Builds the project using C++20 (will regenerate the bui popd_build } -function build-tidy { ## Builds the project using clang-tidy (It takes longer than usual) +function build-tidy() { ## Builds the project using clang-tidy (It takes longer than usual) build "-DSERENE_ENABLE_TIDY=ON" "${@:2}" } diff --git a/scripts/include-fixer.sh b/scripts/include-fixer.sh new file mode 100755 index 0000000..384bf18 --- /dev/null +++ b/scripts/include-fixer.sh @@ -0,0 +1,47 @@ +#! /bin/bash + +set -e + +# function get_changed_files() { +# local add_modified +# local renamed +# add_modified=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '($1 != "D" && $1 !~ /R.+/) { print $2 }') +# renamed=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 ~ /^R.+/ { print $3 }') + +# echo $add_modified | sed '/^[[:space:]]*$/d' +# echo $renamed | sed '/^[[:space:]]*$/d' +# } + +function fix_includes(){ + #local files=$(get_changed_files) + + echo "Fixing '#include' syntax in '$1'" + sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' "$1" +} + +# function clang_format_staged() { +# local files=$(get_changed_files) + +# if [[ "$files" ]]; +# then +# for file in $(get_changed_files) +# do +# echo "Reformatting $file..." +# clang-format -i $file +# done +# fi + +# } + +# function git_add_changes() { +# local files=$(get_changed_files) + +# if [[ "$files" ]]; +# then +# git add $files +# fi +# } + +fix_includes "$1" +# clang_format_staged +# git_add_changes diff --git a/scripts/pre-commit b/scripts/pre-commit deleted file mode 100755 index bd5b558..0000000 --- a/scripts/pre-commit +++ /dev/null @@ -1,51 +0,0 @@ -#! /bin/bash - -set -e - -function get_changed_files() { - local add_modified - local renamed - add_modified=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '($1 != "D" && $1 !~ /R.+/) { print $2 }') - renamed=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 ~ /^R.+/ { print $3 }') - - echo $add_modified | sed '/^[[:space:]]*$/d' - echo $renamed | sed '/^[[:space:]]*$/d' -} - -function fix_includes(){ - local files=$(get_changed_files) - - if [[ "$files" ]]; - then - echo "Fixing '#include' syntax...." - sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $files - fi -} - -function clang_format_staged() { - local files=$(get_changed_files) - - if [[ "$files" ]]; - then - for file in $(get_changed_files) - do - echo "Reformatting $file..." - clang-format -i $file - done - fi - -} - -function git_add_changes() { - local files=$(get_changed_files) - - if [[ "$files" ]]; - then - git add $files - fi -} - - -fix_includes -clang_format_staged -git_add_changes diff --git a/serene-repl/CMakeLists.txt b/serene-repl/CMakeLists.txt index 883d067..8ccb208 100644 --- a/serene-repl/CMakeLists.txt +++ b/serene-repl/CMakeLists.txt @@ -27,7 +27,7 @@ set_target_properties(serene-repl PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) if(SERENE_ENABLE_TIDY) - set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) + set_target_properties(serene-repl PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH}) endif() if (CPP_20_SUPPORT)