#!/bin/bash
#
# This is the jenkins build script for building/testing Numba.
#
# Jenkins Requirements:
#   - Anaconda should be installed in ~/anaconda
#   - Use a jenkins build matrix for multiple
#     platforms/python versions
#   - Use the XShell plugin to launch this script
#   - Call the script from the root workspace
#     directory as ./.jenkins
#

# Require a version of Python to be selected
if [ "${PYTHON_VERSION}" == "" ]; then
 echo You must select a Python version with the PYTHON_VERSION variable.
 exit 1
fi

# Use conda to create a conda environment of the required
# python version and containing the dependencies.
export PYENV_PREFIX=${WORKSPACE}/build/pyenv
rm -rf ${PYENV_PREFIX}
~/anaconda/bin/conda create --yes -p ${PYENV_PREFIX} python=${PYTHON_VERSION} cython scipy llvmpy cffi distribute nose || exit 1
export PATH=${PYENV_PREFIX}/bin:${PATH}

if [ -f "${PYENV_PREFIX}/bin/python" ]; then
 export PYTHON_EXECUTABLE=${PYENV_PREFIX}/bin/python
elif [ -f "${PYENV_PREFIX}/bin/python3" ]; then
 export PYTHON_EXECUTABLE=${PYENV_PREFIX}/bin/python3
else
 echo Conda environment creation failed.
 exit 1
fi

# Build/install Numba
pip install -r requirements.txt --use-mirrors
${PYTHON_EXECUTABLE} setup.py install || exit 1

# Run the tests
pushd ..
${PYTHON_EXECUTABLE} -c 'import sys, numba;sys.exit(0 if numba.test([]) == 0 else 1)' || exit 1
popd
