From fb9af5d704314a20e16e0864ed31b2114fd19e19 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Wed, 7 Dec 2016 14:06:22 -0500
Subject: [PATCH] Add initial travis build for clang-format and flake8

---
 .clang-tidy                        |  1 +
 .travis.yml                        | 21 +++++++++++++++++++++
 flake8.cfg                         |  4 ++++
 scripts/travis/run-clang-format.sh | 24 ++++++++++++++++++++++++
 4 files changed, 50 insertions(+)
 create mode 100644 .clang-tidy
 create mode 100644 .travis.yml
 create mode 100644 flake8.cfg
 create mode 100755 scripts/travis/run-clang-format.sh

diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 000000000..3d43393ef
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1 @@
+Checks: -*,cppcoreguidelines-*,google-*,llvm-*,misc-*,modernize-*,performance-*
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..e63b33157
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,21 @@
+sudo: false
+language: cpp
+dist: trusty
+addons:
+  apt:
+    sources:
+      - llvm-toolchain-trusty-3.8
+    packages:
+      - clang-format-3.8
+      - clang-tidy-3.8
+before_install:
+  - wget http://www.cmake.org/files/v3.7/cmake-3.7.1-Linux-x86_64.tar.gz
+install: 
+  - tar -xf cmake-3.7.1-Linux-x86_64.tar.gz
+  - export PATH="${PWD}/cmake-3.7.1-Linux-x86_64/bin:${PATH}"
+  - pip install --user flake8
+script:
+  - cd ${TRAVIS_BUILD_DIR}
+  - scripts/travis/run-clang-format.sh
+  - ~/.local/bin/flake8 --config=flake8.cfg .
+ 
diff --git a/flake8.cfg b/flake8.cfg
new file mode 100644
index 000000000..94cbae63c
--- /dev/null
+++ b/flake8.cfg
@@ -0,0 +1,4 @@
+[flake8]
+max-line-length: 80
+max-complexity: 14
+format: pylint
diff --git a/scripts/travis/run-clang-format.sh b/scripts/travis/run-clang-format.sh
new file mode 100755
index 000000000..2cf0cfef5
--- /dev/null
+++ b/scripts/travis/run-clang-format.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+if [ -z "${TRAVIS_PULL_REQUEST_BRANCH}" ]
+then
+  echo "This is only designed to run on Pull Requests"
+  exit 1
+else
+  COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../ }"
+fi
+
+# Run clang-format
+DIFF="$(${TRAVIS_BUILD_DIR}/scripts/developer/git/git-clang-format --diff ${COMMIT_RANGE})"
+if [ "${DIFF}" != "no modified files to format" ]
+then
+  echo "clang-format:"
+  echo "  Code format checks failed."
+  echo "  Please run clang-format (or git clang-format) on your changes"
+  echo "  before committing."
+  echo "  The following changes are suggested:"
+  echo "${DIFF}"
+  exit 1
+fi
+
+exit 0
-- 
GitLab