language: rust

before_install:
  - set -e
  - export SCCACHE_CACHE_SIZE=200M
  - export SCCACHE_DIR="$TRAVIS_HOME/.cache/sccache"
  - mkdir "$TRAVIS_HOME/.bin"
  - wget https://github.com/mozilla/sccache/releases/download/0.2.13/sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
  - tar -C "$TRAVIS_HOME/.bin" -xvf sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
  - mv $TRAVIS_HOME/.bin/sccache-0.2.13-x86_64-unknown-linux-musl/sccache $TRAVIS_HOME/.bin/sccache
  - export PATH="$PATH:$TRAVIS_HOME/.bin"
  - export RUSTC_WRAPPER="sccache"
  - |
    declare -r SSH_FILE="$(mktemp -u $HOME/.ssh/XXXXX)"
    openssl aes-256-cbc -K $encrypted_beefc4a47cdc_key -iv $encrypted_beefc4a47cdc_iv -in .travis/travis-snarkos.enc -out $SSH_FILE -d
    chmod 600 "$SSH_FILE" \
           && printf "%s\n" \
                "Host github.com" \
                "  IdentityFile $SSH_FILE" \
                "  LogLevel ERROR" >> ~/.ssh/config
  - git clone --progress --verbose git@github.com:AleoHQ/snarkOS.git
  - mv snarkOS ..

cache:
  directories:
    - $TRAVIS_HOME/.cache/sccache
    - $TRAVIS_HOME/.cargo

# See https://levans.fr/rust_travis_cache.html
before_cache:
  - rm -rf "$TRAVIS_HOME/.cargo/registry"

after_script:
  - (sccache -s||true)
  - set +e

matrix:
  fast_finish: true
  include:
    - rust: stable
      env: TEST_COVERAGE=1
      addons:
        apt:
          packages:
            - libcurl4-openssl-dev
            - libelf-dev
            - libdw-dev
            - cmake
            - gcc
            - binutils-dev
            - libiberty-dev
      script:
        - cargo test --all
      after_success:
        - wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
        - tar xzf master.tar.gz && cd kcov-master
        - mkdir build && cd build && cmake .. && make && sudo make install
        - cd ../.. && rm -rf kcov-master
        - for file in target/debug/deps/*-*; do if [[ "$file" != *\.* ]]; then mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; fi done
        - bash <(curl -s https://codecov.io/bash)
        - echo "Uploaded code coverage"
    - rust: nightly-2020-03-18
      install:
        - rustup component add rustfmt
      script:
        - cargo fmt -- --check
        - cargo test --all

script:
  - echo "leo"