]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Enable check_format and clang-tidy checks in CI (#562)
authorAlexander Lanin <alex@lanin.de>
Mon, 6 Apr 2020 19:46:40 +0000 (21:46 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 19:46:40 +0000 (21:46 +0200)
.clang-tidy [deleted file]
.travis.sh
.travis.yml
src/.clang-tidy [new file with mode: 0644]
src/Counters.cpp
src/logging.cpp
src/third_party/.clang-tidy [new file with mode: 0644]
unittest/.clang-tidy [new file with mode: 0644]

diff --git a/.clang-tidy b/.clang-tidy
deleted file mode 100644 (file)
index 89196e6..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
----
-Checks:          'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,-clang-analyzer-optin.performance.Padding'
-HeaderFilterRegex: 'src/.*|unittest/.*'
-CheckOptions:    
-  - key:             readability-braces-around-statements.ShortStatementLines
-    value:           1
-...
-
index e68d868150d617f7d9234847dfbef474ac836822..8bed7e97e45dcc3ea22e4489ec32de2d69c6601d 100755 (executable)
@@ -8,3 +8,5 @@ make travis CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix CONFIGU
 make travis CC=clang CXX=clang++ CFLAGS="-fsanitize=undefined" LDFLAGS="-fsanitize=undefined" ASAN_OPTIONS="detect_leaks=0"
 make travis CC=clang CXX=clang++ CFLAGS="-fsanitize=address -g" LDFLAGS="-fsanitize=address" ASAN_OPTIONS="detect_leaks=0"
 make travis CC=/usr/bin/clang CXX=/usr/bin/clang++ TEST=analyze
+make travis CC=/usr/bin/clang CXX=/usr/bin/clang++ TEST=tidy
+make travis CC=/usr/bin/clang CXX=/usr/bin/clang++ TEST=check_format
index b3f5db4f68820a4c80401ed96110bfbaadac6e52..06364abef2cc0999d9c381b1c7423c59b6f54865 100644 (file)
@@ -5,7 +5,7 @@ script:
   - ./autogen.sh
   - test -z $BUILD_DIR || { mkdir -p $BUILD_DIR; cd $BUILD_DIR; }
   - ${SRC_DIR:-.}/configure $CONFIGURE
-  - make
+  - test "$NO_COMPILE" || make
   - make ${TEST:-test}
 
 matrix:
@@ -111,3 +111,50 @@ matrix:
         - libb2-dev
     before_install:
     - source ./.travis/install_cuda.sh
+
+  # Job: Clang tidy
+  - os: linux
+    env: V=1 PATH="/usr/bin:$PATH" NO_COMPILE=1 TEST=tidy
+    addons:
+      apt:
+        packages:
+        - elfutils
+        - libzstd1-dev
+        - libb2-dev
+    before_install:
+    - pip install --user compiledb
+
+  # Job: Check formatting
+  - os: linux
+    env: V=1 PATH="/usr/bin:$PATH" NO_COMPILE=1 TEST=check_format
+    addons:
+      apt:
+        packages:
+        - elfutils
+        - libzstd1-dev
+        - libb2-dev
+
+  # New Jobs go here until they are established for some weeks
+  allow_failures:
+
+  # Job: Clang tidy
+  - os: linux
+    env: V=1 PATH="/usr/bin:$PATH" NO_COMPILE=1 TEST=tidy
+    addons:
+      apt:
+        packages:
+        - elfutils
+        - libzstd1-dev
+        - libb2-dev
+    before_install:
+    - pip install --user compiledb
+
+  # Job: Check formatting
+  - os: linux
+    env: V=1 PATH="/usr/bin:$PATH" NO_COMPILE=1 TEST=check_format
+    addons:
+      apt:
+        packages:
+        - elfutils
+        - libzstd1-dev
+        - libb2-dev
diff --git a/src/.clang-tidy b/src/.clang-tidy
new file mode 100644 (file)
index 0000000..ead3108
--- /dev/null
@@ -0,0 +1,84 @@
+# This .clang-tidy file is used by CI to ensure that commits do not worsen the
+# codebase. The checks and values below are the minimum standard for new code.
+(Without claiming that they are 100% correct. They can be modified on demand!)
+If you want to improve the codebase try enabling some additional checks or
+playing with the configuration values.
+# Some checks are highly style dependent. The goal is NOT to activate all
+# of them.
+
+---
+Checks:          '-*,
+                  readability-*,
+                  -readability-implicit-bool-conversion,
+                  -readability-magic-numbers,
+                  -readability-else-after-return,
+                  -readability-named-parameter,
+                  -readability-qualified-auto,
+                  -readability-magic-numbers,
+                  -readability-isolate-declaration,
+                  -readability-inconsistent-declaration-parameter-name,
+                  -readability-simplify-boolean-expr,
+                  performance-*,
+                  -performance-unnecessary-value-param,
+                  -performance-faster-string-find,
+                  modernize-*,
+                  -modernize-avoid-c-arrays,
+                  -modernize-deprecated-headers,
+                  -modernize-loop-convert,
+                  -modernize-pass-by-value,
+                  -modernize-use-auto,
+                  -modernize-use-bool-literals,
+                  -modernize-use-using,
+                  -modernize-use-trailing-return-type,
+                  cppcoreguidelines-*,
+                  -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
+                  -cppcoreguidelines-pro-type-vararg,
+                  -cppcoreguidelines-owning-memory,
+                  -cppcoreguidelines-avoid-magic-numbers,
+                  -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+                  -cppcoreguidelines-no-malloc,
+                  -cppcoreguidelines-init-variables,
+                  -cppcoreguidelines-avoid-c-arrays,
+                  -cppcoreguidelines-pro-bounds-constant-array-index,
+                  -cppcoreguidelines-pro-type-cstyle-cast,
+                  -cppcoreguidelines-avoid-goto,
+                  -cppcoreguidelines-pro-type-member-init,
+                  -cppcoreguidelines-macro-usage,
+                  -cppcoreguidelines-pro-type-reinterpret-cast,
+                  -cppcoreguidelines-pro-type-union-access,
+                  -cppcoreguidelines-narrowing-conversions,
+                  bugprone-*,
+                  -bugprone-signed-char-misuse,
+                  -bugprone-branch-clone,
+                  -bugprone-narrowing-conversions,
+                  cert-*,
+                  -cert-err34-c,
+                  -cert-dcl50-cpp,
+                  -cert-err58-cpp,
+                  clang-diagnostic-*,
+                  clang-analyzer-*,
+                  -clang-analyzer-alpha*,
+                  -clang-analyzer-valist.Uninitialized,
+                  -clang-analyzer-optin.performance.Padding'
+WarningsAsErrors: '*'
+# Exclude subdirectories (currently there is only third_party)
+HeaderFilterRegex: 'src/[^\\/]*^'
+CheckOptions:    
+  # Always add braces (added here just in case clang-tidy default changes).
+  - key:             readability-braces-around-statements.ShortStatementLines
+    value:           0
+
+  # If you hit a limit, please consider changing the code instead of the limit.
+  - key:             readability-function-size.LineThreshold
+    value:           1100
+  - key:             readability-function-size.StatementThreshold
+    value:           760
+  - key:             readability-function-size.BranchThreshold
+    value:           170
+  - key:             readability-function-size.ParameterThreshold
+    value:           6
+  - key:             readability-function-size.NestingThreshold
+    value:           6
+  - key:             readability-function-size.VariableThreshold
+    value:           80
+...
index 8c0a7b7186172f4f89216cad3ab047bcf5212b66..9b639a61ac132bd3f275cff8c32c7b5462c35433 100644 (file)
@@ -26,7 +26,12 @@ Counters::Counters() : m_counters(STATS_END)
 {
 }
 
-unsigned& Counters::operator[](size_t index)
+// Return type is on separate line since clang-format 10.
+// Since different people use different versions, auto formatting is disabled.
+// clang-format off
+unsigned&
+Counters::operator[](size_t index)
+// clang-format on
 {
   if (index >= m_counters.size()) {
     m_counters.resize(index + 1);
@@ -34,7 +39,12 @@ unsigned& Counters::operator[](size_t index)
   return m_counters.at(index);
 }
 
-unsigned Counters::operator[](size_t index) const
+// Return type is on separate line since clang-format 10.
+// Since different people use different versions, auto formatting is disabled.
+// clang-format off
+unsigned
+Counters::operator[](size_t index) const
+// clang-format on
 {
   return index < m_counters.size() ? m_counters.at(index) : 0;
 }
index 9701294eeba1c89bfc1853d44952b7bf3abaf6d8..6d50aab5d5b389831bfd267761dde6ac3c49777a 100644 (file)
@@ -112,7 +112,7 @@ log_prefix(bool log_updated_time)
     struct tm tm;
     struct timeval tv;
     gettimeofday(&tv, nullptr);
-    if (localtime_r((time_t*)&tv.tv_sec, &tm) != NULL) {
+    if (localtime_r((time_t*)&tv.tv_sec, &tm) != nullptr) {
       strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", &tm);
     } else {
       snprintf(timestamp, sizeof(timestamp), "%lu", tv.tv_sec);
diff --git a/src/third_party/.clang-tidy b/src/third_party/.clang-tidy
new file mode 100644 (file)
index 0000000..d2f78e1
--- /dev/null
@@ -0,0 +1,9 @@
+# It's currently not possible to disable all checkers within a subdirectory via
+# config file... So just pick a fast check that will never fail.
+---
+Checks:          '-*,readability-function-size'
+CheckOptions:    
+  - key:             readability-function-size.LineThreshold
+    value:           99999999
+...
+
diff --git a/unittest/.clang-tidy b/unittest/.clang-tidy
new file mode 100644 (file)
index 0000000..ea8ab28
--- /dev/null
@@ -0,0 +1,26 @@
+---
+Checks:          '-*,readability-function-size'
+WarningsAsErrors: '*'
+HeaderFilterRegex: 'unittest/.*'
+CheckOptions:    
+  # Always add braces (added here just in case clang-tidy default changes).
+  - key:             readability-braces-around-statements.ShortStatementLines
+    value:           0
+
+  # If you hit the limits, please change the code and not the limits!!
+  # Note: some limits "disabled" due to TEST_SUITE macro.
+  # The macro generates hundreds of statements, branches and variables.
+  - key:             readability-function-size.LineThreshold
+    value:           130
+  - key:             readability-function-size.StatementThreshold
+    value:           999999
+  - key:             readability-function-size.ParameterThreshold
+    value:           7
+  - key:             readability-function-size.NestingThreshold
+    value:           6
+  - key:             readability-function-size.NestingThreshold
+    value:           999999
+  - key:             readability-function-size.VariableThreshold
+    value:           999999
+...
+