Debian Codegraph @

tools/ci-run.sh

raw
1 #!/usr/bin/bash
2
3 set -x
4
5 GCC_VERSION=${GCC_VERSION:=9}
6 TEST_CFLAGS=
7 EXTRA_CFLAGS=
8 EXTRA_LDFLAGS=
9 SAVED_GITHUB_API_TOKEN="${GITHUB_API_TOKEN}"
10 unset GITHUB_API_TOKEN # remove from env
11
12 # Set up compilers
13 if [ -z "${OS_NAME##ubuntu*}" ]; then
14 echo "Installing requirements [apt]"
15 sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
16 sudo apt-get update -y -q
17 sudo apt-get install -y -q ccache gcc-$GCC_VERSION || exit 1
18 if [ -n "${STATIC_DEPS##true}" ]; then
19 # Ubuntu 22.04 has libxml2 2.9.13, Ubuntu 24.04 has 2.9.14
20 sudo apt-get install -y -q "libxml2=2.9.14*" "libxml2-dev=2.9.14*" libxslt1.1 libxslt1-dev \
21 || sudo apt-get install -y -q "libxml2=2.9.13*" "libxml2-dev=2.9.13*" libxslt1.1 libxslt1-dev
22 fi
23 sudo /usr/sbin/update-ccache-symlinks
24 echo "/usr/lib/ccache" >> $GITHUB_PATH # export ccache to path
25
26 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 60
27
28 export CC="gcc"
29 if [ -z "${PYTHON_VERSION##2*}" ] || [ -z "${PYTHON_VERSION##pypy-2*}" ]; then
30 # Make sure we use the same linker and C compiler.
31 export LDSHARED="$CC -shared"
32 fi
33 export PATH="/usr/lib/ccache:$PATH"
34 TEST_CFLAGS="-Og -g -fPIC"
35 EXTRA_CFLAGS="-Wall -Wextra"
36
37 elif [ -z "${OS_NAME##macos*}" ]; then
38 export CC="clang -Wno-deprecated-declarations"
39 TEST_CFLAGS="-Og -g -fPIC -arch arm64 -arch x86_64"
40 EXTRA_LDFLAGS="-arch arm64 -arch x86_64"
41 EXTRA_CFLAGS="-Wall -Wextra -arch arm64 -arch x86_64"
42
43 if [[ $PYTHON_VERSION == "3."[78]* ]]; then
44 # Py3.7/8 require the same target version as originally used for CPython itself.
45 export MACOSX_DEPLOYMENT_TARGET="11.7"
46 fi
47
48 if [[ $PYTHON_VERSION == "2.7"* ]]; then
49 # make sure we find Python 2.7 before Python 3.x
50 export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
51 fi
52 fi
53
54 # Log versions in use
55 echo "===================="
56 echo "|VERSIONS INSTALLED|"
57 echo "===================="
58 python -c 'import sys; print("Python %s" % (sys.version,))'
59 if [[ "$CC" ]]; then
60 which ${CC%% *}
61 ${CC%% *} --version
62 fi
63 if [ -z "${OS_NAME##win*}" ]; then
64 pkg-config --modversion libxml-2.0 libxslt
65 fi
66 echo "===================="
67
68 ccache -s || true
69
70 # Install python requirements
71 echo "Installing requirements [python]"
72 if [ -z "${PYTHON_VERSION##2*}" ] || [ -z "${PYTHON_VERSION##pypy-2*}" ];
73 then python -m pip install -U "pip<21" "setuptools<45" "wheel<38";
74 else python -m pip install -U pip setuptools wheel;
75 fi
76 if [ -z "${PYTHON_VERSION##*-dev}" ];
77 then CYTHON_COMPILE=false python -m pip install https://github.com/cython/cython/archive/master.zip;
78 else python -m pip install -r requirements.txt;
79 fi
80 if [ -z "${PYTHON_VERSION##2*}" ] || [ -z "${PYTHON_VERSION##pypy-2*}" ]; then
81 python -m pip install -U beautifulsoup4==4.9.3 cssselect==1.1.0 html5lib==1.1 rnc2rng==2.6.5 ${EXTRA_DEPS} || exit 1
82 else
83 python -m pip install -U beautifulsoup4 cssselect html5lib rnc2rng ${EXTRA_DEPS} || exit 1
84 python -m pip install --no-deps lxml_html_clean || exit 1
85 fi
86 if [[ "$COVERAGE" == "true" ]]; then
87 python -m pip install "coverage<5" || exit 1
88 fi
89
90 # Build
91 GITHUB_API_TOKEN="${SAVED_GITHUB_API_TOKEN}" \
92 CFLAGS="$CFLAGS $TEST_CFLAGS $EXTRA_CFLAGS" \
93 LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS" \
94 python -u setup.py build_ext --inplace --warnings -j4 \
95 $(if [[ "$COVERAGE" == "true" ]]; then echo -n " --with-coverage"; fi ) \
96 || exit 1
97
98 # Run tests
99 echo "Running the tests ..."
100 GITHUB_API_TOKEN="${SAVED_GITHUB_API_TOKEN}" \
101 CFLAGS="$TEST_CFLAGS $EXTRA_CFLAGS" \
102 LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS" \
103 PYTHONUNBUFFERED=x \
104 make test || exit 1
105
106 ccache -s || true