- job:
    name: tcwg-buildfarm
    project-type: matrix
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 100
    parameters:
        - string:
            name: override
            default: ''
            description: 'Versions of components to build; e.g. binutils=binutils-gdb.git/linaro_binutils-2_25-branch gcc=gcc.git~linaro/gcc-5-branch glibc=glibc.git~release/2.21/master'
        - string:
            name: host_x86_64_languages
            default: 'default'
            description: 'Languages to build for x86_64-hosted toolchains, e.g., "c,c++" or "all" or "default"'
        - string:
            name: host_aarchXX_languages
            default: 'c,c++'
            description: 'Languages to build for AArchXX-hosted toolchains, e.g., "c,c++" or "all" or "default"'
        - string:
            name: runtests
            default: 'aarch64-linux-gnu armv8l-linux-gnueabihf arm-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf arm-eabi aarch64-none-elf aarch64_be-none-elf tcwg-x86_64-build'
            description: 'Run toolchain tests for these targets -- must be a subset of target_list'
        - string:
            name: send_results_to
            default: ''
            description: 'Email address to send test results to'
        - bool:
            name: try_bootstrap
            default: 'true'
            description: 'Attempt to bootstrap GCC for compatible host and target combinations'
        - string:
            name: host_x86_64_excludecheck
            default: 'gdb'
            description: 'Do not run "make check" on these components on x86_64'
        - string:
            name: host_aarchXX_excludecheck
            default: 'gcc'
            description: 'Do not run "make check" on these components on AArchXX'
        - string:
            name: extraconfig
            default: ''
            description: 'Extra configuration files, syntax tool=path'
        - bool:
            name: rebuild
            default: true
            description: 'Rebuild the toolchain even if results are already on logserver'
        - string:
            name: log_name
            default: '${JOB_NAME}-${BUILD_NUMBER}/@@host@@.$target'
            description: 'Logname directory on logserver'
        - bool:
            name: dont_fail
            default: false
            description: 'Do not fail the build'
        - string:
            name: log_server
            default: dev-01.tcwglab:/home/tcwg-buildslave/logs
            description: 'Log_Server'
        - string:
            name: target_list
            default: 'aarch64-linux-gnu aarch64-linux-gnu_ilp32 armv8l-linux-gnueabihf arm-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf arm-eabi aarch64-none-elf aarch64_be-none-elf tcwg-x86_64-build'
            description: 'List of targets -- aarch64-linux-gnu aarch64-linux-gnu_ilp32 armv8l-linux-gnueabihf arm-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf arm-eabi aarch64-none-elf aarch64_be-none-elf tcwg-x86_64-build tcwg-x86_32-build tcwg-tk1_32-build tcwg-armv8_64 tcwg-armv8_32-build tcwg-sq_32-build tcwg-sq_64-build -- the tcwg-* targets should be a subset of slave axis'
        - string:
            name: abe_branch
            default: tested
            description: 'ABE revision to test'
        - string:
            name: scripts_branch
            default: tested
            description: 'Scripts branch to use'
        - string:
            name: build_container_tag
            default: 'lts_1'
            description: 'Distro to use on the builder with non-default container type: lts_1, lts, ...'
        - string:
            name: test_container_tag
            default: 'lts_1'
            description: 'Distro to use in the test container: lts_1, lts, ...'
        - string:
            name: displaytag
            default: 'manual'
            description: 'Tag to display in the Jenkins console, so that the build name is more helpful'
        - bool:
            name: binaries
            default: false
            description: 'Create binary tarballs'
        - bool:
            name: dryrun
            default: false
            description: 'Dry-run, do nothing, just print steps'
    disabled: false
    node: tcwg-coordinator
    concurrent: true
    display-name: 'TCWG AAA BuildFarm'
    child-workspace: ../tcwg-buildfarm__$EXECUTOR_NUMBER
    scm:
        - git:
            url: https://gitlab.com/Linaro/tcwg/abe.git
            refspec: +refs/heads/*:refs/remotes/origin/* +refs/changes/*:refs/changes/*
            branches:
                - $abe_branch
            skip-tag: true
            shallow-clone: true
            wipe-workspace: true
        - git:
            url: https://gitlab.com/LinaroLtd/tcwg/jenkins-scripts.git
            refspec: +refs/heads/*:refs/remotes/origin/* +refs/changes/*:refs/changes/*
            branches:
                - $scripts_branch
            basedir: jenkins-scripts
            skip-tag: true
            shallow-clone: true
            wipe-workspace: true
    axes:
        - axis:
            type: slave
            name: label
            values:
                - tcwg-x86_64-build
                - tcwg-tk1_32-build
                - tcwg-armv8_64
                - tcwg-armv8_32
                - tcwg-sq_32-build
                - tcwg-sq_64-build
        - axis:
            type: dynamic
            name: target
            values:
                - target_list
    execution-strategy:
        combination-filter: |
            (label=="tcwg-x86_64-build" && ! (target==~/tcwg-.*/)) || (target==label)
        sequential: false
    wrappers:
        - timeout:
            timeout: 1200
        - timestamps
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
        - build-name:
            name: '#${BUILD_NUMBER}-${displaytag}'
    builders:
        - shell: |
            #!/bin/bash
            set -ex
            ./jenkins-scripts/docker-run.sh \
              --label $label \
              --node $NODE_NAME \
              --distro $build_container_tag \
              $(case "$target" in qemu-*) echo "--qemu $target" ;; esac) \
              --dryrun "$dryrun" \
              -- ./jenkins-scripts/tcwg-buildfarm.sh \
              --label "$label" \
              --target "$target" \
              --BUILD_NUMBER "$BUILD_NUMBER" \
              --JOB_NAME "$JOB_NAME" \
              --NODE_NAME "$NODE_NAME" \
              --WORKSPACE "$WORKSPACE" \
              --override "$override" \
              --host_x86_64_languages "$host_x86_64_languages" \
              --host_aarchXX_languages "$host_aarchXX_languages" \
              --runtests "$runtests" \
              --send_results_to "$send_results_to" \
              --try_bootstrap "$try_bootstrap" \
              --host_x86_64_excludecheck "$host_x86_64_excludecheck" \
              --host_aarchXX_excludecheck "$host_aarchXX_excludecheck" \
              --extraconfig "$extraconfig" \
              --rebuild "$rebuild" \
              --log_name "$log_name" \
              --dont_fail "$dont_fail" \
              --log_server "$log_server" \
              --abe_branch "$abe_branch" \
              --test_container_tag "$test_container_tag" \
              --binaries "$binaries" \
              --dryrun "$dryrun"
      
              # There seems to be a bug in glibc tests, leading a huge
              #  cert.out file in crypt/. Remove it to avoid disk full
              #  issues.
              ./jenkins-scripts/docker-run.sh \
              --label $label \
              --node $NODE_NAME \
              --distro $build_container_tag \
              $(case "$target" in qemu-*) echo "--qemu $target" ;; esac) \
              --dryrun "$dryrun" \
              -- find $WORKSPACE/_build/builds -name cert.out -ls -delete

    publishers:
        - archive:
            artifacts: 'artifacts/*'
            latest-only: false
        - workspace-cleanup:
            clean-if:
                - success: true
                - unstable: false
                - failure: false
                - aborted: false
                - not-built: false
