From 27836ede7004581308edee8072f865f0fb993cec Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 17 Jul 2018 15:01:01 +0200 Subject: [PATCH] run clang tidy on travis --- .travis.yml | 29 ++++++++++++--- Jamroot.jam | 2 + clang_tidy.jam | 92 ++++++++++++++++++++++++++++++++++++++++++++++ ed25519/src/sc.cpp | 50 ++++++++++++------------- 4 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 clang_tidy.jam diff --git a/.travis.yml b/.travis.yml index 4073f92d9..a1ee8b6db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,18 @@ matrix: fast_finish: true include: - if: repo = arvidn/libtorrent - env: variant=release sonar_scan=1 toolset=gcc pylint=1 - - env: variant=test_debug lint=1 tests=1 toolset=gcc-sanitizer + env: variant=release sonar_scan=1 toolset=gcc + - env: variant=debug toolset=gcc lint=1 pylint=1 clang_tidy=1 + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - libc++-dev + - python3-pip + - libboost1.55-all-dev + - libboost1.55-tools-dev + - env: variant=test_debug tests=1 toolset=gcc-sanitizer - env: variant=test_debug sim=1 crypto=openssl toolset=gcc-sanitizer - env: variant=test_release coverage=1 tests=1 toolset=gcc-coverage python=1 - env: autotools=1 toolset=gcc @@ -46,7 +56,6 @@ addons: - python2.7-dev - g++-5 - [cmake3, ninja-build] - - python3-pip before_install: @@ -110,6 +119,9 @@ install: -static-libstdc++ -static-libgcc ;" >> ~/user-config.jam; fi;' + - 'if [ $clang_tidy == "1" ]; then + echo "using clang_tidy : : clang-tidy "-checks=-clang-analyzer-core.*" : -std=c++11 -stdlib=libc++ -stdlib=libc++ ;" >> ~/user-config.jam; + fi' - 'echo "using darwin : : ccache clang++ : -std=c++11 ;" >> ~/user-config.jam' - 'echo "using darwin : ios_sim : ccache clang++ : -std=c11 -std=c++11 -Wno-deprecated-declarations \"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk\" @@ -174,8 +186,10 @@ install: # remove all paths containing 'cmake' to use the executable from /usr/bin export PATH=`echo ${PATH} | awk -v RS=: -v ORS=: '/cmake/ {next} {print}'` fi - - which cmake - - cmake --version + - if [[ "$cmake" == "1" ]]; then + which cmake; + cmake --version; + fi script: @@ -196,6 +210,11 @@ script: build-wrapper-linux-x86-64 --out-dir bw-output bjam -a -j3 optimization=off crypto=$crypto deprecated-functions=off $toolset variant=$variant -l300 && sonar-scanner -D sonar.login=$SONAR_TOKEN; fi' + - 'if [[ $clang_tidy == "1" ]]; then + which clang-tidy; + clang-tidy --version; + bjam -a -j3 clang_tidy; + fi' # if we are building with code coverage, report it as soon as possible # libtorrent is the name of the test suite target diff --git a/Jamroot.jam b/Jamroot.jam index e69de29bb..4d20e952a 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -0,0 +1,2 @@ +include clang_tidy.jam + diff --git a/clang_tidy.jam b/clang_tidy.jam new file mode 100644 index 000000000..726018aaf --- /dev/null +++ b/clang_tidy.jam @@ -0,0 +1,92 @@ +# Copyright (c) 2018 Arvid Norberg (arvid@libtorrent.org) +# +# Use, modification and distribution is subject to the Boost Software +# License Version 1.0. (See accompanying file LICENSE_1_0.txt or +# http://www.boost.org/LICENSE_1_0.txt) + +import common ; +import toolset ; +import feature ; + +feature.extend toolset : clang_tidy ; + +generators.register-c-compiler clang_tidy.compile.c++ : CPP : OBJ : clang_tidy ; +generators.register-c-compiler clang_tidy.compile.c : C : OBJ : clang_tidy ; +generators.register-archiver clang_tidy.archive : OBJ : STATIC_LIB : clang_tidy ; +generators.register-linker clang_tidy.link : OBJ SEARCHED_LIB STATIC_LIB : EXE : clang_tidy ; +generators.register-linker clang_tidy.link.dll : OBJ SEARCHED_LIB STATIC_LIB : SHARED_LIB : clang_tidy ; + +rule init ( version ? : command * : options * ) { + command = [ common.get-invocation-command clang_tidy : clang-tidy + : $(command) ] ; + + # Determine the version + if $(command) { + local command-string = \"$(command)\" ; + command-string = $(command-string:J=" ") ; + version ?= [ MATCH "version ([0-9.]+)" + : [ SHELL "$(command-string) --version" ] ] ; + } + + local condition = [ common.check-init-parameters clang_tidy + : version $(version) ] ; + + common.handle-options clang_tidy : $(condition) : $(command) : $(options) ; +} + +############################################################################### +# Flags + +toolset.flags clang_tidy.compile OPTIONS ; +toolset.flags clang_tidy.compile.c++ OPTIONS ; + +toolset.flags clang_tidy.compile DEFINES ; +toolset.flags clang_tidy.compile INCLUDES ; + +toolset.flags clang_tidy.compile OPTIONS off : ; +toolset.flags clang_tidy.compile OPTIONS speed : -O3 ; +toolset.flags clang_tidy.compile OPTIONS space : -Os ; + +toolset.flags clang_tidy.compile OPTIONS off : -fno-inline ; +# For clang, 'on' and 'full' are identical. +toolset.flags clang_tidy.compile OPTIONS on : -Wno-inline ; +toolset.flags clang_tidy.compile OPTIONS full : -Wno-inline ; + +toolset.flags clang_tidy.compile OPTIONS off : -w ; +toolset.flags clang_tidy.compile OPTIONS on : -Wall ; +toolset.flags clang_tidy.compile OPTIONS all : -Wall -pedantic ; +toolset.flags clang_tidy.compile OPTIONS on : -Werror ; + +toolset.flags clang_tidy.compile OPTIONS on : -g ; +toolset.flags clang_tidy.compile OPTIONS on : -pg ; +toolset.flags clang_tidy.compile OPTIONS off : -fno-rtti ; + +############################################################################### +# C and C++ compilation + +TOUCH = [ common.file-creation-command ] ; + +actions compile.c++ { + "$(CONFIG_COMMAND)" -header-filter=*. -warnings-as-errors=* "$(>)" -- -x c++ $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" \ + && $(TOUCH) "$(<)" +} + +actions compile.c { + "$(CONFIG_COMMAND)" -header-filter=*. -warnings-as-errors=* "$(>)" -- -x c $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" \ + && $(TOUCH) "$(<)" +} + +############################################################################### +# Linking + +actions archive { + $(TOUCH) "$(<)" +} + +actions link { + $(TOUCH) "$(<)" +} + +actions link.dll { + $(TOUCH) "$(<)" +} diff --git a/ed25519/src/sc.cpp b/ed25519/src/sc.cpp index 18b8b4771..8a18055c3 100644 --- a/ed25519/src/sc.cpp +++ b/ed25519/src/sc.cpp @@ -88,42 +88,42 @@ void sc_reduce(unsigned char *s) { s14 -= s23 * 997805; s15 += s23 * 136657; s16 -= s23 * 683901; - s23 = 0; + s23 = 0; // NOLINT s10 += s22 * 666643; s11 += s22 * 470296; s12 += s22 * 654183; s13 -= s22 * 997805; s14 += s22 * 136657; s15 -= s22 * 683901; - s22 = 0; + s22 = 0; // NOLINT s9 += s21 * 666643; s10 += s21 * 470296; s11 += s21 * 654183; s12 -= s21 * 997805; s13 += s21 * 136657; s14 -= s21 * 683901; - s21 = 0; + s21 = 0; // NOLINT s8 += s20 * 666643; s9 += s20 * 470296; s10 += s20 * 654183; s11 -= s20 * 997805; s12 += s20 * 136657; s13 -= s20 * 683901; - s20 = 0; + s20 = 0; // NOLINT s7 += s19 * 666643; s8 += s19 * 470296; s9 += s19 * 654183; s10 -= s19 * 997805; s11 += s19 * 136657; s12 -= s19 * 683901; - s19 = 0; + s19 = 0; // NOLINT s6 += s18 * 666643; s7 += s18 * 470296; s8 += s18 * 654183; s9 -= s18 * 997805; s10 += s18 * 136657; s11 -= s18 * 683901; - s18 = 0; + s18 = 0; // NOLINT carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= shift_left(carry6, 21); @@ -163,35 +163,35 @@ void sc_reduce(unsigned char *s) { s8 -= s17 * 997805; s9 += s17 * 136657; s10 -= s17 * 683901; - s17 = 0; + s17 = 0; // NOLINT s4 += s16 * 666643; s5 += s16 * 470296; s6 += s16 * 654183; s7 -= s16 * 997805; s8 += s16 * 136657; s9 -= s16 * 683901; - s16 = 0; + s16 = 0; // NOLINT s3 += s15 * 666643; s4 += s15 * 470296; s5 += s15 * 654183; s6 -= s15 * 997805; s7 += s15 * 136657; s8 -= s15 * 683901; - s15 = 0; + s15 = 0; // NOLINT s2 += s14 * 666643; s3 += s14 * 470296; s4 += s14 * 654183; s5 -= s14 * 997805; s6 += s14 * 136657; s7 -= s14 * 683901; - s14 = 0; + s14 = 0; // NOLINT s1 += s13 * 666643; s2 += s13 * 470296; s3 += s13 * 654183; s4 -= s13 * 997805; s5 += s13 * 136657; s6 -= s13 * 683901; - s13 = 0; + s13 = 0; // NOLINT s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; @@ -284,7 +284,7 @@ void sc_reduce(unsigned char *s) { s3 -= s12 * 997805; s4 += s12 * 136657; s5 -= s12 * 683901; - s12 = 0; + s12 = 0; // NOLINT carry0 = s0 >> 21; s1 += carry0; s0 -= shift_left(carry0, 21); @@ -550,42 +550,42 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s14 -= s23 * 997805; s15 += s23 * 136657; s16 -= s23 * 683901; - s23 = 0; + s23 = 0; // NOLINT s10 += s22 * 666643; s11 += s22 * 470296; s12 += s22 * 654183; s13 -= s22 * 997805; s14 += s22 * 136657; s15 -= s22 * 683901; - s22 = 0; + s22 = 0; // NOLINT s9 += s21 * 666643; s10 += s21 * 470296; s11 += s21 * 654183; s12 -= s21 * 997805; s13 += s21 * 136657; s14 -= s21 * 683901; - s21 = 0; + s21 = 0; // NOLINT s8 += s20 * 666643; s9 += s20 * 470296; s10 += s20 * 654183; s11 -= s20 * 997805; s12 += s20 * 136657; s13 -= s20 * 683901; - s20 = 0; + s20 = 0; // NOLINT s7 += s19 * 666643; s8 += s19 * 470296; s9 += s19 * 654183; s10 -= s19 * 997805; s11 += s19 * 136657; s12 -= s19 * 683901; - s19 = 0; + s19 = 0; // NOLINT s6 += s18 * 666643; s7 += s18 * 470296; s8 += s18 * 654183; s9 -= s18 * 997805; s10 += s18 * 136657; s11 -= s18 * 683901; - s18 = 0; + s18 = 0; // NOLINT carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= shift_left(carry6, 21); @@ -625,42 +625,42 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s8 -= s17 * 997805; s9 += s17 * 136657; s10 -= s17 * 683901; - s17 = 0; + s17 = 0; // NOLINT s4 += s16 * 666643; s5 += s16 * 470296; s6 += s16 * 654183; s7 -= s16 * 997805; s8 += s16 * 136657; s9 -= s16 * 683901; - s16 = 0; + s16 = 0; // NOLINT s3 += s15 * 666643; s4 += s15 * 470296; s5 += s15 * 654183; s6 -= s15 * 997805; s7 += s15 * 136657; s8 -= s15 * 683901; - s15 = 0; + s15 = 0; // NOLINT s2 += s14 * 666643; s3 += s14 * 470296; s4 += s14 * 654183; s5 -= s14 * 997805; s6 += s14 * 136657; s7 -= s14 * 683901; - s14 = 0; + s14 = 0; // NOLINT s1 += s13 * 666643; s2 += s13 * 470296; s3 += s13 * 654183; s4 -= s13 * 997805; s5 += s13 * 136657; s6 -= s13 * 683901; - s13 = 0; + s13 = 0; // NOLINT s0 += s12 * 666643; s1 += s12 * 470296; s2 += s12 * 654183; s3 -= s12 * 997805; s4 += s12 * 136657; s5 -= s12 * 683901; - s12 = 0; + s12 = 0; // NOLINT carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; s0 -= shift_left(carry0, 21); @@ -746,7 +746,7 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, s3 -= s12 * 997805; s4 += s12 * 136657; s5 -= s12 * 683901; - s12 = 0; + s12 = 0; // NOLINT carry0 = s0 >> 21; s1 += carry0; s0 -= shift_left(carry0, 21);