# Global variables
language: python
python:
    - "2.7"
env:
  global:
    - TOOLS_DIR=$HOME/build_tools
    - GNAT_TAR_PATH=$TOOLS_DIR/gpl-2017-compiler.tar.gz
    - LINUX_GNAT_URL=http://mirrors.cdn.adacore.com/art/591c6d80c7a447af2deed1d7
    - DARWIN_GNAT_URL=http://mirrors.cdn.adacore.com/art/591c9045c7a447af2deed24e
os:
  - linux

# Cache directory that allows us to not download GNAT GPL every time, speeding
# up the process.
cache:
  directories:
    - /home/travis/build_tools
    - /Users/travis/build_tools

install:
  # Check if the GNAT package is already available in the cache directory. If
  # not, download it.
  - >
      test -f $GNAT_TAR_PATH ||
      (mkdir -p $TOOLS_DIR &&
       if [ "$TRAVIS_OS_NAME" = "osx" ]; then
          wget $DARWIN_GNAT_URL -O $GNAT_TAR_PATH
       else
          wget $LINUX_GNAT_URL -O $GNAT_TAR_PATH
       fi
      )

  # Extract GNAT from its package
  - (mkdir -p ada-compiler && cd ada-compiler && tar --strip-components 1 -xzf $GNAT_TAR_PATH)

  # Add GNAT to $PATH
  - export PATH=$PWD/ada-compiler/bin:$PATH

  # Checkout gprbuild
  - git clone https://github.com/AdaCore/gprbuild libgpr-src

  # Add e3-testsuite
  - pip install git+https://github.com/AdaCore/e3-testsuite.git 

script:
  # Show GNAT version for the record
  - $PWD/ada-compiler/bin/gprbuild --version

  - (cd libgpr-src && make libgpr.build && make libgpr.install)

    # Build gnatcoll-core
  - make all

  - (cd testsuite; ./run-tests --gcov)

after_success:
  - bash <(curl -s https://codecov.io/bash)
