travis_linux_steps.sh 4.7 KB
Newer Older
1
#!/bin/bash
2
# Wheel build, install, run test steps on Linux
3
4
5
#
# In fact the main work is to wrap up the real functions in docker commands.
# The real work is in the BUILD_SCRIPT (which builds the wheel) and
6
# `docker_install_run.sh`, which can be configured with `config.sh`.
7
8
9
10
11
#
# Must define
#  before_install
#  build_wheel
#  install_run
12
set -e
13

Matthew Brett's avatar
Matthew Brett committed
14
MANYLINUX_URL=${MANYLINUX_URL:-https://5cf40426d9f06eb7461d-6fe47d9331aba7cd62fc36c7196769e4.ssl.cf2.rackcdn.com}
15

Matthew Brett's avatar
Matthew Brett committed
16
17
18
19
20
# Default Manylinux version
# Warning: ignored if DOCKER_IMAGE variable is set.
# See build_multilinux function.
MB_ML_VER=${MB_ML_VER:-1}

21
# Get our own location on this filesystem
22
MULTIBUILD_DIR=$(dirname "${BASH_SOURCE[0]}")
23

24
25
26
# Allow travis Python version as proxy for multibuild Python version
MB_PYTHON_VERSION=${MB_PYTHON_VERSION:-$TRAVIS_PYTHON_VERSION}

27
function before_install {
28
    # Install a virtualenv to work in.
29
30
31
32
33
34
    virtualenv --python=python venv
    source venv/bin/activate
    python --version # just to check
    pip install --upgrade pip wheel
}

35
36
function build_wheel {
    # Builds wheel, puts into $WHEEL_SDIR
37
    #
38
39
    # In fact wraps the actual work which happens in the container.
    #
40
    # Depends on
41
42
    #     REPO_DIR  (or via input argument)
    #     PLAT (can be passed in as argument)
43
    #     MB_PYTHON_VERSION
44
    #     BUILD_COMMIT
45
46
47
48
49
50
    #     UNICODE_WIDTH (optional)
    #     BUILD_DEPENDS (optional)
    #     MANYLINUX_URL (optional)
    #     WHEEL_SDIR (optional)
    local repo_dir=${1:-$REPO_DIR}
    [ -z "$repo_dir" ] && echo "repo_dir not defined" && exit 1
Matthew Brett's avatar
Matthew Brett committed
51
    local plat=${2:-${PLAT:-x86_64}}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    build_multilinux $plat "build_wheel $repo_dir"
}

function build_index_wheel {
    # Builds wheel from an index (e.g pypi), puts into $WHEEL_SDIR
    #
    # In fact wraps the actual work which happens in the container.
    #
    # Depends on
    #     PLAT (can be passed in as argument)
    #     MB_PYTHON_VERSION
    #     UNICODE_WIDTH (optional)
    #     BUILD_DEPENDS (optional)
    #     MANYLINUX_URL (optional)
    #     WHEEL_SDIR (optional)
    local project_spec=$1
    [ -z "$project_spec" ] && echo "project_spec not defined" && exit 1
Matthew Brett's avatar
Matthew Brett committed
69
    local plat=${2:-${PLAT:-x86_64}}
70
71
72
73
74
75
76
77
    build_multilinux $plat "build_index_wheel $project_spec"
}

function build_multilinux {
    # Runs passed build commands in manylinux container
    #
    # Depends on
    #     MB_PYTHON_VERSION
Matthew Brett's avatar
Matthew Brett committed
78
    #     MB_ML_VER
79
80
    #     UNICODE_WIDTH (optional)
    #     BUILD_DEPENDS (optional)
Matthew Brett's avatar
Matthew Brett committed
81
    #     DOCKER_IMAGE (optional)
82
83
84
85
86
    #     MANYLINUX_URL (optional)
    #     WHEEL_SDIR (optional)
    local plat=$1
    [ -z "$plat" ] && echo "plat not defined" && exit 1
    local build_cmds="$2"
Matthew Brett's avatar
Matthew Brett committed
87
    local docker_image=${DOCKER_IMAGE:-quay.io/pypa/manylinux${MB_ML_VER}_\$plat}
xoviat's avatar
xoviat committed
88
    docker_image=$(eval echo "$docker_image")
89
    retry docker pull $docker_image
90
    docker run --rm \
91
        -e BUILD_COMMANDS="$build_cmds" \
92
        -e PYTHON_VERSION="$MB_PYTHON_VERSION" \
93
        -e MB_PYTHON_VERSION="$MB_PYTHON_VERSION" \
94
        -e UNICODE_WIDTH="$UNICODE_WIDTH" \
95
        -e BUILD_COMMIT="$BUILD_COMMIT" \
96
        -e CONFIG_PATH="$CONFIG_PATH" \
97
        -e ENV_VARS_PATH="$ENV_VARS_PATH" \
98
        -e WHEEL_SDIR="$WHEEL_SDIR" \
99
        -e MANYLINUX_URL="$MANYLINUX_URL" \
100
        -e BUILD_DEPENDS="$BUILD_DEPENDS" \
xoviat's avatar
xoviat committed
101
        -e USE_CCACHE="$USE_CCACHE" \
102
        -e REPO_DIR="$repo_dir" \
103
        -e PLAT="$PLAT" \
Matthew Brett's avatar
Matthew Brett committed
104
        -e MB_ML_VER="$MB_ML_VER" \
105
        -v $PWD:/io \
xoviat's avatar
xoviat committed
106
        -v $HOME:/parent-home \
107
        $docker_image /io/$MULTIBUILD_DIR/docker_build_wrap.sh
108
}
109
110

function install_run {
111
112
113
114
115
116
    # Install wheel, run tests
    #
    # In fact wraps the actual work which happens in the container.
    #
    # Depends on
    #  PLAT (can be passed in as argument)
117
    #  MB_PYTHON_VERSION
118
119
120
121
    #  UNICODE_WIDTH (optional)
    #  WHEEL_SDIR (optional)
    #  MANYLINUX_URL (optional)
    #  TEST_DEPENDS  (optional)
mattip's avatar
mattip committed
122
    #  MB_TEST_VER (optional)
Matthew Brett's avatar
Matthew Brett committed
123
    local plat=${1:-${PLAT:-x86_64}}
124
125
126
127
    if [ -z "$DOCKER_TEST_IMAGE" ]; then
        local bitness=$([ "$plat" == i686 ] && echo 32 || echo 64)
        local docker_image="matthewbrett/trusty:$bitness"
    else
128
129
130
        # aarch64 is called arm64v8 in Ubuntu
        local plat_subst=$([ "$plat" == aarch64 ] && echo arm64v8 || echo $plat)
        local docker_image="${DOCKER_TEST_IMAGE/\{plat_subst\}/$plat_subst}"
131
    fi
132
133
    docker pull $docker_image
    docker run --rm \
134
        -e PYTHON_VERSION="$MB_PYTHON_VERSION" \
135
        -e MB_PYTHON_VERSION="$MB_PYTHON_VERSION" \
136
        -e UNICODE_WIDTH="$UNICODE_WIDTH" \
137
        -e CONFIG_PATH="$CONFIG_PATH" \
138
139
140
141
        -e WHEEL_SDIR="$WHEEL_SDIR" \
        -e MANYLINUX_URL="$MANYLINUX_URL" \
        -e TEST_DEPENDS="$TEST_DEPENDS" \
        -v $PWD:/io \
142
        $docker_image /io/$MULTIBUILD_DIR/docker_test_wrap.sh
143
}