travis_linux_steps.sh 5.02 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

14
# Get our own location on this filesystem
15
MULTIBUILD_DIR=$(dirname "${BASH_SOURCE[0]}")
16

17
18
19
# Allow travis Python version as proxy for multibuild Python version
MB_PYTHON_VERSION=${MB_PYTHON_VERSION:-$TRAVIS_PYTHON_VERSION}

20
function before_install {
21
    # Install a virtualenv to work in.
mattip's avatar
mattip committed
22
    virtualenv --python=$PYTHON_EXE venv
23
24
25
26
27
    source venv/bin/activate
    python --version # just to check
    pip install --upgrade pip wheel
}

28
29
function build_wheel {
    # Builds wheel, puts into $WHEEL_SDIR
30
    #
31
32
    # In fact wraps the actual work which happens in the container.
    #
33
    # Depends on
34
35
    #     REPO_DIR  (or via input argument)
    #     PLAT (can be passed in as argument)
36
    #     MB_PYTHON_VERSION
37
    #     BUILD_COMMIT
38
39
40
41
42
43
    #     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
44
    local plat=${2:-${PLAT:-x86_64}}
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    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
62
    local plat=${2:-${PLAT:-x86_64}}
63
64
65
66
67
68
69
70
    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
71
    #     MB_ML_VER
John Jones's avatar
John Jones committed
72
    #     MB_ML_LIBC (optional)
73
74
    #     UNICODE_WIDTH (optional)
    #     BUILD_DEPENDS (optional)
Matthew Brett's avatar
Matthew Brett committed
75
    #     DOCKER_IMAGE (optional)
76
77
78
79
80
    #     MANYLINUX_URL (optional)
    #     WHEEL_SDIR (optional)
    local plat=$1
    [ -z "$plat" ] && echo "plat not defined" && exit 1
    local build_cmds="$2"
John Jones's avatar
John Jones committed
81
82
    local libc=${MB_ML_LIBC:-manylinux}
    local docker_image=${DOCKER_IMAGE:-quay.io/pypa/${libc}${MB_ML_VER}_\$plat}
xoviat's avatar
xoviat committed
83
    docker_image=$(eval echo "$docker_image")
84
    retry docker pull $docker_image
85
    docker run --rm \
86
        -e BUILD_COMMANDS="$build_cmds" \
87
        -e PYTHON_VERSION="$MB_PYTHON_VERSION" \
88
        -e MB_PYTHON_VERSION="$MB_PYTHON_VERSION" \
89
        -e UNICODE_WIDTH="$UNICODE_WIDTH" \
90
        -e BUILD_COMMIT="$BUILD_COMMIT" \
91
        -e CONFIG_PATH="$CONFIG_PATH" \
92
        -e ENV_VARS_PATH="$ENV_VARS_PATH" \
93
        -e WHEEL_SDIR="$WHEEL_SDIR" \
94
        -e MANYLINUX_URL="$MANYLINUX_URL" \
95
        -e BUILD_DEPENDS="$BUILD_DEPENDS" \
xoviat's avatar
xoviat committed
96
        -e USE_CCACHE="$USE_CCACHE" \
97
        -e REPO_DIR="$repo_dir" \
98
        -e PLAT="$PLAT" \
Matthew Brett's avatar
Matthew Brett committed
99
        -e MB_ML_VER="$MB_ML_VER" \
John Jones's avatar
John Jones committed
100
        -e MB_ML_LIBC="$libc" \
101
        -v $PWD:/io \
xoviat's avatar
xoviat committed
102
        -v $HOME:/parent-home \
103
        $docker_image /io/$MULTIBUILD_DIR/docker_build_wrap.sh
104
}
105
106

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