Преглед изворни кода

add clang-tidy for linting

Julius Pfrommer пре 7 година
родитељ
комит
4f93f53c23

+ 1 - 26
.travis.yml

@@ -33,11 +33,9 @@ addons:
   apt:
     sources:
       # see https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
-      - kalakris-cmake
     packages:
       - binutils-mingw-w64-i686
       - build-essential
-      - clang
       - cmake
       - gcc-multilib
       - g++-multilib
@@ -73,7 +71,6 @@ cache:
     - $HOME/install
 
 before_install:
-- sh ./tools/travis/travis_notifications.sh
 - if [ ${TRAVIS_OS_NAME} == "linux" ]; then sh ./tools/travis/travis_linux_before_install.sh; fi
 - if [ ${TRAVIS_OS_NAME} == "osx" ]; then sh ./tools/travis/travis_osx_before_install.sh; fi
 
@@ -84,19 +81,6 @@ script:
 after_success:
 - if [ ${TRAVIS_OS_NAME} == "linux" ]; then sh ./tools/travis/travis_linux_after_success.sh; fi
 
-before_deploy:
-- rm build -rf && mkdir -p build && cd build
-- echo "Cross compile release build for Raspberry Pi"
-- cd ~
-- git clone https://github.com/raspberrypi/tools
-- cd -
-- export PATH=$PATH:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
-- cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
-- make
-- tar -pczf open62541-raspberrypi.tar.gz ../doc ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
-- cp open62541-raspberrypi.tar.gz ..
-- cd ..
-
 deploy:
   provider: releases
   api_key:
@@ -113,13 +97,4 @@ deploy:
   on:
     repo: open62541/open62541
     tags: true
-    condition: $CC = gcc && $ANALYZE = false
-
-notifications:
-  irc:
-    channels:
-        - "chat.freenode.net#open62541"
-    on_success: ${IRC_NOTIFY_SUCCESS} # default: change, variable defined in ./tools/travis/travis_notification.sh
-    on_failure: ${IRC_NOTIFY_FAILURE} # default: always, variable defined in ./tools/travis/travis_notification.sh
-    use_notice: true
-    skip_join: true
+    condition: $CC = gcc && $ANALYZE = false

+ 34 - 16
CMakeLists.txt

@@ -424,6 +424,27 @@ if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
                     DEPENDS ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
 endif()
 
+############################
+# Linting run (clang-tidy) #
+############################
+
+find_package(ClangTools)
+add_custom_target(lint ${CLANG_TIDY_PROGRAM}
+                  ${lib_sources}
+                  -checks=cert-*,performance-*,readability-*,-readability-braces-around-statements
+                  -warnings-as-errors=cert-*,performance-*,readability-*,-readability-braces-around-statements
+                  --
+                  -std=c99
+                  -I${PROJECT_SOURCE_DIR}/include
+                  -I${PROJECT_SOURCE_DIR}/plugins
+                  -I${PROJECT_SOURCE_DIR}/deps
+                  -I${PROJECT_SOURCE_DIR}/src
+                  -I${PROJECT_SOURCE_DIR}/src/server
+                  -I${PROJECT_SOURCE_DIR}/src/client
+                  -I${PROJECT_BINARY_DIR}/src_generated
+                  DEPENDS ${lib_sources}
+                  COMMENT "Run clang-tidy on the library")
+add_dependencies(lint open62541)
 
 ##########################
 # Installation           #
@@ -435,27 +456,24 @@ endif()
 # export library (either static or shared depending on BUILD_SHARED_LIBS)
 install(TARGETS open62541
         LIBRARY DESTINATION lib
-        ARCHIVE DESTINATION lib
-    )
+        ARCHIVE DESTINATION lib)
 # export amalgamated header open62541.h which is generated due to build of open62541-object
 install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include)
 
-
-
 ##########################
 # Packaging (DEB/RPM)    #
 ##########################
 # invoke via `make package`
 
-SET(CPACK_GENERATOR "TGZ;DEB;RPM")
-SET(CPACK_PACKAGE_VENDOR "open62541 team")
-SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
-SET(CPACK_PACKAGE_DESCRIPTION "open62541 is a C-based library (linking with C++ projects is possible) with all necessary tools to implement dedicated OPC UA clients and servers, or to integrate OPC UA-based communication into existing applications.")
-SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
-SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
-SET(CPACK_PACKAGE_VERSION_MAJOR "0")
-SET(CPACK_PACKAGE_VERSION_MINOR "2")
-SET(CPACK_PACKAGE_VERSION_PATCH "0")
-SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
-
-INCLUDE(CPack)
+set(CPACK_GENERATOR "TGZ;DEB;RPM")
+set(CPACK_PACKAGE_VENDOR "open62541 team")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
+set(CPACK_PACKAGE_DESCRIPTION "open62541 is a C-based library (linking with C++ projects is possible) with all necessary tools to implement dedicated OPC UA clients and servers, or to integrate OPC UA-based communication into existing applications.")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+set(CPACK_PACKAGE_VERSION_MAJOR "0")
+set(CPACK_PACKAGE_VERSION_MINOR "2")
+set(CPACK_PACKAGE_VERSION_PATCH "0")
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
+
+include(CPack)

+ 29 - 0
tools/cmake/FindClangTools.cmake

@@ -0,0 +1,29 @@
+# Find Clang Tools
+#
+# This module defines
+#  CLANG_TIDY_PROGRAM, The  path to the clang tidy binary
+#  CLANG_TIDY_FOUND, Whether clang tidy was found
+#  CLANG_FORMAT_PROGRAM, The path to the clang format binary
+#  CLANG_FORMAT_FOUND, Whether clang format was found
+
+find_program(CLANG_TIDY_PROGRAM
+  NAMES clang-tidy-3.9 clang-tidy-3.8 clang-tidy-3.7 clang-tidy-3.6  clang-tidy
+  PATHS $ENV{CLANG_TOOLS_PATH} /usr/local/bin /usr/bin
+  NO_DEFAULT_PATH)
+
+if("${CLANG_TIDY_PROGRAM}" STREQUAL "CLANG_TIDY_PROGRAM-NOTFOUND")
+  set(CLANG_TIDY_FOUND 0)
+else()
+  set(CLANG_TIDY_FOUND 1)
+endif()
+
+find_program(CLANG_FORMAT_PROGRAM
+  NAMES clang-format 3.9 clang-format-3.8 clang-format-3.7 clang-format-3.6  clang-format
+  PATHS $ENV{CLANG_TOOLS_PATH} /usr/local/bin /usr/bin
+  NO_DEFAULT_PATH)
+
+if("${CLANG_FORMAT_PROGRAM}" STREQUAL "CLANG_FORMAT_PROGRAM-NOTFOUND")
+  set(CLANG_FORMAT_FOUND 0)
+else()
+  set(CLANG_FORMAT_FOUND 1)
+endif()

+ 7 - 6
tools/travis/travis_linux_before_install.sh

@@ -1,18 +1,19 @@
 #!/bin/bash
 set -ev
 
-echo "=== Updating the build environment in $LOCAL_PKG ==="
+echo "=== Installing from external package sources ==="
+wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
+echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main" | sudo tee -a /etc/apt/sources.list
+sudo add-apt-repository -y ppa:lttng/ppa
+sudo apt-get update -qq
+sudo apt-get install -y clang-3.9 clang-tidy-3.9
+sudo apt-get install -y liburcu4 liburcu-dev
 
 echo "=== Installing python packages ==="
 pip install --user cpp-coveralls
 pip install --user sphinx
 pip install --user sphinx_rtd_theme
 
-wget https://launchpad.net/~lttng/+archive/ubuntu/ppa/+build/11525342/+files/liburcu-dev_0.9.x+stable+bzr1192+pack30+201612060302~ubuntu14.04.1_amd64.deb
-wget https://launchpad.net/~lttng/+archive/ubuntu/ppa/+build/11525342/+files/liburcu4_0.9.x+stable+bzr1192+pack30+201612060302~ubuntu14.04.1_amd64.deb
-sudo dpkg -i *.deb
-rm *.deb
-
 echo "=== Installed versions are ==="
 clang --version
 g++ --version

+ 35 - 20
tools/travis/travis_linux_script.sh

@@ -6,20 +6,27 @@ if [ $ANALYZE = "true" ]; then
     if [ "$CC" = "clang" ]; then
         mkdir -p build
         cd build
-        scan-build cmake -G "Unix Makefiles" -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
-        scan-build -enable-checker security.FloatLoopCounter \
+        scan-build-3.9 cmake -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON ..
+        scan-build-3.9 -enable-checker security.FloatLoopCounter \
           -enable-checker security.insecureAPI.UncheckedReturn \
           --status-bugs -v \
-          make -j 8
+          make -j
         cd .. && rm build -rf
 
         mkdir -p build
         cd build
-        scan-build cmake -G "Unix Makefiles" -DUA_ENABLE_AMALGAMATION=ON ..
-        scan-build -enable-checker security.FloatLoopCounter \
+        scan-build-3.9 cmake -DUA_ENABLE_AMALGAMATION=ON ..
+        scan-build-3.9 -enable-checker security.FloatLoopCounter \
           -enable-checker security.insecureAPI.UncheckedReturn \
           --status-bugs -v \
-          make -j 8
+          make -j
+        cd .. && rm build -rf
+
+        mkdir -p build
+        cd build
+        cmake -DUA_BUILD_EXAMPLES=ON ..
+        make -j
+        make lint
         cd .. && rm build -rf
     else
         cppcheck --template "{file}({line}): {severity} ({id}): {message}" \
@@ -53,7 +60,7 @@ else
     mkdir -p build
     cd build
     cmake -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_GENERATE_NAMESPACE0=On -DUA_BUILD_EXAMPLES=ON  ..
-    make -j8
+    make -j
     cd .. && rm build -rf
     
     # cross compilation only with gcc
@@ -61,33 +68,43 @@ else
         echo "Cross compile release build for MinGW 32 bit"
         mkdir -p build && cd build
         cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
-        make -j8
-        zip -r open62541-win32.zip ../../doc ../../doc_latex/open62541.pdf ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
+        make -j
+        zip -r open62541-win32.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
         cp open62541-win32.zip ..
         cd .. && rm build -rf
 
         echo "Cross compile release build for MinGW 64 bit"
         mkdir -p build && cd build
         cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-mingw64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
-        make -j8
-        zip -r open62541-win64.zip ../../doc ../../doc_latex/open62541.pdf ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
+        make -j
+        zip -r open62541-win64.zip ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server.exe examples/client.exe libopen62541.dll.a open62541.h open62541.c
         cp open62541-win64.zip ..
         cd .. && rm build -rf
 
         echo "Cross compile release build for 32-bit linux"
         mkdir -p build && cd build
         cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-gcc-m32.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
-        make -j8
-        tar -pczf open62541-linux32.tar.gz ../../doc ../../doc_latex/open62541.pdf ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
+        make -j
+        tar -pczf open62541-linux32.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
         cp open62541-linux32.tar.gz ..
         cd .. && rm build -rf
+
+        echo "Cross compile release build for RaspberryPi"
+        mkdir -p build && cd build
+        git clone https://github.com/raspberrypi/tools
+        export PATH=$PATH:./tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/
+        cmake -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/Toolchain-rpi64.cmake -DUA_ENABLE_AMALGAMATION=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON ..
+        make -j
+        tar -pczf open62541-raspberrypi.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
+        cp open62541-raspberrypi.tar.gz ..
+        cd .. && rm build -rf
     fi
 
     echo "Compile release build for 64-bit linux"
     mkdir -p build && cd build
     cmake -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON -DUA_BUILD_EXAMPLES=ON ..
-    make -j8
-    tar -pczf open62541-linux64.tar.gz ../../doc ../../doc_latex/open62541.pdf ../../server_cert.der ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
+    make -j
+    tar -pczf open62541-linux64.tar.gz ../../doc_latex/open62541.pdf ../LICENSE ../AUTHORS ../README.md examples/server examples/client libopen62541.a open62541.h open62541.c
     cp open62541-linux64.tar.gz ..
     cp open62541.h ../.. # copy single file-release
     cp open62541.c ../.. # copy single file-release
@@ -103,25 +120,23 @@ else
     echo "Compile multithreaded version"
     mkdir -p build && cd build
     cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLESERVER=ON -DUA_BUILD_EXAMPLES=ON ..
-    make -j8
+    make -j
     cd .. && rm build -rf
 
     echo "Debug build and unit tests (64 bit)"
     mkdir -p build && cd build
     cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
-    make -j8 && make test ARGS="-V"
+    make -j && make test ARGS="-V"
     (valgrind --leak-check=yes --error-exitcode=3 ./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
     # without valgrind
     cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON ..
-    make -j8 && make test ARGS="-V"
+    make -j && make test ARGS="-V"
     (./examples/server & export pid=$!; sleep 2; kill -INT $pid; wait $pid);
     # only run coveralls on main repo, otherwise it fails uploading the files
     echo "-> Current repo: ${TRAVIS_REPO_SLUG}"
     if [ "$CC" = "gcc" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
         echo "  Building coveralls for ${TRAVIS_REPO_SLUG}"
         coveralls -E '.*\.h' -E '.*CMakeCXXCompilerId\.cpp' -E '.*CMakeCCompilerId\.c' -r ../ || true # ignore result since coveralls is unreachable from time to time
-    else
-        echo "  Skipping coveralls since not gcc and/or ${TRAVIS_REPO_SLUG} is not the main repo"
     fi
     cd .. && rm build -rf
 fi

+ 0 - 12
tools/travis/travis_notifications.sh

@@ -1,12 +0,0 @@
-#!/bin/bash
-set -ev
-
-IRC_NOTIFY_SUCCESS="never"
-IRC_NOTIFY_FAILURE="never"
-
-if [ ${TRAVIS_OS_NAME} == "linux" ] && [ ${CC} == "gcc" ]; then
-    if [ ${TRAVIS_BRANCH} == "0.2" ] || [ ${TRAVIS_BRANCH} == "master" ]; then
-        IRC_NOTIFY_SUCCESS="always"
-        IRC_NOTIFY_FAILURE="always"
-    fi
-fi