language: c

notifications:
  - email: true

git:
  depth: false

before_install:
  - sudo apt-get -y install codespell

before_script:
  - export OPTEE_OS=$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_OS
  - source scripts/checkpatch_inc.sh

  # Install pycodestyle
  - pip install --upgrade --user pycodestyle

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

  # Check Python style
  - pycodestyle scripts/*.py core/arch/arm/plat-stm32mp1/scripts/stm32image.py
