|
| 1 | +#!/bin/bash |
| 2 | + |
1 | 3 | # Small script to run tests for a target (or all targets) inside all the
|
2 | 4 | # respective docker images.
|
3 | 5 |
|
4 |
| -set -ex |
| 6 | +set -eux |
5 | 7 |
|
6 | 8 | run() {
|
7 |
| - local target=$1 |
| 9 | + local target="$1" |
8 | 10 |
|
9 |
| - echo $target |
| 11 | + echo "TESTING TARGET: $target" |
10 | 12 |
|
11 | 13 | # This directory needs to exist before calling docker, otherwise docker will create it but it
|
12 | 14 | # will be owned by root
|
13 | 15 | mkdir -p target
|
14 | 16 |
|
15 |
| - docker build -t $target ci/docker/$target |
| 17 | + if [ $(uname -s) = "Linux" ] && [ -z "${DOCKER_BASE_IMAGE:-}" ]; then |
| 18 | + # Share the host rustc and target. Do this only on Linux and if the image |
| 19 | + # isn't overridden |
| 20 | + run_args=( |
| 21 | + --user "$(id -u):$(id -g)" |
| 22 | + -e "CARGO_HOME=/cargo" |
| 23 | + -v "${HOME}/.cargo:/cargo" |
| 24 | + -v "$(pwd)/target:/builtins-target" |
| 25 | + -v "$(rustc --print sysroot):/rust:ro" |
| 26 | + ) |
| 27 | + run_cmd="HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh $target" |
| 28 | + else |
| 29 | + # Use rustc provided by a docker image |
| 30 | + docker volume create compiler-builtins-cache |
| 31 | + build_args=( |
| 32 | + "--build-arg" "IMAGE=${DOCKER_BASE_IMAGE:-rustlang/rust:nightly}" |
| 33 | + ) |
| 34 | + run_args=( |
| 35 | + -v "compiler-builtins-cache:/builtins-target" |
| 36 | + ) |
| 37 | + run_cmd="HOME=/tmp USING_CONTAINER_RUSTC=1 ci/run.sh $target" |
| 38 | + fi |
| 39 | + |
| 40 | + if [ -d compiler-rt ]; then |
| 41 | + export RUST_COMPILER_RT_ROOT=./compiler-rt |
| 42 | + fi |
| 43 | + |
| 44 | + docker build \ |
| 45 | + -t "builtins-$target" \ |
| 46 | + ${build_args[@]:-} \ |
| 47 | + "ci/docker/$target" |
16 | 48 | docker run \
|
17 | 49 | --rm \
|
18 |
| - --user $(id -u):$(id -g) \ |
19 |
| - -e CARGO_HOME=/cargo \ |
20 |
| - -e CARGO_TARGET_DIR=/target \ |
21 | 50 | -e RUST_COMPILER_RT_ROOT \
|
22 |
| - -v "${HOME}/.cargo":/cargo \ |
23 |
| - -v `pwd`/target:/target \ |
24 |
| - -v `pwd`:/checkout:ro \ |
25 |
| - -v `rustc --print sysroot`:/rust:ro \ |
| 51 | + -e "CARGO_TARGET_DIR=/builtins-target" \ |
| 52 | + -v "$(pwd):/checkout:ro" \ |
26 | 53 | -w /checkout \
|
| 54 | + ${run_args[@]:-} \ |
27 | 55 | --init \
|
28 |
| - $target \ |
29 |
| - sh -c "HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh $target" |
| 56 | + "builtins-$target" \ |
| 57 | + sh -c "$run_cmd" |
30 | 58 | }
|
31 | 59 |
|
32 |
| -if [ -z "$1" ]; then |
33 |
| - for d in `ls ci/docker/`; do |
34 |
| - run $d |
| 60 | +if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then |
| 61 | + set +x |
| 62 | + echo "\ |
| 63 | + usage: ./ci/run-docker.sh [target] |
| 64 | +
|
| 65 | + you can also set DOCKER_BASE_IMAGE to use something other than the default |
| 66 | + ubuntu:18.04 (or rustlang/rust:nightly). |
| 67 | + " |
| 68 | + exit |
| 69 | +fi |
| 70 | + |
| 71 | +if [ -z "${1:-}" ]; then |
| 72 | + for d in ci/docker/*; do |
| 73 | + run $(basename "$d") |
35 | 74 | done
|
36 | 75 | else
|
37 |
| - run $1 |
| 76 | + run "$1" |
38 | 77 | fi
|
0 commit comments