manylinux_utils.sh 2.74 KB
Newer Older
1
#!/bin/bash
2
3
4
5
# Useful utilities common across manylinux1 builds

MULTIBUILD_DIR=$(dirname "${BASH_SOURCE[0]}")
source $MULTIBUILD_DIR/common_utils.sh
6

7
8
# UNICODE_WIDTH selects "32"=wide (UCS4) or "16"=narrow (UCS2/UTF16) builds
UNICODE_WIDTH="${UNICODE_WIDTH:-32}"
9

Matthew Brett's avatar
Matthew Brett committed
10
11
12
13
14
function get_platform {
    # Report platform as given by uname
    python -c 'import platform; print(platform.uname()[4])'
}

15
16
17
18
19
20
21
function cpython_path {
    # Return path to cpython given
    # * version (of form "2.7")
    # * u_width ("16" or "32" default "32")
    #
    # For back-compatibility "u" as u_width also means "32"
    local py_ver="${1:-2.7}"
mattip's avatar
mattip committed
22
    local abi_suff=m
23
24
    local u_width="${2:-${UNICODE_WIDTH}}"
    local u_suff=u
mattip's avatar
mattip committed
25
26
27
28
29
    # Python 3.8 and up no longer uses the PYMALLOC 'm' suffix
    # https://github.com/pypa/wheel/pull/303
    if [ $(lex_ver $py_ver) -ge $(lex_ver 3.8) ]; then
        abi_suff=""
    fi
30
31
    # Back-compatibility
    if [ "$u_width" == "u" ]; then u_width=32; fi
Hugo's avatar
Hugo committed
32
33
    # For Python >= 3.4, "u" suffix not meaningful
    if [ $(lex_ver $py_ver) -ge $(lex_ver 3.4) ] ||
34
35
36
37
38
39
        [ "$u_width" == "16" ]; then
        u_suff=""
    elif [ "$u_width" != "32" ]; then
        echo "Incorrect u_width value $u_width"
        exit 1
    fi
40
    local no_dots=$(echo $py_ver | tr -d .)
mattip's avatar
mattip committed
41
    echo "/opt/python/cp${no_dots}-cp${no_dots}$abi_suff${u_suff}"
42
43
44
45
}

function repair_wheelhouse {
    local in_dir=$1
46
    local out_dir=${2:-$in_dir}
47
    for whl in $in_dir/*.whl; do
48
49
        if [[ $whl == *none-any.whl ]]; then  # Pure Python wheel
            if [ "$in_dir" != "$out_dir" ]; then cp $whl $out_dir; fi
50
51
        else
            auditwheel repair $whl -w $out_dir/
52
53
            # Remove unfixed if writing into same directory
            if [ "$in_dir" == "$out_dir" ]; then rm $whl; fi
54
55
56
57
        fi
    done
    chmod -R a+rwX $out_dir
}
xoviat's avatar
xoviat committed
58
59
60

function activate_ccache {
    # Link up the correct location for ccache
xoviat's avatar
xoviat committed
61
    mkdir -p /parent-home/.ccache
xoviat's avatar
xoviat committed
62
63
64
    ln -s /parent-home/.ccache $HOME/.ccache

    # Now install ccache
65
    suppress yum_install ccache
xoviat's avatar
xoviat committed
66
67
68
69
70
71

    # Create fake compilers and prepend them to the PATH
    # Note that yum is supposed to create these for us,
    # but I had trouble finding them
    local ccache_dir=/usr/lib/ccache/compilers
    mkdir -p $ccache_dir
xoviat's avatar
xoviat committed
72
73
74
75
76
    ln -s /usr/bin/ccache $ccache_dir/gcc
    ln -s /usr/bin/ccache $ccache_dir/g++
    ln -s /usr/bin/ccache $ccache_dir/cc
    ln -s /usr/bin/ccache $ccache_dir/c++
    export PATH=$ccache_dir:$PATH
xoviat's avatar
xoviat committed
77
78

    # Prove to the developer that ccache is activated
xoviat's avatar
xoviat committed
79
    echo "Using C compiler: $(which gcc)"
xoviat's avatar
xoviat committed
80
}
81
82
83
84
85
function yum_install {
    # CentOS 5 yum doesn't fail in some cases, e.g. if package is not found
    # https://serverfault.com/questions/694942/yum-should-error-when-a-package-is-not-available
    yum install -y "$1" && rpm -q "$1"
}