From caa1be62b6d7d9a481d4c2ee2d18dab3ea79dd50 Mon Sep 17 00:00:00 2001
From: Jorge Aparicio <japaricious@gmail.com>
Date: Sun, 8 Jan 2017 10:43:20 -0500
Subject: [PATCH] CI: use the cross template

---
 .travis.yml                                   | 19 ++++++----
 ci/docker/thumbv6m-none-eabi/Dockerfile       |  9 -----
 ci/docker/thumbv7em-none-eabi/Dockerfile      |  9 -----
 ci/docker/thumbv7em-none-eabihf/Dockerfile    |  9 -----
 ci/docker/thumbv7m-none-eabi/Dockerfile       |  9 -----
 ci/docker/x86_64-unknown-linux-gnu/Dockerfile |  5 ---
 ci/install.sh                                 | 15 ++++++++
 ci/run-docker.sh                              | 35 -------------------
 ci/run.sh                                     | 12 -------
 ci/script.sh                                  | 11 ++++++
 10 files changed, 38 insertions(+), 95 deletions(-)
 delete mode 100644 ci/docker/thumbv6m-none-eabi/Dockerfile
 delete mode 100644 ci/docker/thumbv7em-none-eabi/Dockerfile
 delete mode 100644 ci/docker/thumbv7em-none-eabihf/Dockerfile
 delete mode 100644 ci/docker/thumbv7m-none-eabi/Dockerfile
 delete mode 100644 ci/docker/x86_64-unknown-linux-gnu/Dockerfile
 create mode 100644 ci/install.sh
 delete mode 100755 ci/run-docker.sh
 delete mode 100755 ci/run.sh
 create mode 100644 ci/script.sh

diff --git a/.travis.yml b/.travis.yml
index 3337d3f..0bd9001 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,22 +1,27 @@
-cache: cargo
 dist: trusty
 language: rust
-rust: nightly
 services: docker
 sudo: required
 
+rust: nightly
+
+env: TARGET=x86_64-unknown-linux-gnu
 matrix:
   include:
     - env: TARGET=thumbv6m-none-eabi
-    - env: TARGET=thumbv7m-none-eabi
     - env: TARGET=thumbv7em-none-eabi
     - env: TARGET=thumbv7em-none-eabihf
-env: TARGET=x86_64-unknown-linux-gnu
+    - env: TARGET=thumbv7m-none-eabi
+
+install:
+  - sh ci/install.sh
+  - source ~/.cargo/env || true
 
 script:
-  - cargo generate-lockfile
-  - sh ci/run-docker.sh $TARGET
-  # Travis can't cache files that are not readable by "others"
+  - bash ci/script.sh
+
+cache: cargo
+before_cache:
   - chmod -R a+r $HOME/.cargo
 
 branches:
diff --git a/ci/docker/thumbv6m-none-eabi/Dockerfile b/ci/docker/thumbv6m-none-eabi/Dockerfile
deleted file mode 100644
index fa5439a..0000000
--- a/ci/docker/thumbv6m-none-eabi/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-FROM ubuntu:16.04
-RUN apt-get update
-RUN apt-get install -y --no-install-recommends \
-    ca-certificates \
-    curl \
-    libcurl4-openssl-dev \
-    libssh2-1
-RUN curl -sf "https://raw.githubusercontent.com/japaric/rust-everywhere/master/install.sh" | \
-    bash -s -- --at /usr/bin --from japaric/xargo --for x86_64-unknown-linux-gnu --tag v0.1.13
diff --git a/ci/docker/thumbv7em-none-eabi/Dockerfile b/ci/docker/thumbv7em-none-eabi/Dockerfile
deleted file mode 100644
index fa5439a..0000000
--- a/ci/docker/thumbv7em-none-eabi/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-FROM ubuntu:16.04
-RUN apt-get update
-RUN apt-get install -y --no-install-recommends \
-    ca-certificates \
-    curl \
-    libcurl4-openssl-dev \
-    libssh2-1
-RUN curl -sf "https://raw.githubusercontent.com/japaric/rust-everywhere/master/install.sh" | \
-    bash -s -- --at /usr/bin --from japaric/xargo --for x86_64-unknown-linux-gnu --tag v0.1.13
diff --git a/ci/docker/thumbv7em-none-eabihf/Dockerfile b/ci/docker/thumbv7em-none-eabihf/Dockerfile
deleted file mode 100644
index fa5439a..0000000
--- a/ci/docker/thumbv7em-none-eabihf/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-FROM ubuntu:16.04
-RUN apt-get update
-RUN apt-get install -y --no-install-recommends \
-    ca-certificates \
-    curl \
-    libcurl4-openssl-dev \
-    libssh2-1
-RUN curl -sf "https://raw.githubusercontent.com/japaric/rust-everywhere/master/install.sh" | \
-    bash -s -- --at /usr/bin --from japaric/xargo --for x86_64-unknown-linux-gnu --tag v0.1.13
diff --git a/ci/docker/thumbv7m-none-eabi/Dockerfile b/ci/docker/thumbv7m-none-eabi/Dockerfile
deleted file mode 100644
index fa5439a..0000000
--- a/ci/docker/thumbv7m-none-eabi/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-FROM ubuntu:16.04
-RUN apt-get update
-RUN apt-get install -y --no-install-recommends \
-    ca-certificates \
-    curl \
-    libcurl4-openssl-dev \
-    libssh2-1
-RUN curl -sf "https://raw.githubusercontent.com/japaric/rust-everywhere/master/install.sh" | \
-    bash -s -- --at /usr/bin --from japaric/xargo --for x86_64-unknown-linux-gnu --tag v0.1.13
diff --git a/ci/docker/x86_64-unknown-linux-gnu/Dockerfile b/ci/docker/x86_64-unknown-linux-gnu/Dockerfile
deleted file mode 100644
index dbbecfa..0000000
--- a/ci/docker/x86_64-unknown-linux-gnu/Dockerfile
+++ /dev/null
@@ -1,5 +0,0 @@
-FROM ubuntu:16.04
-RUN apt-get update
-RUN apt-get install -y --no-install-recommends \
-    ca-certificates gcc libc6-dev
-ENV PATH=$PATH:/rust/bin
diff --git a/ci/install.sh b/ci/install.sh
new file mode 100644
index 0000000..1a72b33
--- /dev/null
+++ b/ci/install.sh
@@ -0,0 +1,15 @@
+set -ex
+
+main() {
+    curl https://sh.rustup.rs -sSf | \
+        sh -s -- -y --default-toolchain $TRAVIS_RUST_VERSION
+
+    curl -LSfs https://japaric.github.io/trust/install.sh | \
+        sh -s -- \
+           --force \
+           --git japaric/cross \
+           --tag v0.1.4 \
+           --target x86_64-unknown-linux-gnu
+}
+
+main
diff --git a/ci/run-docker.sh b/ci/run-docker.sh
deleted file mode 100755
index 5a4762d..0000000
--- a/ci/run-docker.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-set -ex
-
-run() {
-    local target=$1
-
-    echo $target
-
-    # This directory needs to exist before calling docker, otherwise docker will create it but it
-    # will be owned by root
-    mkdir -p target
-
-    docker build -t $target ci/docker/$target
-    docker run \
-           --rm \
-           --user $(id -u):$(id -g) \
-           -e CARGO_HOME=/cargo \
-           -e CARGO_TARGET_DIR=/target \
-           -e HOME=/tmp \
-           -v $HOME/.cargo:/cargo \
-           -v `pwd`/target:/target \
-           -v `pwd`:/checkout:ro \
-           -v `rustc --print sysroot`:/rust:ro \
-           -w /checkout \
-           -it $target \
-           sh -c "PATH=\$PATH:/rust/bin ci/run.sh $target"
-}
-
-
-if [ -z "$1" ]; then
-    for d in `ls ci/docker/`; do
-        run $d
-    done
-else
-    run $1
-fi
diff --git a/ci/run.sh b/ci/run.sh
deleted file mode 100755
index fdd3fd2..0000000
--- a/ci/run.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-set -ex
-
-case $1 in
-    thumbv*)
-        xargo build --target $1
-    ;;
-    *)
-        cargo test --target $1
-    ;;
-esac
diff --git a/ci/script.sh b/ci/script.sh
new file mode 100644
index 0000000..53215a8
--- /dev/null
+++ b/ci/script.sh
@@ -0,0 +1,11 @@
+set -ex
+
+main() {
+    cross build --target $TARGET
+
+    if [ $TARGET = x86_64-unknown-linux-gnu ]; then
+        cross test --target $TARGET
+    fi
+}
+
+main
-- 
GitLab