- job:
    name: android-lmg-vexpress-aosp-master
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 60
        numToKeep: 60
    properties:
        - authorization:
            anonymous:
                - job-read
            everyone-flat:
                - job-build
                - job-cancel
    disabled: true
    node: docker-xenial-aosp
    display-name: 'DELETE ME'
    concurrent: true
    wrappers:
        - timestamps
        - timeout:
            timeout: 500
    builders:
        - shell: |
            #!/bin/bash

            BUILD_CONFIG_FILENAME=aosp-master-vexpress-lsk

            java -version

            sudo add-apt-repository ppa:linaro-maintainers/tools
            sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
            sudo apt-get update
            sudo apt-get install -y bison git gperf libxml2-utils python-mako zip time python-requests genisoimage patch

            mkdir -p ${HOME}/bin ${WORKSPACE}/build/out
            curl https://storage.googleapis.com/git-repo-downloads/repo > ${HOME}/bin/repo
            chmod a+x ${HOME}/bin/*
            export PATH=${HOME}/bin:${PATH}

            if [ ! -d "/home/buildslave/srv/${JOB_NAME}" ]; then
              sudo mkdir -p /home/buildslave/srv/${JOB_NAME}
              sudo chmod 777 /home/buildslave/srv/${JOB_NAME}
            fi
            cd /home/buildslave/srv/${JOB_NAME}

            git config --global user.email "ci_notify@linaro.org"
            git config --global user.name "Linaro CI"

            # Runs as ubuntu
            set -xe
            rm -rf build-tools jenkins-tools build-configs build/out build/android-patchsets
            git clone --depth 1 https://git.linaro.org/infrastructure/linaro-android-build-tools.git build-tools
            git clone --depth 1 https://git.linaro.org/infrastructure/linaro-jenkins-tools.git jenkins-tools
            git clone --depth 1 http://android-git.linaro.org/git/android-build-configs.git build-configs

            export BUNDLE_STREAM_NAME=${BUNDLE_STREAM_NAME:-/private/team/wg/wg-private/}
            export BUILD_CONFIG_FILENAME=${BUILD_CONFIG_FILENAME:-${JOB_NAME#android-*}}

            # Early test
            if [ ! -f build-configs/${BUILD_CONFIG_FILENAME} ]; then
              echo "No config file named ${BUILD_CONFIG_FILENAME} exists"
              echo "in android-build-configs.git"
              exit 1
            fi

            cat << EOF > config.txt
            BUILD_CONFIG_REPO=http://android-git.linaro.org/git/android-build-configs.git
            BUILD_CONFIG_BRANCH=master
            EOF
            echo config.txt
            export CONFIG=`base64 -w 0 config.txt`

            # Build Android
            build-tools/node/build us-east-1.ec2-git-mirror.linaro.org "${CONFIG}"
            cp -a /home/buildslave/srv/${JOB_NAME}/build/out/*.xml ${WORKSPACE}/

            # Publish parameters
            cat << EOF > ${WORKSPACE}/publish_parameters
            PUB_SRC=${PWD}/build/out
            PUB_DEST=/android/${JOB_NAME}/${BUILD_NUMBER}
            EOF

            # Construct post-build-lava parameters
            source build-configs/${BUILD_CONFIG_FILENAME}
            cat << EOF > ${WORKSPACE}/post_build_lava_parameters
            DEVICE_TYPE=${LAVA_DEVICE_TYPE:-${TARGET_PRODUCT}}
            TARGET_PRODUCT=${TARGET_PRODUCT}
            MAKE_TARGETS=${MAKE_TARGETS}
            JOB_NAME=${JOB_NAME}
            BUILD_NUMBER=${BUILD_NUMBER}
            BUILD_URL=${BUILD_URL}
            LAVA_SERVER=validation.linaro.org/RPC2/
            LAVA_STREAM=${BUNDLE_STREAM_NAME}
            BUNDLE_STREAM_NAME=${BUNDLE_STREAM_NAME}
            FRONTEND_JOB_NAME=${JOB_NAME}
            EOF

            grep \
              -e ^LAVA_JOB_URL \
              build-configs/${BUILD_CONFIG_FILENAME} \
                | sed -e 's:^LAVA_JOB_URL:CUSTOM_JSON_URL:g' \
                >> ${WORKSPACE}/post_build_lava_parameters
        - inject:
            properties-file: publish_parameters
        - linaro-publish-token
        - shell:
            !include-raw:
                - android/linaro-publisher.sh
        - trigger-builds:
            - project: 'post-build-lava'
              property-file: post_build_lava_parameters
              block: true
    publishers:
        - archive:
            artifacts: '*.xml'
            latest-only: true
        - logparser:
            parse-rules: '/var/jenkins_home/userContent/android.parse'
            unstable-on-warning: false
            fail-on-error: false
        - fingerprint:
            files: 'build/fingerprints/*'
        - email:
            recipients: 'vishal.bhoj@linaro.org fathi.boudra@linaro.org daniel.diaz@linaro.org'
