浏览代码

cache Cargo artifacts

notable changes in the docker-based testing infrastructure

- the docker containers can now modify $CARGO_HOME, to re-use the outer
  Cargo registry, and the target directory to re-use build artifacts.

- the docker containers are removed when their execution finishes
  because it's no longer necessary to re-start them to inspect them
  because all the interesting output is in the outer target directory
Jorge Aparicio 8 年之前
父节点
当前提交
43e019dfc4

+ 5 - 2
.travis.yml

@@ -1,3 +1,4 @@
+cache: cargo
 dist: trusty
 dist: trusty
 language: rust
 language: rust
 services: docker
 services: docker
@@ -45,14 +46,16 @@ install:
 script:
 script:
   - cargo generate-lockfile
   - cargo generate-lockfile
   - if [[ $TRAVIS_OS_NAME = "linux" ]]; then
   - if [[ $TRAVIS_OS_NAME = "linux" ]]; then
-      sudo apt-get remove -y qemu-user-static &&
-      sudo apt-get install -y qemu-user-static &&
       sh ci/run-docker.sh $TARGET;
       sh ci/run-docker.sh $TARGET;
     else
     else
       cargo test --target $TARGET &&
       cargo test --target $TARGET &&
       cargo test --target $TARGET --release;
       cargo test --target $TARGET --release;
     fi
     fi
 
 
+after_success:
+  # Travis can't cache files that are not readable by "others"
+  - chmod -R a+r /home/travis/.cargo
+
 branches:
 branches:
   only:
   only:
     - auto
     - auto

+ 0 - 1
ci/docker/aarch64-unknown-linux-gnu/Dockerfile

@@ -5,6 +5,5 @@ RUN apt-get install -y --no-install-recommends \
   gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
   gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
   qemu-user-static
   qemu-user-static
 ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
 ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
     QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/arm-unknown-linux-gnueabi/Dockerfile

@@ -4,7 +4,6 @@ RUN apt-get install -y --no-install-recommends \
   gcc libc6-dev ca-certificates \
   gcc libc6-dev ca-certificates \
   gcc-arm-linux-gnueabi libc6-dev-armel-cross qemu-user-static
   gcc-arm-linux-gnueabi libc6-dev-armel-cross qemu-user-static
 ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc \
 ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabi \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabi \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1
 
 

+ 0 - 1
ci/docker/arm-unknown-linux-gnueabihf/Dockerfile

@@ -4,6 +4,5 @@ RUN apt-get install -y --no-install-recommends \
   gcc libc6-dev ca-certificates \
   gcc libc6-dev ca-certificates \
   gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
   gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
 ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
 ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile

@@ -4,6 +4,5 @@ RUN apt-get install -y --no-install-recommends \
   gcc libc6-dev ca-certificates \
   gcc libc6-dev ca-certificates \
   gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
   gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
 ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
 ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
     QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/i586-unknown-linux-gnu/Dockerfile

@@ -2,4 +2,3 @@ FROM ubuntu:16.04
 RUN apt-get update
 RUN apt-get update
 RUN apt-get install -y --no-install-recommends \
 RUN apt-get install -y --no-install-recommends \
   gcc-multilib libc6-dev ca-certificates
   gcc-multilib libc6-dev ca-certificates
-ENV PATH=$PATH:/rust/bin

+ 0 - 1
ci/docker/i686-unknown-linux-gnu/Dockerfile

@@ -2,4 +2,3 @@ FROM ubuntu:16.04
 RUN apt-get update
 RUN apt-get update
 RUN apt-get install -y --no-install-recommends \
 RUN apt-get install -y --no-install-recommends \
   gcc-multilib libc6-dev ca-certificates
   gcc-multilib libc6-dev ca-certificates
-ENV PATH=$PATH:/rust/bin

+ 0 - 1
ci/docker/mips-unknown-linux-gnu/Dockerfile

@@ -7,6 +7,5 @@ RUN apt-get install -y --no-install-recommends \
         binfmt-support qemu-user-static qemu-system-mips
         binfmt-support qemu-user-static qemu-system-mips
 
 
 ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \
 ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/mips-linux-gnu \
     QEMU_LD_PREFIX=/usr/mips-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/mipsel-unknown-linux-gnu/Dockerfile

@@ -7,6 +7,5 @@ RUN apt-get install -y --no-install-recommends \
         binfmt-support qemu-user-static
         binfmt-support qemu-user-static
 
 
 ENV CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_GNU_LINKER=mipsel-linux-gnu-gcc \
 ENV CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_GNU_LINKER=mipsel-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/mipsel-linux-gnu \
     QEMU_LD_PREFIX=/usr/mipsel-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/powerpc-unknown-linux-gnu/Dockerfile

@@ -7,6 +7,5 @@ RUN apt-get install -y --no-install-recommends \
         qemu-system-ppc
         qemu-system-ppc
 
 
 ENV CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_LINKER=powerpc-linux-gnu-gcc \
 ENV CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_LINKER=powerpc-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/powerpc-linux-gnu \
     QEMU_LD_PREFIX=/usr/powerpc-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/powerpc64-unknown-linux-gnu/Dockerfile

@@ -8,6 +8,5 @@ RUN apt-get install -y --no-install-recommends \
 
 
 ENV CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_LINKER=powerpc64-linux-gnu-gcc \
 ENV CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_LINKER=powerpc64-linux-gnu-gcc \
     CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc \
     CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/powerpc64-linux-gnu \
     QEMU_LD_PREFIX=/usr/powerpc64-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 2
ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile

@@ -7,7 +7,5 @@ RUN apt-get install -y --no-install-recommends \
         qemu-system-ppc
         qemu-system-ppc
 
 
 ENV CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_LINKER=powerpc64le-linux-gnu-gcc \
 ENV CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_LINKER=powerpc64le-linux-gnu-gcc \
-    CC_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-gcc \
-    PATH=$PATH:/rust/bin \
     QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu \
     QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu \
     RUST_TEST_THREADS=1
     RUST_TEST_THREADS=1

+ 0 - 1
ci/docker/thumbv6m-none-eabi/Dockerfile

@@ -5,4 +5,3 @@ RUN apt-get install -y --no-install-recommends \
 ENV AR_thumbv6m_none_eabi=arm-none-eabi-ar \
 ENV AR_thumbv6m_none_eabi=arm-none-eabi-ar \
     CARGO_TARGET_THUMBV6M_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CARGO_TARGET_THUMBV6M_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CC_thumbv6m_none_eabi=arm-none-eabi-gcc \
     CC_thumbv6m_none_eabi=arm-none-eabi-gcc \
-    PATH=$PATH:/rust/bin

+ 0 - 1
ci/docker/thumbv7em-none-eabi/Dockerfile

@@ -5,4 +5,3 @@ RUN apt-get install -y --no-install-recommends \
 ENV AR_thumbv7em_none_eabi=arm-none-eabi-ar \
 ENV AR_thumbv7em_none_eabi=arm-none-eabi-ar \
     CARGO_TARGET_THUMBV7EM_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CARGO_TARGET_THUMBV7EM_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CC_thumbv7em_none_eabi=arm-none-eabi-gcc \
     CC_thumbv7em_none_eabi=arm-none-eabi-gcc \
-    PATH=$PATH:/rust/bin

+ 0 - 1
ci/docker/thumbv7em-none-eabihf/Dockerfile

@@ -5,4 +5,3 @@ RUN apt-get install -y --no-install-recommends \
 ENV AR_thumbv7em_none_eabihf=arm-none-eabi-ar \
 ENV AR_thumbv7em_none_eabihf=arm-none-eabi-ar \
     CARGO_TARGET_THUMBV7EM_NONE_EABIHF_LINKER=arm-none-eabi-gcc \
     CARGO_TARGET_THUMBV7EM_NONE_EABIHF_LINKER=arm-none-eabi-gcc \
     CC_thumbv7em_none_eabihf=arm-none-eabi-gcc \
     CC_thumbv7em_none_eabihf=arm-none-eabi-gcc \
-    PATH=$PATH:/rust/bin

+ 0 - 1
ci/docker/thumbv7m-none-eabi/Dockerfile

@@ -5,4 +5,3 @@ RUN apt-get install -y --no-install-recommends \
 ENV AR_thumbv7m_none_eabi=arm-none-eabi-ar \
 ENV AR_thumbv7m_none_eabi=arm-none-eabi-ar \
     CARGO_TARGET_THUMBV7M_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CARGO_TARGET_THUMBV7M_NONE_EABI_LINKER=arm-none-eabi-gcc \
     CC_thumbv7m_none_eabi=arm-none-eabi-gcc \
     CC_thumbv7m_none_eabi=arm-none-eabi-gcc \
-    PATH=$PATH:/rust/bin

+ 0 - 2
ci/docker/x86_64-unknown-linux-gnu/Dockerfile

@@ -2,5 +2,3 @@ FROM ubuntu:16.04
 RUN apt-get update
 RUN apt-get update
 RUN apt-get install -y --no-install-recommends \
 RUN apt-get install -y --no-install-recommends \
   gcc libc6-dev ca-certificates
   gcc libc6-dev ca-certificates
-ENV PATH=$PATH:/rust/bin
-

+ 23 - 9
ci/run-docker.sh

@@ -4,16 +4,30 @@
 set -ex
 set -ex
 
 
 run() {
 run() {
-    echo $1
-    docker build -t $1 ci/docker/$1
+    local gid=$(id -g) \
+          group=$(id -g -n) \
+          target=$1 \
+          uid=$(id -u) \
+          user=$(id -u -n)
+
+    echo $target
+    docker build -t $target ci/docker/$target
     docker run \
     docker run \
-      -v `rustc --print sysroot`:/rust:ro \
-      -v `pwd`:/checkout:ro \
-      -e CARGO_TARGET_DIR=/tmp/target \
-      -w /checkout \
-      --privileged \
-      -it $1 \
-      sh ci/run.sh $1
+           --rm \
+           -e CARGO_HOME=/cargo \
+           -e CARGO_TARGET_DIR=/target \
+           -v $HOME/.cargo:/cargo \
+           -v `pwd`/target:/target \
+           -v `pwd`:/checkout:ro \
+           -v `rustc --print sysroot`:/rust:ro \
+           -w /checkout \
+           -it $target \
+           sh -c "
+groupadd -g $gid $group
+useradd -m -g $gid -u $uid $user
+chown $user /cargo /target
+su -c 'PATH=\$PATH:/rust/bin ci/run.sh $target' $user
+"
 }
 }
 
 
 if [ -z "$1" ]; then
 if [ -z "$1" ]; then

+ 2 - 3
ci/run.sh

@@ -44,10 +44,9 @@ esac
 
 
 case $TRAVIS_OS_NAME in
 case $TRAVIS_OS_NAME in
     osx)
     osx)
-        NM=gnm
-
         # NOTE OSx's nm doesn't accept the `--defined-only` or provide an equivalent.
         # NOTE OSx's nm doesn't accept the `--defined-only` or provide an equivalent.
         # Use GNU nm instead
         # Use GNU nm instead
+        NM=gnm
         brew install binutils
         brew install binutils
         ;;
         ;;
     *)
     *)
@@ -56,7 +55,7 @@ case $TRAVIS_OS_NAME in
 esac
 esac
 
 
 # NOTE On i586, It's normal that the get_pc_thunk symbol appears several times so ignore it
 # NOTE On i586, It's normal that the get_pc_thunk symbol appears several times so ignore it
-$PREFIX$NM -g --defined-only /tmp/target/${1}/debug/librustc_builtins.rlib | \
+$PREFIX$NM -g --defined-only /target/${1}/debug/librustc_builtins.rlib | \
     sort | uniq -d | grep -v __x86.get_pc_thunk | grep 'T __'
     sort | uniq -d | grep -v __x86.get_pc_thunk | grep 'T __'
 
 
 if test $? = 0; then
 if test $? = 0; then