From a024e872d2a11182d325ea02cc6f470c7f8b87f2 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Tue, 9 Jun 2020 08:12:00 -0400 Subject: [PATCH] travis-ci: Make sure python is set properly in the lib so the path is correctly set in all the scripts. provide a bash backtrace function, so we can add that for debugging. Signed-off-by: Robin Getz --- CI/travis/before_install_linux | 81 +++++++++++++++++++++++++-------- CI/travis/lib.sh | 47 +++++++++++++++++++ CI/travis/make_linux | 83 +++++++++++++++++++++++----------- bindings/python/CMakeLists.txt | 18 ++++++++ 4 files changed, 184 insertions(+), 45 deletions(-) diff --git a/CI/travis/before_install_linux b/CI/travis/before_install_linux index 2a0bc523f..f26a8aff1 100755 --- a/CI/travis/before_install_linux +++ b/CI/travis/before_install_linux @@ -3,16 +3,35 @@ . CI/travis/lib.sh install_sphinx() { - if [ "$(python -c 'import sys; print(".".join(map(str, sys.version_info[:1])))')" -eq "3" ] ; then - sudo pip3 install sphinx - sudo pip3 install sphinx-rtd-theme - else - sudo pip install sphinx - sudo pip install sphinx-rtd-theme + if command_exists python ; then + python --version + command -v python + python -m pip install -U pip + python -m pip install sphinx + python -m pip install sphinx-rtd-theme + fi +} + +install_pyenv() { + if ! command_exists pyenv ; then + echo installing pyenv + git clone git://github.com/yyuu/pyenv.git $HOME/.pyenv + export PATH="$HOME/.pyenv/bin:$PATH" + export PYENV_ROOT="$HOME/.pyenv" fi +} +install_python() { + echo "### installing python" + command -v pyenv + add_python_path + pyenv install --list | grep "^[[:space:]]*[0-9]" + pyenv install 3.6.3 + pyenv global 3.6.3 + add_python_path } + handle_centos() { # needed for man2html and a few other popular tools yum search epel-release @@ -24,25 +43,40 @@ handle_centos() { yum -y install cmake libxml2-devel libusb1-devel libaio-devel \ bzip2 gzip rpm rpm-build redhat-lsb-core - # CENTOS 6 doesn't include python 3, it's too old. - if is_centos_at_least_ver "7" ; then - yum -y install python3-pip + # needed for building python with pyenv + yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel + + # CentOS 6 & 7 don't work with doc, or the latest python. + # install_pyenv + # install_python + + if [ "$(get_version | head -c 1)" = "7" ] ; then + # install Cmake3, and make it the default + yum -y install cmake3 + alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \ + --slave /usr/local/bin/ctest ctest /usr/bin/ctest \ + --slave /usr/local/bin/cpack cpack /usr/bin/cpack \ + --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake \ + --family cmake + alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \ + --slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \ + --slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \ + --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \ + --family cmake fi if is_centos_at_least_ver "8" ; then # On CentOS 8, avahi-devel & doxygen are in this repo; enable it + yum -y install yum-utils yum config-manager --set-enabled PowerTools + # On CentOS 6 & 7, have issues building or packaging doc + yum -y install python3 doxygen man2html + install_sphinx else # On CentOS 8, cdk-devel (Curses Development Kit) does not exist yet yum -y install ncurses-devel cdk-devel fi - # CENTOS 6 will has issues with sphinx - if is_centos_at_least_ver "7" ; then - yum -y install doxygen man2html - install_sphinx - fi - yum -y install avahi-devel } @@ -56,13 +90,24 @@ handle_ubuntu_docker() { handle_default() { sudo apt-get -qq update + sudo apt-get install -y apt-utils sudo DEBIAN_FRONTEND=noninteractive apt-get install -y cmake graphviz \ libaio-dev libavahi-client-dev \ libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar \ - bzip2 gzip flex bison git lsb-release python3-pip libncurses5-dev libcdk5-dev + bzip2 gzip flex bison git lsb-release libncurses5-dev libcdk5-dev - sudo apt-get install -y doxygen man2html - install_sphinx + # Most of these should be here, but are needed for building python by pyenv + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \ + libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \ + wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev \ + libffi-dev liblzma-dev python-openssl git + + if ! is_arm ; then + install_pyenv + install_python + sudo apt-get install -y doxygen man2html + install_sphinx + fi if [ `sudo apt-cache search libserialport-dev | wc -l` -gt 0 ] ; then sudo apt-get install -y libserialport-dev diff --git a/CI/travis/lib.sh b/CI/travis/lib.sh index 939001458..881142acb 100644 --- a/CI/travis/lib.sh +++ b/CI/travis/lib.sh @@ -27,6 +27,48 @@ echo_red() { printf "\033[1;31m$*\033[m\n"; } echo_green() { printf "\033[1;32m$*\033[m\n"; } echo_blue() { printf "\033[1;34m$*\033[m\n"; } +backtrace() { + # shell backtraces only work on bash + if [ ! -z "${BASH}" ] ; then + local i= + i=${#FUNCNAME[@]} + ((--i)) + + while (( i >= 0 )) + do + echo "${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}.${FUNCNAME[$i]}()" + i=$((i - 1)) + done + fi +} + +add_python_path() { + echo "adding Python to the path" + if [ -d "$HOME/.pyenv/bin" -a "$(echo "$PATH" | grep .pyenv/bin | wc -c)" -eq "0" ] ; then + echo "adding $HOME/.pyenv/bin to path" + export PATH="$HOME/.pyenv/bin:$PATH" + fi + if [ -z "${PYENV_SHELL}" ] ; then + echo init pyenv + eval "$(pyenv init -)" + fi + if [ -d /opt/pyenv/versions/3.6.3/bin -a "$(echo "$PATH" | grep opt/pyenv/versions | wc -c)" -eq "0" ] ; then + echo adding python on opt to PATH + export PATH="/opt/pyenv/versions/3.6.3/bin:$PATH" + fi + if [ -d /root/.pyenv/versions/3.6.3/bin -a "$(echo "$PATH" | grep root/.pyenv/versions | wc -c)" -eq "0" ] ; then + echo adding python on root/.pyenv to PATH + export PATH="/root/.pyenv/versions/3.6.3/bin:$PATH" + fi + if ! command_exists python ; then + echo No python on path + echo "$PATH" + else + python --version + command -v python + fi +} + get_script_path() { local script="$1" @@ -347,6 +389,11 @@ is_centos_at_least_ver() { version_ge "$(get_version)" "$1" } +is_arm() { + [ "$(dpkg --print-architecture)" = "armhf" ] || return 1 + test "$(dpkg --print-architecture)" = "armhf" +} + print_github_api_rate_limits() { # See https://developer.github.com/v3/rate_limit/ # Note: Accessing this endpoint does not count against your REST API rate limit. diff --git a/CI/travis/make_linux b/CI/travis/make_linux index 47e4cef93..81b8d4fe1 100755 --- a/CI/travis/make_linux +++ b/CI/travis/make_linux @@ -9,7 +9,34 @@ handle_default() { mkdir -p build cd build - FLAGS="-DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON -DPYTHON_BINDINGS=ON -DWITH_EXAMPLES=ON" + add_python_path + if command_exists python ; then + command -v python + python --version + + PYTHON_HELP="-DPYTHON_BINDINGS=ON \ + -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ + -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \ + -DPYTHON_EXECUTABLE=$(command -v python)" + if command_exists sphinx-build ; then + DOC_HELP="-DWITH_DOC=ON" + fi + else + echo No Python + if command_exists doxygen ; then + DOC_HELP="-DWITH_DOC=ON" + fi + fi + if [ ! -n "${DOC_HELP}" ] ; then + if command_exists man2html ; then + echo doc and man + MAN_HELP="-DWITH_MAN=ON" + fi + else + MAN_HELP="-DWITH_MAN=ON" + fi + + FLAGS="-DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON -DWITH_EXAMPLES=ON ${PYTHON_HELP} ${DOC_HELP} ${MAN_HELP}" echo "### cmake ${FLAGS}" cmake ${FLAGS} .. @@ -21,34 +48,35 @@ handle_default() { echo "### make" make - if command_exists sphinx-build ; then - # to build the python doc, libiio and py-iio need to be installed - # so we need to re-do some minor things now that they are - FLAGS="${FLAGS} -DWITH_DOC=ON -DWITH_MAN=ON" - echo "### cmake ${FLAGS}" - cmake ${FLAGS} .. - echo "### make" - make - # check the error output if either file isn't empty - if [ -s ./Dox_output_libiio -o -s ./Dox_output_csharp -o -s ./Spx_output_python ] ; then - if [ -s ./Dox_output_libiio ] ; then - echo "### ERRORs in Dox_output_libiio" - cat ./Dox_output_libiio - fi - if [ -s ./Dox_output_csharp ] ; then - echo "### ERRORs in Dox_output_csharp" - cat ./Dox_output_csharp - fi - if [ -s ./Spx_output_python ] ; then - echo "### ERRRORs in Spx_output_python" - cat ./Spx_output_python - fi - exit 1 - else - echo "### No errors in Doc" - ls -l Dox_output_csharp Dox_output_libiio Spx_output_python + + # check the error output if either file is not empty + if [ -s ./Dox_output_libiio -o -s ./Dox_output_csharp -o -s ./Spx_output_python ] ; then + if [ -s ./Dox_output_libiio ] ; then + echo "### ERRORs in Dox_output_libiio" + cat ./Dox_output_libiio + fi + if [ -s ./Dox_output_csharp ] ; then + echo "### ERRORs in Dox_output_csharp" + cat ./Dox_output_csharp + fi + if [ -s ./Spx_output_python ] ; then + echo "### ERRRORs in Spx_output_python" + cat ./Spx_output_python + fi + exit 1 + else + echo "### No errors in Doc" + if [ -f Dox_output_csharp ] ; then + ls -l Dox_output_csharp + fi + if [ -f Dox_output_libiio ] ; then + ls -l Dox_output_libiio + fi + if [ -f Spx_output_python ] ; then + ls -l Spx_output_python fi fi + echo "### make package" make package if [ -n "${GH_DOC_TOKEN}" ] && \ @@ -65,6 +93,7 @@ handle_default() { } handle_centos() { + echo "handle centos" mkdir -p build cd build cmake -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON .. diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 21b2d1914..6acac2edf 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -2,14 +2,28 @@ cmake_minimum_required(VERSION 2.8.7) project(libiio-py NONE) if(${CMAKE_VERSION} VERSION_LESS "3.12.0") + message(STATUS "bin=${PYTHON_EXECUTABLE} lib=${PYTHON_LIBRARY} inc=${PYTHON_INCLUDE_DIR}") include(FindPythonInterp) # Set variables as they would be set by module FindPython, # which is available from CMake 3.12. set(Python_Interpreter_FOUND ${PYTHONINTERP_FOUND}) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + message(STATUS "old") else() + if(PYTHON_EXECUTABLE) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() + if (PYTHON_LIBRARY) + set(Python_LIBRARY ${PYTHON_LIBRARY}) + endif() + if (PYTHON_INCLUDE_DIR) + set(Python_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) + endif() + message(STATUS "bin=${Python_EXECUTABLE} lib=${Python_LIBRARY} inc=${Python_INCLUDE_DIR}") find_package (Python COMPONENTS Interpreter) + message(STATUS "new") + message(STATUS "Python_EXECUTABLE ${Python_EXECUTABLE}") endif() if (Python_Interpreter_FOUND) @@ -31,6 +45,10 @@ else() endif() if(WITH_DOC) + if(${CMAKE_VERSION} VERSION_LESS "3.2.0") + # cmake -E env was added in 3.2 + message(FATAL_ERROR "Sorry, you can't build python doc with ancient cmake, please update") + endif() find_program(SPHINX_EXECUTABLE NAMES sphinx-build DOC "Sphinx Documentation Builder (sphinx-doc.org)"