- job:
    name: openembedded-rootfs-external-toolchain
    project-type: matrix
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
    parameters:
        - string:
            name: toolchain_url
            default: 'http://releases.linaro.org/components/toolchain/binaries/5.3-2016.02/aarch64-linux-gnu/gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz'
    disabled: true
    node: build
    display-name: 'DELETE ME'
    scm:
        - git:
            url: https://git.linaro.org/openembedded/jenkins-setup.git
            refspec: +refs/heads/master:refs/remotes/origin/master
            name: origin
            branches:
                - refs/heads/master
            skip-tag: true
            shallow-clone: true
            wipe-workspace: false
    axes:
        - axis:
            type: slave
            name: label
            values:
                - build
        - axis:
            type: user-defined
            name: rootfs
            values:
                - lamp
                - minimal
    execution-strategy:
        sequential: true
        touchstone:
            expr: 'rootfs=="minimal"'
    wrappers:
        - timestamps
        - matrix-tie-parent:
            node: build
    builders:
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            set -ex

            case "$(echo ${toolchain_url} | sed -e 's|^.*x86_64_||')" in
              armeb*)
                arch=armv7ab
                ;;
              arm*)
                arch=armv7a
                ;;
              aarch64_be*)
                arch=armv8b
                ;;
              aarch64*)
                arch=armv8
                ;;
              *)
                arch=x86
                ;;
            esac

            # we clean build and populate it from cache
            bash -x pre-build-do-cleanup.sh

            # do a build
            bash -x init-and-build.sh -a ${arch} -u ${toolchain_url} linaro-image-${rootfs}

            cd ${WORKSPACE}

            bash -x post-build-create-image-manifest.sh
            bash -x post-build-sort-out-downloads.sh

            # Capture what we're building in the build output.
            echo "Build configuration: ${PWD}"
            git log --format="%H %s" -1
            $HOME/bin/repo forall -p -c 'git log --format="%H %s" -1'

            # Publish
            test -d ${HOME}/bin || mkdir ${HOME}/bin
            wget -q https://git.linaro.org/ci/publishing-api.git/blob_plain/HEAD:/linaro-cp.py -O ${HOME}/bin/linaro-cp.py
            time python3 ${HOME}/bin/linaro-cp.py \
              --api_version 3 \
              --link-latest \
              out/ openembedded/images/${rootfs}-${arch}-external-toolchain/${BUILD_NUMBER}
    publishers:
        - email:
            recipients: 'fathi.boudra@linaro.org'
