Skip to content

Commit 72c18e7

Browse files
authored
Improve ci-run.sh (cythonGH-4398)
1 parent 454a498 commit 72c18e7

1 file changed

Lines changed: 66 additions & 23 deletions

File tree

Tools/ci-run.sh

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,36 @@
33
GCC_VERSION=${GCC_VERSION:=8}
44

55
# Set up compilers
6-
if [ "${OS_NAME##ubuntu*}" == "" -a "$TEST_CODE_STYLE" != "1" ]; then
6+
if [ "$TEST_CODE_STYLE" == "1" ]; then
7+
echo "Skipping compiler setup"
8+
elif [ "${OSTYPE##linux-gnu*}" == "" ]; then
9+
echo "Setting up linux compiler"
710
echo "Installing requirements [apt]"
811
sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
912
sudo apt update -y -q
1013
sudo apt install -y -q ccache gdb python-dbg python3-dbg gcc-$GCC_VERSION || exit 1
14+
15+
ALTERNATIVE_ARGS=""
1116
if [ -z "${BACKEND##*cpp*}" ]; then
1217
sudo apt install -y -q g++-$GCC_VERSION || exit 1
18+
ALTERNATIVE_ARGS="--slave /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION"
1319
fi
1420
sudo /usr/sbin/update-ccache-symlinks
1521
echo "/usr/lib/ccache" >> $GITHUB_PATH # export ccache to path
1622

17-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 60 $(if [ -z "${BACKEND##*cpp*}" ]; then echo " --slave /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION"; fi)
23+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 60 $ALTERNATIVE_ARGS
1824

1925
export CC="gcc"
2026
if [ -z "${BACKEND##*cpp*}" ]; then
2127
sudo update-alternatives --set g++ /usr/bin/g++-$GCC_VERSION
2228
export CXX="g++"
2329
fi
24-
fi
25-
if [ "${OS_NAME##macos*}" == "" ]; then
30+
elif [ "${OSTYPE##darwin*}" == "" ]; then
31+
echo "Setting up macos compiler"
2632
export CC="clang -Wno-deprecated-declarations"
2733
export CXX="clang++ -stdlib=libc++ -Wno-deprecated-declarations"
34+
else
35+
echo "No setup specified for $OSTYPE"
2836
fi
2937

3038
# Set up miniconda
@@ -35,11 +43,13 @@ if [ "$STACKLESS" == "true" ]; then
3543
conda install --quiet --yes stackless || exit 1
3644
fi
3745

46+
PYTHON_SYS_VERSION=$(python -c 'import sys; print(sys.version)')
47+
3848
# Log versions in use
3949
echo "===================="
4050
echo "|VERSIONS INSTALLED|"
4151
echo "===================="
42-
python -c 'import sys; print("Python %s" % (sys.version,))'
52+
echo "Python $PYTHON_SYS_VERSION"
4353
if [ "$CC" ]; then
4454
which ${CC%% *}
4555
${CC%% *} --version
@@ -61,7 +71,7 @@ elif [ -z "${PYTHON_VERSION##3.[45]*}" ]; then
6171
else
6272
python -m pip install -U pip setuptools wheel || exit 1
6373

64-
if [ -n "${PYTHON_VERSION##*-dev}" ]; then
74+
if [ -n "${PYTHON_VERSION##*-dev}" -o "$COVERAGE" == "1" ]; then
6575
python -m pip install -r test-requirements.txt || exit 1
6676

6777
if [ "${PYTHON_VERSION##pypy*}" -a "${PYTHON_VERSION##3.[4789]*}" ]; then
@@ -74,7 +84,7 @@ if [ "$TEST_CODE_STYLE" == "1" ]; then
7484
STYLE_ARGS="--no-unit --no-doctest --no-file --no-pyregr --no-examples";
7585
python -m pip install -r doc-requirements.txt || exit 1
7686
else
77-
STYLE_ARGS="--no-code-style";
87+
STYLE_ARGS="--no-code-style"
7888

7989
# Install more requirements
8090
if [ -n "${PYTHON_VERSION##*-dev}" ]; then
@@ -83,45 +93,78 @@ else
8393
# python -m pip install pythran==0.9.5 || exit 1
8494
fi
8595

86-
if [ "$BACKEND" != "cpp" -a -n "${PYTHON_VERSION##pypy*}" -a -n "${PYTHON_VERSION##2*}" -a -n "${PYTHON_VERSION##*3.4}" ]; then
96+
if [ "$BACKEND" != "cpp" -a -n "${PYTHON_VERSION##pypy*}" -a
97+
-n "${PYTHON_VERSION##2*}" -a -n "${PYTHON_VERSION##3.4*}" ]; then
8798
python -m pip install mypy || exit 1
8899
fi
89100
fi
90101
fi
91102

92103
# Run tests
104+
echo "==== Running tests ===="
93105
ccache -s 2>/dev/null || true
94106
export PATH="/usr/lib/ccache:$PATH"
95107

108+
# Most modern compilers allow the last conflicting option
109+
# to override the previous ones, so '-O0 -O3' == '-O3'
110+
# This is true for the latest msvc, gcc and clang
111+
CFLAGS="-O0 -ggdb -Wall -Wextra"
112+
96113
if [ "$NO_CYTHON_COMPILE" != "1" -a -n "${PYTHON_VERSION##pypy*}" ]; then
97-
CFLAGS="-O2 -ggdb -Wall -Wextra $(python -c 'import sys; print("-fno-strict-aliasing" if sys.version_info[0] == 2 else "")')" \
98-
python setup.py build_ext -i \
99-
$(if [ "$COVERAGE" == "1" ]; then echo " --cython-coverage"; fi) \
100-
$(if [ "$CYTHON_COMPILE_ALL" == "1" ]; then echo " --cython-compile-all"; fi) \
101-
$(python -c 'import sys; print("-j5" if sys.version_info >= (3,5) else "")') \
102-
|| exit 1
103-
if [ -z "$COVERAGE" -a -z "$STACKLESS" -a -z "$LIMITED_API" -a -z "$CYTHON_COMPILE_ALL" -a -z "$EXTRA_CFLAGS" -a -n "${BACKEND//*cpp*}" ]; then
114+
115+
BUILD_CFLAGS="$CFLAGS -O2"
116+
if [[ $PYTHON_SYS_VERSION == "2"* ]]; then
117+
BUILD_CFLAGS="$BUILD_CFLAGS -fno-strict-aliasing"
118+
fi
119+
120+
SETUP_ARGS=""
121+
if [ "$COVERAGE" == "1" ]; then
122+
SETUP_ARGS="$SETUP_ARGS --cython-coverage"
123+
fi
124+
if [ "$CYTHON_COMPILE_ALL" == "1" ]; then
125+
SETUP_ARGS="$SETUP_ARGS --cython-compile-all"
126+
fi
127+
SETUP_ARGS="$SETUP_ARGS
128+
$(python -c 'import sys; print("-j5" if sys.version_info >= (3,5) else "")')"
129+
130+
CFLAGS=$BUILD_CFLAGS \
131+
python setup.py build_ext -i $SETUP_ARGS || exit 1
132+
133+
if [ -z "$COVERAGE" -a -z "$STACKLESS" -a -n "${BACKEND//*cpp*}" -a
134+
-z "$LIMITED_API" -a -z "$CYTHON_COMPILE_ALL" -a -z "$EXTRA_CFLAGS" ]; then
104135
python setup.py bdist_wheel || exit 1
105136
fi
106137
fi
107138

108139
if [ "$TEST_CODE_STYLE" == "1" ]; then
109140
make -C docs html || exit 1
110141
elif [ -n "${PYTHON_VERSION##pypy*}" ]; then
111-
# Run the debugger tests in python-dbg if available (but don't fail, because they currently do fail)
112-
PYTHON_DBG="python$( python -c 'import sys; print("%d.%d" % sys.version_info[:2])' )-dbg"
113-
if $PYTHON_DBG -V >&2; then CFLAGS="-O0 -ggdb" $PYTHON_DBG runtests.py -vv --no-code-style Debugger --backends=$BACKEND; fi;
142+
# Run the debugger tests in python-dbg if available
143+
# (but don't fail, because they currently do fail)
144+
PYTHON_DBG=$(python -c 'import sys; print("%d.%d" % sys.version_info[:2])')
145+
PYTHON_DBG="python$PYTHON_DBG-dbg"
146+
if $PYTHON_DBG -V >&2; then
147+
CFLAGS=$CFLAGS $PYTHON_DBG \
148+
runtests.py -vv --no-code-style Debugger --backends=$BACKEND
149+
fi
150+
fi
151+
152+
RUNTESTS_ARGS=""
153+
if [ "$COVERAGE" == "1" ]; then
154+
RUNTESTS_ARGS="$RUNTESTS_ARGS --coverage --coverage-html --cython-only"
155+
fi
156+
if [ -z "$TEST_CODE_STYLE" ]; then
157+
RUNTESTS_ARGS="$RUNTESTS_ARGS -j7"
114158
fi
115159

116-
export CFLAGS="-O0 -ggdb -Wall -Wextra $EXTRA_CFLAGS"
160+
export CFLAGS="$CFLAGS $EXTRA_CFLAGS"
117161
python runtests.py \
118162
-vv $STYLE_ARGS \
119163
-x Debugger \
120164
--backends=$BACKEND \
121-
$LIMITED_API \
122-
$EXCLUDE \
123-
$(if [ "$COVERAGE" == "1" ]; then echo " --coverage --coverage-html --cython-only"; fi) \
124-
$(if [ -z "$TEST_CODE_STYLE" ]; then echo " -j7 "; fi)
165+
$LIMITED_API \
166+
$EXCLUDE \
167+
$RUNTESTS_ARGS
125168

126169
EXIT_CODE=$?
127170

0 commit comments

Comments
 (0)