From fd940b2e19df31a4aa95c031e0ae0ff8dfb86901 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Thu, 8 Dec 2016 16:18:50 -0500
Subject: [PATCH] Prepare the travis run to use a matrix of options

---
 .travis.yml                        |  6 ++---
 scripts/travis/run-clang-format.sh | 24 --------------------
 scripts/travis/run-format.sh       | 35 ++++++++++++++++++++++++++++++
 scripts/travis/run.sh              | 19 ++++++++++++++++
 4 files changed, 57 insertions(+), 27 deletions(-)
 delete mode 100755 scripts/travis/run-clang-format.sh
 create mode 100755 scripts/travis/run-format.sh
 create mode 100755 scripts/travis/run.sh

diff --git a/.travis.yml b/.travis.yml
index e63b33157..16e53174d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,8 +14,8 @@ 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
+env:
+  - BUILD_MATRIX_ENTRY=format
 script:
-  - cd ${TRAVIS_BUILD_DIR}
-  - scripts/travis/run-clang-format.sh
-  - ~/.local/bin/flake8 --config=flake8.cfg .
+  - ${TRAVIS_BUILD_DIR}/scripts/travis/run.sh
  
diff --git a/scripts/travis/run-clang-format.sh b/scripts/travis/run-clang-format.sh
deleted file mode 100755
index 2cf0cfef5..000000000
--- a/scripts/travis/run-clang-format.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/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
diff --git a/scripts/travis/run-format.sh b/scripts/travis/run-format.sh
new file mode 100755
index 000000000..7ba599738
--- /dev/null
+++ b/scripts/travis/run-format.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+if [ -z "${SOURCE_DIR}" ]
+then
+  echo "Error: SOURCE_DIR is empty or undefined"
+  exit 1
+fi
+if [ -z "${COMMIT_RANGE}" ]
+then
+  echo "Error: COMMIT_RANGE is empty or undefined"
+  exit 1
+fi
+
+cd ${SOURCE_DIR}
+
+# Check C and C++ code with clang-format
+DIFF="$(./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
+
+# Check python code with flake8
+if ! ~/.local/bin/flake8 --config=flake8.cfg .
+then
+  exit 3
+fi
+
+exit 0
diff --git a/scripts/travis/run.sh b/scripts/travis/run.sh
new file mode 100755
index 000000000..5d0138236
--- /dev/null
+++ b/scripts/travis/run.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+
+export SOURCE_DIR=${TRAVIS_BUILD_DIR}
+export BUILD_DIR=$(readlink -f ${SOURCE_DIR}/..)
+export COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../ }"
+
+case ${BUILD_MATRIX_ENTRY} in
+  format)
+    echo "Running formatting tests"
+    if ! ${SOURCE_DIR}/scripts/travis/run-format.sh; then
+      exit 1;
+    fi
+    ;;
+  *)
+    echo "Error: BUILD_MATRIX_ENTRY is undefined or set to an unknown value"
+    exit 1;
+    ;;
+esac
-- 
GitLab