From b42ce83f915f79d3182e7fa6e6d42e18746ed0d0 Mon Sep 17 00:00:00 2001
From: Ben Taylor <ben.taylor@sanger.ac.uk>
Date: Thu, 11 Jun 2015 11:35:55 +0100
Subject: [PATCH] Cache dependencies, add install_dependencies script

---
 .travis.yml             | 10 +++-----
 install_dependencies.sh | 57 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 6 deletions(-)
 create mode 100644 install_dependencies.sh

diff --git a/.travis.yml b/.travis.yml
index 0a6529e46..65ba4990e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,15 +2,13 @@ language: java
 jdk:
   - openjdk7
 sudo: false
+cache:
+  directories:
+  - "build"
 before_install:
   - "export DISPLAY=:99.0"
   - "sh -e /etc/init.d/xvfb start"
-  - "mkdir dependencies && cd dependencies"
-  - "wget ftp://emboss.open-bio.org/pub/EMBOSS/EMBOSS-6.6.0.tar.gz && tar xzfv EMBOSS-6.6.0.tar.gz"
-  - "cd EMBOSS-6.6.0 && mkdir build && ./configure --prefix $(pwd)/build"
-  - "make"
-  - "make install"
-  - "export EMBOSS_ROOT=$(pwd)/build && cd ../.."
+  - "source install_dependencies.sh"
 install:
   - "make"
   - "cd test"
diff --git a/install_dependencies.sh b/install_dependencies.sh
new file mode 100644
index 000000000..d2600866b
--- /dev/null
+++ b/install_dependencies.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+set -x
+set -e
+
+start_dir=$(pwd)
+
+EMBOSS_VERSION="6.6.0"
+
+EMBOSS_DOWNLOAD_URL="ftp://emboss.open-bio.org/pub/EMBOSS/EMBOSS-${EMBOSS_VERSION}.tar.gz"
+
+# Make an install location
+if [ ! -d 'build' ]; then
+  mkdir build
+fi
+cd build
+build_dir=$(pwd)
+
+# DOWNLOAD ALL THE THINGS
+download () {
+  url=$1
+  download_location=$2
+
+  if [ -e $download_location ]; then
+    echo "Skipping download of $url, $download_location already exists"
+  else
+    echo "Downloading $url to $download_location"
+    wget $url -O $download_location
+  fi
+}
+
+download $EMBOSS_DOWNLOAD_URL "emboss-${EMBOSS_VERSION}.tgz"
+
+# Build all the things
+cd $build_dir
+
+## Emboss
+emboss_dir=$(pwd)/EMBOSS-${EMBOSS_VERSION}
+if [ ! -d $emboss_dir ]; then
+  tar xzf emboss-${EMBOSS_VERSION}.tgz
+fi
+cd $emboss_dir
+if [ -e "${emboss_dir}/build/bin/restrict" ]; then
+  echo "Already built Emboss; skipping build"
+else
+  mkdir build
+  ./configure --prefix ${emboss_dir}/build
+  make
+  make install
+fi
+
+export EMBOSS_ROOT=${emboss_dir}/build
+
+cd $start_dir
+
+set +x
+set +e
-- 
GitLab