From 2cc43a0558d854107d7f8ebd2a01890a29c9fc2e Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sun, 28 Apr 2019 01:05:52 +0800 Subject: [PATCH 1/6] add clang-tidy support --- .clang-tidy | 8 ++++++++ .travis.yml | 6 ++++++ tools/travis-scripts/before-install.sh | 3 +++ tools/travis-scripts/run-script.sh | 16 ++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000000..233f33927d26 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,8 @@ +--- +Checks: "-*,\ +performance-for-range-copy,\ +readability-const-return-type,\ +" +WarningsAsErrors: '*' +HeaderFilterRegex: '/(?!external)/.*' +... diff --git a/.travis.yml b/.travis.yml index a24f88911744..fb840e17653e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,6 +69,12 @@ matrix: env: BUILD_TARGET=linux_cocos_new_lua_test language: cpp sudo: required + # clang-tidy + - os: linux + dist: xenial + env: BUILD_TARGET=linux_clang_tidy + language: cpp + sudo: required script: - tools/travis-scripts/run-script.sh diff --git a/tools/travis-scripts/before-install.sh b/tools/travis-scripts/before-install.sh index d0c2ee71d9d2..003c5438e869 100755 --- a/tools/travis-scripts/before-install.sh +++ b/tools/travis-scripts/before-install.sh @@ -65,6 +65,9 @@ function install_environement_for_pull_request() if [ "$BUILD_TARGET" == "linux" ]; then install_linux_environment fi + if [ "$BUILD_TARGET" == "linux_clang_tidy" ]; then + install_linux_environment + fi fi if [ "$TRAVIS_OS_NAME" == "osx" ]; then diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index 2505b4525344..064e0fa8d9a6 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -37,6 +37,16 @@ function build_linux() cmake --build . } +function build_linux_clang_tidy() +{ + echo "Building clang tidy test on Linux ..." + cd $COCOS2DX_ROOT/build + mkdir -p clang-tidy-build + cd clang-tidy-build + cmake ../.. -DCMAKE_EXPORT_COMPILE_COMMANDS=on + python /usr/local/clang-7.0.0/share/clang/run-clang-tidy.py -config=$COCOS2DX_ROOT/.clang-tidy +} + function build_mac() { NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` @@ -291,6 +301,12 @@ function run_pull_request() build_linux fi + # linux_clang_tidy_test + if [ $BUILD_TARGET == 'linux_clang_tidy' ]; then + genernate_binding_codes + build_linux_clang_tidy + fi + # android if [ $BUILD_TARGET == 'android_cpp_ndk-build' ]; then build_android_cpp_ndk-build From 2c2fbebbe6275476976bdaafb60b89428e3014db Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sun, 28 Apr 2019 02:04:25 +0800 Subject: [PATCH 2/6] move clang_tidy_test up in travis yaml file so that it's run first --- .clang-tidy | 2 +- .travis.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 233f33927d26..3813411c62e0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,7 @@ --- Checks: "-*,\ +performance-faster-string-find,\ performance-for-range-copy,\ -readability-const-return-type,\ " WarningsAsErrors: '*' HeaderFilterRegex: '/(?!external)/.*' diff --git a/.travis.yml b/.travis.yml index fb840e17653e..7e2fa0f4057d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,12 @@ matrix: - secure: M5lyDs0qai15mWHzJdkh0WPfVJJmVZu6SWtYULxatukGPXVwoQvmEtYAwAW+iz6aM+tXksQ/mk6nW5L8UFbHm+n6yrsa5bZU9sGXjilPE8p8bLFYDmIbPRazU+E6pBP3J2CDoAm0XnWkiYQ8feTxKTo6ysLnHAEjyaHTw0+Q1GM= sudo: required language: cpp + # clang-tidy + - os: linux + dist: xenial + env: BUILD_TARGET=linux_clang_tidy + language: cpp + sudo: required # mac_cmake - os: osx env: BUILD_TARGET=mac_cmake @@ -69,12 +75,6 @@ matrix: env: BUILD_TARGET=linux_cocos_new_lua_test language: cpp sudo: required - # clang-tidy - - os: linux - dist: xenial - env: BUILD_TARGET=linux_clang_tidy - language: cpp - sudo: required script: - tools/travis-scripts/run-script.sh From e253680f1ef026afdddffb7e24aaeb72feaa114c Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sun, 28 Apr 2019 02:34:20 +0800 Subject: [PATCH 3/6] use dump-config to generate .clang-tidy file --- .clang-tidy | 38 ++++++++++++++++++++++++++---- tools/travis-scripts/run-script.sh | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3813411c62e0..5f8b0c4d5473 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,8 +1,38 @@ --- -Checks: "-*,\ -performance-faster-string-find,\ -performance-for-range-copy,\ -" +Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-faster-string-find,performance-for-range-copy,' WarningsAsErrors: '*' HeaderFilterRegex: '/(?!external)/.*' +AnalyzeTemporaryDtors: false +FormatStyle: none +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: performance-faster-string-find.StringLikeClasses + value: 'std::basic_string' + - key: performance-for-range-copy.AllowedTypes + value: '' + - key: performance-for-range-copy.WarnOnAllAutoCopies + value: '0' ... diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index 064e0fa8d9a6..07484bb9b2f2 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -44,7 +44,7 @@ function build_linux_clang_tidy() mkdir -p clang-tidy-build cd clang-tidy-build cmake ../.. -DCMAKE_EXPORT_COMPILE_COMMANDS=on - python /usr/local/clang-7.0.0/share/clang/run-clang-tidy.py -config=$COCOS2DX_ROOT/.clang-tidy + python /usr/local/clang-7.0.0/share/clang/run-clang-tidy.py } function build_mac() From e1182151dd54b2ad6e999b85f2e525447235d137 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sun, 28 Apr 2019 18:00:40 +0800 Subject: [PATCH 4/6] use flexible way to find run-clang-tidy.py clang-tidy and run-clang-tidy.py shares common ancester directory. find the script dynamically rather than hard-coding it. --- tools/travis-scripts/run-script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index 07484bb9b2f2..be1b67bf5c4b 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -44,7 +44,7 @@ function build_linux_clang_tidy() mkdir -p clang-tidy-build cd clang-tidy-build cmake ../.. -DCMAKE_EXPORT_COMPILE_COMMANDS=on - python /usr/local/clang-7.0.0/share/clang/run-clang-tidy.py + python $(dirname $(dirname $(readlink -f `which clang-tidy`)))/share/clang/run-clang-tidy.py } function build_mac() From b5dde36fc95784886e93eb165c770651b81806ce Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sun, 28 Apr 2019 19:42:08 +0800 Subject: [PATCH 5/6] place clang-tidy check options in separate lines --- .clang-tidy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 5f8b0c4d5473..b1e2570723cc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,11 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-faster-string-find,performance-for-range-copy,' +Checks: > + clang-diagnostic-*, + clang-analyzer-*, + -*, + performance-faster-string-find, + performance-for-range-copy, + WarningsAsErrors: '*' HeaderFilterRegex: '/(?!external)/.*' AnalyzeTemporaryDtors: false From 0d996af836dd651da1bf03a0b006fe13c686d72b Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 29 Apr 2019 12:55:35 +0800 Subject: [PATCH 6/6] clang_tidy_test target clean up --- .clang-tidy | 34 ------------------------------ tools/travis-scripts/run-script.sh | 1 - 2 files changed, 35 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b1e2570723cc..f44b7418125e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,5 @@ --- Checks: > - clang-diagnostic-*, - clang-analyzer-*, -*, performance-faster-string-find, performance-for-range-copy, @@ -10,35 +8,3 @@ WarningsAsErrors: '*' HeaderFilterRegex: '/(?!external)/.*' AnalyzeTemporaryDtors: false FormatStyle: none -CheckOptions: - - key: cert-dcl16-c.NewSuffixes - value: 'L;LL;LU;LLU' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: '1' - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - - key: google-readability-function-size.StatementThreshold - value: '800' - - key: google-readability-namespace-comments.ShortNamespaceLines - value: '10' - - key: google-readability-namespace-comments.SpacesBeforeComments - value: '2' - - key: modernize-loop-convert.MaxCopySize - value: '16' - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: modernize-use-nullptr.NullMacros - value: 'NULL' - - key: performance-faster-string-find.StringLikeClasses - value: 'std::basic_string' - - key: performance-for-range-copy.AllowedTypes - value: '' - - key: performance-for-range-copy.WarnOnAllAutoCopies - value: '0' -... diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index be1b67bf5c4b..7a9bd3dd7c9b 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -303,7 +303,6 @@ function run_pull_request() # linux_clang_tidy_test if [ $BUILD_TARGET == 'linux_clang_tidy' ]; then - genernate_binding_codes build_linux_clang_tidy fi