Ver código fonte

travis: include clang-format compatibility

Benjamin Bara 5 anos atrás
pai
commit
8f90b67ff4

+ 16 - 0
.travis.yml

@@ -182,6 +182,22 @@ matrix:
         - ANALYZE=true
         - PYTHON=python3
 #
+# clang-format code analysis
+    - os: linux
+      compiler: clang-6.0
+      addons:
+        apt:
+          sources:
+            - llvm-toolchain-trusty-6.0
+            - ubuntu-toolchain-r-test
+          packages:
+            - clang-6.0
+            - clang-tidy-6.0
+            - clang-format-6.0
+      env:
+        - CLANG_FORMAT=true
+        - PYTHON=python3
+#
 # cpplint checking
     #- os: linux
     #  compiler: gcc

+ 1 - 1
tools/travis/travis_linux_after_success.sh

@@ -2,7 +2,7 @@
 set -ev
 
 # We only want to push the docs once, so we just take the travis run where MINGW=true which is only enabled once
-if [ $MINGW = "true" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
+if [ "$MINGW" = "true" ] && [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
     echo "=== Executing after_success scripts ==="
     # List branches where the doc should be pushed to the webpage
     if [ "${TRAVIS_BRANCH}" = "master" ] || [ "${TRAVIS_BRANCH}" = "0.3" ]; then

+ 5 - 0
tools/travis/travis_linux_before_install.sh

@@ -6,6 +6,11 @@ if [ -z ${LOCAL_PKG+x} ] || [ -z "$LOCAL_PKG" ]; then
     exit 1
 fi
 
+if ! [ -z ${CLANG_FORMAT+x} ]; then
+    echo "CLANG_FORMAT does not need any dependencies. Done."
+    exit 0
+fi
+
 if [ -z ${DOCKER+x} ] && [ -z ${SONAR+x} ]; then
 	# Only on non-docker builds required
 

+ 33 - 0
tools/travis/travis_linux_script.sh

@@ -92,6 +92,39 @@ echo "=== Install build, then compile examples ===" && echo -en 'travis_fold:sta
     exit 0
 fi
 
+if ! [ -z ${CLANG_FORMAT+x} ]; then
+
+    # Only run clang format on Pull requests, not on direct push
+    if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
+        echo -en "\\nSkipping clang-format on non-pull request\\n"
+        exit 0
+    fi
+
+    echo "=== Running clang-format with diff against branch '$TRAVIS_BRANCH' ===" && echo -en 'travis_fold:start:script.clang-format\\r'
+
+    # add clang-format-ci
+    curl -Ls "https://raw.githubusercontent.com/llvm-mirror/clang/c510fac5695e904b43d5bf0feee31cc9550f110e/tools/clang-format/git-clang-format" -o "$LOCAL_PKG/bin/git-clang-format"
+    chmod +x $LOCAL_PKG/bin/git-clang-format
+
+    # We want to get colored diff output into the variable
+    git config color.diff always
+
+    # clang-format the diff to the target branch of the PR
+    difference="$($LOCAL_PKG/bin/git-clang-format --style=file --diff $TRAVIS_BRANCH)"
+
+    if ! case $difference in *"no modified files to format"*) false;; esac; then
+        echo "====== clang-format did not find any issues. Well done! ======"
+        exit 0
+    fi
+
+    echo "====== clang-format Format Errors ======"
+    echo -e "Please fix the following issues:\n\n"
+    echo "${difference}"
+
+    echo -en 'travis_fold:start:script.clang-format\\r'
+    exit 1
+fi
+
 if ! [ -z ${ANALYZE+x} ]; then
     echo "=== Running static code analysis ===" && echo -en 'travis_fold:start:script.analyze\\r'
     if ! case $CC in clang*) false;; esac; then