travis_linux_steps.sh 5.18 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.
Matthew Brett's avatar
Matthew Brett committed
22
23
    # Virtualenv package may not be installed on host Python.
    python -m pip install virtualenv
mattip's avatar
mattip committed
24
    virtualenv --python=$PYTHON_EXE venv
25
26
    source venv/bin/activate
    python --version # just to check
Matthew Brett's avatar
Matthew Brett committed
27
28
    # Tomli for pyproject.toml parsing, to get dependencies.
    pip install --upgrade pip wheel tomli
29
30
}

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

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