- job:
    name: jdk8-build-release
    project-type: matrix
    defaults: global
    description: |
        * Configures and builds jdk8u for release. Run after the source has passed tests.
        * Tags build with Linaro-YYMM as per normal release procedure.
        * The source tarball is copied from the jdk8-update-src-tree job.<br>
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            openjdk-members:
                - job-build
                - job-cancel
                - job-workspace
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 10
            artifact-num-to-keep: 5
    disabled: true
    node: j12-qrep-01
    display-name: 'DELETE ME'
    scm:
        - git:
            url: https://git.linaro.org/leg/openjdk/openjdk8-jenkins-only-build-patches.git
            refspec: +refs/heads/master:refs/remotes/origin/master
            name: origin
            branches:
                - refs/heads/master
            basedir: patches
            skip-tag: true
            shallow-clone: true
            wipe-workspace: false
    axes:
        - axis:
            type: user-defined
            name: BUILD_TYPE
            values:
                - release
        - axis:
            type: slave
            name: label
            values:
                - j12-qrep-01
    execution-strategy:
        sequential: true
    wrappers:
        - workspace-cleanup:
            dirmatch: false
        - timestamps
        - matrix-tie-parent:
            node: j12-qrep-01
    builders:
        - copyartifact:
            project: jdk8-update-src-tree
            filter: 'out/jdk8u.tar.gz'
            target: incoming
            flatten: true
            target: incoming
            flatten: true
        - shell: |
            #!/bin/bash

            set -exu

            # Generate files names dependent on year/month.
            RELEASE=$(date +%y%m)
            JDKDIR=jdk8u-${BUILD_TYPE}-${RELEASE}
            JDK_SRCDIR=jdk8u-src-${RELEASE}

            ccache_build_opts=--disable-ccache

            rm -rf jdk* primordial-jdk* build* out
            mkdir -p build-stage1 build-stage2 out

            cd $HOME/srv/jdk-cache/jdk8u
            export JAVA_HOME=${PWD}

            export PATH=${JAVA_HOME}/bin:${PATH}

            cd ${WORKSPACE}

            # Extract sources from upstream job
            rm -rf jdk8u
            tar xf incoming/jdk8u.tar.gz

            mv jdk8u $JDK_SRCDIR
            # Tar up the source before sullying it with a build.
            tar --exclude=.hg\* -acf out/jdk8u-src-${RELEASE}.tar.xz $JDK_SRCDIR

            mv $JDK_SRCDIR $JDKDIR
            shopt -s nullglob

            # Configure and build.
            two_stage_build=0

            which java
            java -version

            EXTRA_CFLAGS="-Wno-error -fno-delete-null-pointer-checks \
              -fno-lifetime-dse -Wno-deprecated-declarations         \
              -Wno-maybe-uninitialized -Wno-misleading-indentation \
              -Wno-shift-negative-value"
            EXTRA_CPP_FLAGS="-Wno-error -std=gnu++98 \
              -fno-delete-null-pointer-checks -fno-lifetime-dse \
              -Wno-deprecated-declarations -Wno-maybe-uninitialized \
              -Wno-misleading-indentation -Wno-shift-negative-value"
            if [ $two_stage_build = 1 ]; then
              pushd build-stage1
              sh ../$JDKDIR/configure --with-debug-level=${BUILD_TYPE} --with-boot-jdk=${WORKSPACE}/primordial-jdk7 ${ccache_build_opts} \
                 --with-extra-cxxflags="$EXTRA_CPP_FLAGS" --with-extra-cflags="$EXTRA_CFLAGS"
              make images
              popd

              pushd build-stage2
              sh ../$JDKDIR/configure   --with-debug-level=${BUILD_TYPE} \
                                        --with-boot-jdk=${WORKSPACE}/build-stage1/images/j2sdk-image \
                                        ${ccache_build_opts} \
                                        --with-extra-cxxflags="$EXTRA_CPP_FLAGS" \
                                        --with-extra-cflags="$EXTRA_CFLAGS" \
                                        --with-user-release-suffix="Linaro-$RELEASE" \
                                        --with-milestone="release"
              make images
              popd
            else
              pushd build-stage2
              sh ../$JDKDIR/configure   --with-debug-level=${BUILD_TYPE} \
                                        ${ccache_build_opts} \
                                         --with-extra-cxxflags="$EXTRA_CPP_FLAGS" \
                                        --with-extra-cflags="$EXTRA_CFLAGS" \
                                        --with-user-release-suffix="Linaro-$RELEASE" \
                                        --with-milestone="release"
              make images
              popd
            fi

            # Archive the result
            artifact_name=jdk8u-${BUILD_TYPE}-${RELEASE}

            # This is different from ordinary builds.
            tar -C build-stage2/images --exclude=\*.diz --transform="s!^j2sdk-image!$artifact_name!" -acf out/${artifact_name}.tar.xz j2sdk-image
    publishers:
        - archive:
            artifacts: 'out/*.tar.xz'
        - email:
            recipients: 'stuart.monteith@linaro.org fathi.boudra@linaro.org'
