---
language: python

#python:
#  - 3.6
#  - 3.7

jobs:
  include:
    # - name: "Generic Python 3.6 on Windows 10"
    #   ## https://docs.travis-ci.com/user/reference/windows/#how-do-i-use-msys2
    #   os: windows
    #   language: shell
    #   before_install:
    #     - |
    #         case $TRAVIS_OS_NAME in
    #           windows)
    #             [[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64
    #             choco uninstall -y mingw
    #             choco upgrade --no-progress -y msys2
    #             export msys2='cmd //C RefreshEnv.cmd '
    #             export msys2+='& set MSYS=winsymlinks:nativestrict '
    #             export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start'
    #             export mingw64="$msys2 -mingw64 -full-path -here -c "\"\$@"\" --"
    #             export msys2+=" -msys2 -c "\"\$@"\" --"
    #             $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain
    #             ## Install more MSYS2 packages from https://packages.msys2.org/base here
    #             $msys2 pacman -S --noconfirm --needed base
    #             $msys2 pacman -S --noconfirm --needed base-devel
    #             $msys2 pacman -S --noconfirm --needed cmake
    #             $msys2 pacman -S --noconfirm --needed development
    #             $msys2 pacman -S --noconfirm --needed compression
    #             $msys2 pacman -S --noconfirm --needed git
    #             $msys2 pacman -S --noconfirm --needed libraries
    #             $msys2 pacman -S --noconfirm --needed msys2-devel
    #             $msys2 pacman -S --noconfirm --needed make
    #             $msys2 pacman -S --noconfirm --needed python3.7
    #             $msys2 pacman -S --noconfirm --needed python3-pip
    #             $msys2 pacman -S --noconfirm --needed swig
    #             taskkill //IM gpg-agent.exe //F  # https://travis-ci.community/t/4967
    #             export PATH=/C/tools/msys64/bin/:/C/tools/msys64/mingw64/usr/bin:$PATH
    #             ## https://www.msys2.org/wiki/Porting/
    #             ## Don't use mingw32-make
    #             export MAKE=mingw32-make  # so that Autotools can find it
    #             echo IAMHERE
    #             echo PRINTENV
    #             printenv
    #             ;;
    #         esac
    #   before_cache:
    #     - |
    #         # https://unix.stackexchange.com/a/137322/107554
    #         $msys2 pacman --sync --clean --noconfirm
    #   cache:
    #     directories:
    #       - $HOME/AppData/Local/Temp/chocolatey
    #       - /C/tools/msys64
    - name: "Generic Python 3.X on macOS"
      os: osx
      osx_image: xcode11.4
      language: shell
      addons:
        homebrew:
          packages:
            - gcc@7
            - bison
            - flex
            - git-lfs
            - python@3
            - readline
            - swig
          update: true
    - name: "Generic Python 3.X on Linux"
      os: linux
      dist: xenial
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - build-essential
            - cmake 
            - doxygen
            - software-properties-common
            - gcc-6
            - g++-6
            - git
            - bison
            - flex
            - libreadline-dev
            - libncurses5-dev
            - libncursesw5-dev
            - libreadline-dev
            - libssh-dev
            - python3.7
            - python3.7-dev
            - python3-pip 
            - swig

# compiler:
#    - gcc
#    - clang

env:
  global:
    - TRAVIS_ALLOW_FAILURE=true
    - TEST_LIST='born geoflow actin-dimer-auto actin-dimer-parallel alkanes FKBP hca-bind ion-pmf ion-protein ionize pka-lig point-pmf solv protein-rna'
    # From https://codecov.io/gh/Electrostatics/apbs-pdb2pqr
    - CODECOV_TOKEN="e3a1e24c-5598-4f47-9353-7fa0ac57f98e"
    - CMAKE_OPTS=' -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DENABLE_GEOFLOW=ON  -DENABLE_BEM=ON  -DGET_MSMS=ON  -DENABLE_FETK=ON  -DENABLE_PBSAM=ON  -DENABLE_PBAM=ON  -DENABLE_PYTHON=ON  -DBUILD_SHARED_LIBS=ON  -DBUILD_DOC=OFF'
    #  - CMAKE_OPTS=' -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DENABLE_GEOFLOW=ON  -DENABLE_BEM=ON  -DGET_MSMS=ON  -DENABLE_FETK=ON  -DENABLE_PBSAM=ON  -DENABLE_PBAM=ON  -DENABLE_PYTHON=ON  -DBUILD_SHARED_LIBS=ON  -DBUILD_DOC=OFF'
    #  - CMAKE_OPTS=' -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DENABLE_GEOFLOW=ON  -DENABLE_BEM=ON  -DGET_MSMS=ON  -DENABLE_FETK=ON  -DENABLE_PBSAM=OFF -DENABLE_PBAM=OFF -DENABLE_PYTHON=ON  -DBUILD_SHARED_LIBS=ON  -DCMAKE_C_FLAGS="-fPIC" -DBUILD_DOC=ON'
    #  - CMAKE_OPTS=' -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DENABLE_GEOFLOW=ON  -DENABLE_BEM=OFF -DGET_MSMS=OFF -DENABLE_FETK=ON  -DENABLE_PBSAM=OFF -DENABLE_PBAM=OFF -DENABLE_PYTHON=ON  -DBUILD_SHARED_LIBS=ON  -DCMAKE_C_FLAGS="-fPIC" -DBUILD_DOC=ON'

if: >-
  branch = master
  AND commit_message !~ /^noci/


before_install:
  - python3 --version
  - pip3 install -U pip
  - pip3 install -U pytest
  - pip3 install -U numpy
  - pip3 install -U virtualenv
  - pip3 install -r pdb2pqr/requirements.txt

before_script:
  - |
      echo "==================================== WHERE AM I ==================================== "
      pwd
      # Make the install directory
      mkdir -p $HOME/local
      echo "ENV2"
      env

      echo "==================================== VERSIONS: ==================================== "
      echo "==================================== PYTHON VERSION"
      case $TRAVIS_OS_NAME in
        windows)
          where python
          find /C/tools/msys64 -name pip3\*
          find /C/tools/msys64 -name swig\*
          find /C -name rpc.h
          find /C -name fcntl.h
          ;;
      esac
      python -c "import sys; print(sys.version)"
      echo "==================================== CMAKE VERSION"
      cmake --version
      echo "==================================== Gcc VERSION"
      export CC=gcc
      export CMAKE_C_COMPILER=gcc
      gcc --version
      echo "==================================== G++ VERSION"
      export CXX=g++
      export CMAKE_CXX_COMPILER=g++
      g++ --version
      echo "==================================== SWIG VERSION"
      swig -version

      echo "==================================== Install Python requirements ==================================== "
      pip3 install -U pip
      pip3 install -U pytest
      pip3 install -U virtualenv
      pip3 install -U numpy
      pip3 install -r pdb2pqr/requirements.txt

      #  Just build APBS for now
      echo "==================================== PWD FOR TOP DIR ==================================== "
      pwd

      echo "==================================== Get External SubModules ==================================== "
      git submodule init
      git submodule update
      #mkdir build
      #cd build
      #cmake ..
      #make VERBOSE=1
      #cd ..

      cd apbs
      echo "==================================== PWD FOR APBS SRC ==================================== "
      pwd
      mkdir build
      cd build
      echo "==================================== BUILD DIR ==================================== "
      pwd

      echo "==================================== RUN CMAKE ==================================== "
      pwd
      export CMAKE_C_STANDARD_INCLUDE_DIRECTORIES="/C/tools/msys64/opt/x86_64-w64-mingw32/"
      export CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/C/tools/msys64/opt/x86_64-w64-mingw32/"
      cmake $CMAKE_OPTS -DCMAKE_INSTALL_PREFIX:PATH=$HOME/local .. || exit 1
      echo "==================================== RAN CMAKE =================================== "

      echo "==================================== RUN MAKE ==================================== "
      pwd
      make -j 1
      make -j 1 install

script:
  - |
      #  Assume we are in the User's home directory where the top of the repository
      echo "==================================== LOOK for APBS binary ==================================== "
      pwd
      echo find $HOME -type f -name apbs
      find $HOME -type f -name apbs
      echo find $HOME -type f -name libmaloc
      find $HOME -type f -name libmaloc\*
      echo cd ../tests
      cd ../tests
      echo pwd
      pwd
      echo ls
      ls
      export LD_LIBRARY_PATH=${HOME}/local/lib
      if [ -f /etc/os-release ]; then
        ldd $HOME/local/bin/apbs
      fi
      if [ "$TRAVIS_OS_NAME" = "osx" ]; then
        otool -L $HOME/local/bin/apbs
      fi
      for name in `echo $TEST_LIST`
      do
        echo bash run_travis_test.sh $HOME/local/bin $name
             bash run_travis_test.sh $HOME/local/bin $name
      done

notifications:
  slack:
    on_success: always
    #  - electrostatics:U4cSeRAFGXl9vUqdg4WOubnc
