# One may have a look at http://docs.travis-ci.com/user/installing-dependencies/

language: c

notifications:
  - email: true

git:
  depth: false

before_script:
  - export OPTEE_CLIENT=$PWD

  # Download checkpatch.pl
  - export KERNEL=$HOME/linux && mkdir -p $KERNEL/scripts && cd $KERNEL/scripts
  - wget https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/plain/scripts/checkpatch.pl && chmod a+x checkpatch.pl
  - wget https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/plain/scripts/spelling.txt
  - echo "invalid.struct.name" >const_structs.checkpatch
  - export PATH=$KERNEL/scripts/:$PATH
  - cd $OPTEE_CLIENT
  - source scripts/checkpatch_inc.sh

# Install the cross-compiler
before_install:
  - sudo apt-get update -qq
  - sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
  - arm-linux-gnueabihf-gcc --version
  # Travis does 'export CC=gcc'. Unset CC so that ./flags.mk properly
  # defines the cross-compiler to the default value: $(CROSS_COMPILE)gcc.
  - unset CC

# Several compilation options are checked
script:
  # Run checkpatch.pl on:
  # - the tip of the branch if we're not in a pull request
  # - each commit in the development branch that's not in the target branch otherwise
  - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then checkpatch HEAD; else for c in $(git rev-list HEAD^1..HEAD^2); do checkpatch $c || failed=1; done; [ -z "$failed" ]; fi
  # If we have a pull request with more than 1 commit, also check the squashed commits
  # Useful to check if fix-up commits do indeed solve previous checkpatch errors
  - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ "$(git rev-list --count HEAD^1..HEAD^2)" -gt 1 ]; then checkdiff $(git rev-parse HEAD^1) $(git rev-parse HEAD^2); fi; fi

  - make clean all
  - CFG_TEE_CLIENT_LOG_LEVEL=0 make clean all
  - CFG_TEE_CLIENT_LOG_LEVEL=5 make clean all
