# Purpose:
# - To test and prove that a new commit in  the mbed TLS repository builds
# and integrates with mbed-os properly.
#           AND
# - To test and prove that the current development head of mbed TLS builds
# and integrates with the current mbed-os master branch.
#
# The script fetches all the prerequisites and builds the mbed TLS 'tls-client'
# example. This script is triggered by every commit and once each night and the
# exact behaviour depends on how it was triggered:
# - If it is a nightly build then it builds the mbed TLS development head with
#   mbed-os master.
# - If it was triggered by the commit, then it builds the example with mbed TLS
#   at that commit and mbed-os at the commit pointed by mbed-os.lib in the
#   example repository.

test:
    override:
        - cd ../mbed-os-example-tls/tls-client/ && mbed compile -m K64F -t GCC_ARM -c

dependencies:
    pre:
        # Install gcc-arm
        - cd .. && wget "https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2"
        - cd .. && tar -xvjf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2
        - ln -s ../gcc-arm-none-eabi-4_9-2015q3/bin/* ../bin/
        # Install mbed-cli
        - cd ../ && git clone https://github.com/ARMmbed/mbed-cli.git
        - cd ../mbed-cli && sudo -H pip install -e .
        # Get the sample application
        - cd ../ && git clone git@github.com:ARMmbed/mbed-os-example-tls.git
        # Get mbed-os
        - cd ../mbed-os-example-tls/tls-client && mbed deploy
        # Update mbed-os to master only if it is a nightly build
        - >
            if [ -n "${RUN_NIGHTLY_BUILD}" ]; then
                cd ../mbed-os-example-tls/tls-client/mbed-os/ && mbed update master;
            fi
        # Import mbedtls current revision
        - ln -s ../../../../../../../mbedtls/ ../mbed-os-example-tls/tls-client/mbed-os/features/mbedtls/importer/TARGET_IGNORE/mbedtls
        - cd ../mbed-os-example-tls/tls-client/mbed-os/features/mbedtls/importer/ && make
    override:
        # Install the missing python packages
        - cd ../mbed-os-example-tls/tls-client/mbed-os/ && sudo -H pip install -r requirements.txt
