- job:
    name: leg-96boards-developerbox-edk2
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
                - job-workspace
            everyone-flat:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
    disabled: true
    node: docker-stretch-arm64
    display-name: 'DELETE ME'
    scm:
        - git:
            url: git://git.linaro.org/leg/noupstream/edk2-platforms.git
            refspec: +refs/heads/developer-box:refs/remotes/origin/developer-box
            name: origin
            branches:
                - refs/heads/developer-box
            basedir: edk2-platforms
            skip-tag: true
            shallow-clone: true
            clean: true
            wipe-workspace: false
    triggers:
        - pollscm: 'H/5 * * * *'
        - timed: '@monthly'
    wrappers:
        - timestamps
        - build-name:
            name: '#${BUILD_NUMBER}-${GIT_REVISION,length=8}'
    builders:
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            set -ex

            trap cleanup_exit INT TERM EXIT

            cleanup_exit()
            {
              cd ${WORKSPACE}
              rm -rf out Build edk2 edk2-non-osi
            }

            export EDK2_GIT_URL=git://git.linaro.org/leg/noupstream/edk2.git
            export EDK2_GIT_BRANCH=developer-box
            git clone --depth 1 -b $EDK2_GIT_BRANCH --recurse-submodules $EDK2_GIT_URL
            export EDK2_GIT_COMMIT=$(cd edk2; git rev-parse HEAD)

            export EDK2_NON_OSI_GIT_URL=git://git.linaro.org/leg/noupstream/edk2-non-osi.git
            export EDK2_NON_OSI_GIT_BRANCH=developer-box
            git clone --depth 1 -b $EDK2_NON_OSI_GIT_BRANCH  $EDK2_NON_OSI_GIT_URL
            export EDK2_NON_OSI_GIT_COMMIT=$(cd edk2-non-osi; git rev-parse HEAD)

            export OUTDIR=${WORKSPACE}/out
            export PACKAGES_PATH=${WORKSPACE}/edk2:${WORKSPACE}/edk2-platforms:${WORKSPACE}/edk2-non-osi

            NUM_THREADS=$((`getconf _NPROCESSORS_ONLN` + 1))

            make -C edk2/BaseTools -j $NUM_THREADS

            source edk2/edksetup.sh

            build -a AARCH64 -t GCC5 -b RELEASE -n $NUM_THREADS -p Platform/Socionext/DeveloperBox/DeveloperBox.dsc -D BUILD_NUMBER=${BUILD_NUMBER} -D X64EMU_ENABLE -D FIRMWARE_VENDOR=Linaro
            build -a AARCH64 -t GCC5 -b DEBUG -n $NUM_THREADS -p Platform/Socionext/DeveloperBox/DeveloperBox.dsc -D BUILD_NUMBER=${BUILD_NUMBER} -D X64EMU_ENABLE -D FIRMWARE_VENDOR=Linaro

            mkdir $OUTDIR
            cp Build/DeveloperBox/DEBUG_GCC5/FV/SPI_NOR_IMAGE.fd $OUTDIR/SPI_NOR_IMAGE.fd-DEBUG
            cp Build/DeveloperBox/RELEASE_GCC5/FV/SPI_NOR_IMAGE.fd $OUTDIR/SPI_NOR_IMAGE.fd-RELEASE
            cp Build/DeveloperBox/DEBUG_GCC5/FV/SYNQUACERFIRMWAREUPDATECAPSULEFMPPKCS7.Cap $OUTDIR/DeveloperBox-DEBUG.Cap
            cp Build/DeveloperBox/RELEASE_GCC5/FV/SYNQUACERFIRMWAREUPDATECAPSULEFMPPKCS7.Cap $OUTDIR/DeveloperBox.Cap

            # Build information
            cat > out/HEADER.textile << EOF

            h4. 96boards Enterprise Edition - Socionext DeveloperBox System Firmware

            Build Description:
            * Build URL             : "$BUILD_URL":$BUILD_URL
            * edk2-platforms repo   : $GIT_URL
            * edk2-platforms branch : $GIT_BRANCH
            * edk2-platforms HEAD   : $GIT_COMMIT
            * edk2 repo             : $EDK2_GIT_URL
            * edk2 branch           : $EDK2_GIT_BRANCH
            * edk2 HEAD             : $EDK2_GIT_COMMIT
            * edk2-non-osi repo     : $EDK2_NON_OSI_GIT_URL
            * edk2-non-osi branch   : $EDK2_NON_OSI_GIT_BRANCH
            * edk2-non-osi HEAD     : $EDK2_NON_OSI_GIT_COMMIT
            EOF

            #find out -name '*QEMU_EFI.fd' -exec bash -c 'in=${1}; out=${in%fd}img; cat $in /dev/zero | dd iflag=fullblock bs=1M count=64 of=$out; gzip -9 $out' _ {} \;

            # 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 components/kernel/${JOB_NAME}/${BUILD_NUMBER}
    publishers:
        - email:
            recipients: 'ard.biesheuvel@linaro.org'
