.build-tmpl: &build
  stage: build
  image: registry.gitlab.com/xen-project/xen/${CONTAINER}
  script:
    - ./automation/scripts/build 2>&1 | tee build.log
  artifacts:
    paths:
      - binaries/
      - xen-config
      - xen-cppcheck.txt
      - '*.log'
      - '*/*.log'
    when: always
  needs: []

.gcc-tmpl:
  variables: &gcc
    CC: gcc
    CXX: g++

.clang-tmpl:
  variables: &clang
    CC: clang
    CXX: clang++
    clang: y

.x86-64-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: x86_64
  tags:
    - x86_64

.x86-64-build:
  extends: .x86-64-build-tmpl
  variables:
    debug: n

.x86-64-build-debug:
  extends: .x86-64-build-tmpl
  variables:
    debug: y

.x86-32-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: x86_32
  tags:
    - x86_32

.x86-32-build:
  extends: .x86-32-build-tmpl
  variables:
    debug: n

.x86-32-build-debug:
  extends: .x86-32-build-tmpl
  variables:
    debug: y

.gcc-x86-64-build:
  extends: .x86-64-build
  variables:
    <<: *gcc

.gcc-x86-64-build-debug:
  extends: .x86-64-build-debug
  variables:
    <<: *gcc

.gcc-x86-32-build:
  extends: .x86-32-build
  variables:
    <<: *gcc

.gcc-x86-32-build-debug:
  extends: .x86-32-build-debug
  variables:
    <<: *gcc

.clang-x86-64-build:
  extends: .x86-64-build
  variables:
    <<: *clang

.clang-x86-64-build-debug:
  extends: .x86-64-build-debug
  variables:
    <<: *clang

.clang-x86-32-build:
  extends: .x86-32-build
  variables:
    <<: *clang

.clang-x86-32-build-debug:
  extends: .x86-32-build-debug
  variables:
    <<: *clang

.arm32-cross-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: arm32
  tags:
    - arm64

.arm32-cross-build:
  extends: .arm32-cross-build-tmpl
  variables:
    debug: n

.arm32-cross-build-debug:
  extends: .arm32-cross-build-tmpl
  variables:
    debug: y

.gcc-arm32-cross-build:
  extends: .arm32-cross-build
  variables:
    <<: *gcc

.gcc-arm32-cross-build-debug:
  extends: .arm32-cross-build-debug
  variables:
    <<: *gcc

.arm64-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: arm64
  tags:
    - arm64

.arm64-build:
  extends: .arm64-build-tmpl
  variables:
    debug: n

.arm64-build-debug:
  extends: .arm64-build-tmpl
  variables:
    debug: y

.gcc-arm64-build:
  extends: .arm64-build
  variables:
    <<: *gcc

.gcc-arm64-build-debug:
  extends: .arm64-build-debug
  variables:
    <<: *gcc

.riscv64-cross-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: riscv64
  tags:
    - x86_64

.riscv64-cross-build:
  extends: .riscv64-cross-build-tmpl
  variables:
    debug: n

.riscv64-cross-build-debug:
  extends: .riscv64-cross-build-tmpl
  variables:
    debug: y

.gcc-riscv64-cross-build:
  extends: .riscv64-cross-build
  variables:
    <<: *gcc

.gcc-riscv64-cross-build-debug:
  extends: .riscv64-cross-build-debug
  variables:
    <<: *gcc

.ppc64le-cross-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: ppc64
  tags:
    - x86_64

.ppc64le-cross-build:
  extends: .ppc64le-cross-build-tmpl
  variables:
    debug: n

.ppc64le-cross-build-debug:
  extends: .ppc64le-cross-build-tmpl
  variables:
    debug: y

.gcc-ppc64le-cross-build:
  extends: .ppc64le-cross-build
  variables:
    <<: *gcc

.gcc-ppc64le-cross-build-debug:
  extends: .ppc64le-cross-build-debug
  variables:
    <<: *gcc

.yocto-test:
  stage: build
  image: registry.gitlab.com/xen-project/xen/${CONTAINER}
  script:
    - ./automation/build/yocto/build-yocto.sh -v --log-dir=./logs --xen-dir=`pwd` ${YOCTO_BOARD} ${YOCTO_OUTPUT}
  variables:
    YOCTO_VERSION: kirkstone
    CONTAINER: yocto:${YOCTO_VERSION}-${YOCTO_BOARD}-${YOCTO_HOST}
  artifacts:
    paths:
      - 'logs/*'
      - binaries/
    when: always
  needs: []

.yocto-test-arm64:
  extends: .yocto-test
  variables:
    YOCTO_HOST: arm64v8
  tags:
    - arm64

# This is not used by any test job as we only run Yocto on arm based machines.
# Keep it here so that someone having x86 hardware can easily add jobs.
.yocto-test-x86-64:
  extends: .yocto-test
  variables:
    YOCTO_HOST: amd64
  tags:
    - x86_64

.x86-64-cross-build-tmpl:
  <<: *build
  variables:
    XEN_TARGET_ARCH: x86_64
  tags:
    - arm64

.x86-64-cross-build:
  extends: .x86-64-cross-build-tmpl
  variables:
    debug: n

.gcc-x86-64-cross-build:
  extends: .x86-64-cross-build
  variables:
    <<: *gcc

## Test artifacts common

.test-jobs-artifact-common:
  stage: build
  needs: []

# Arm test artifacts

alpine-3.18-arm64-rootfs-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/alpine:3.18-arm64v8
  script:
    - mkdir binaries && cp /initrd.tar.gz binaries/initrd.tar.gz
  artifacts:
    paths:
      - binaries/initrd.tar.gz
  tags:
    - arm64

kernel-5.19-arm64-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/kernel:5.19-arm64v8
  script:
    - mkdir binaries && cp /Image binaries/Image
  artifacts:
    paths:
      - binaries/Image
  tags:
    - arm64

qemu-system-aarch64-6.0.0-arm64-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/qemu-system-aarch64:6.0.0-arm64v8
  script:
    - mkdir binaries && cp /qemu-system-aarch64 binaries/qemu-system-aarch64
  artifacts:
    paths:
      - binaries/qemu-system-aarch64
  tags:
    - arm64

qemu-system-aarch64-6.0.0-arm32-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/qemu-system-aarch64:6.0.0-arm64v8
  script:
    - mkdir binaries && cp /qemu-system-arm binaries/qemu-system-arm
  artifacts:
    paths:
      - binaries/qemu-system-arm
  tags:
    - arm64

# ppc64 test artifacts

qemu-system-ppc64-8.1.0-ppc64-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/qemu-system-ppc64:8.1.0-ppc64
  script:
    - mkdir binaries && cp /qemu-system-ppc64 /skiboot.lid binaries/
  artifacts:
    paths:
      - binaries/qemu-system-ppc64
      - binaries/skiboot.lid
  tags:
    - x86_64

# x86_64 test artifacts

alpine-3.18-rootfs-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/alpine:3.18
  script:
    - mkdir binaries && cp /initrd.tar.gz binaries/initrd.tar.gz
  artifacts:
    paths:
      - binaries/initrd.tar.gz
  tags:
    - x86_64

kernel-6.1.19-export:
  extends: .test-jobs-artifact-common
  image: registry.gitlab.com/xen-project/xen/tests-artifacts/kernel:6.1.19
  script:
    - mkdir binaries && cp /bzImage binaries/bzImage
  artifacts:
    paths:
      - binaries/bzImage
  tags:
    - x86_64

# Jobs below this line

# Build jobs needed for tests

alpine-3.18-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: alpine:3.18

alpine-3.18-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: alpine:3.18
    BUILD_QEMU_XEN: y

debian-stretch-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: debian:stretch

debian-bookworm-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: debian:bookworm

# Arm32 cross-build

debian-bookworm-gcc-arm32:
  extends: .gcc-arm32-cross-build
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y

debian-bookworm-gcc-arm32-debug:
  extends: .gcc-arm32-cross-build-debug
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y

debian-bookworm-gcc-arm32-randconfig:
  extends: .gcc-arm32-cross-build
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y
    RANDCONFIG: y

debian-bookworm-gcc-arm32-debug-randconfig:
  extends: .gcc-arm32-cross-build-debug
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y
    RANDCONFIG: y

debian-bookworm-gcc-arm32-staticmem:
  extends: .gcc-arm32-cross-build
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y
    EXTRA_XEN_CONFIG: |
      CONFIG_EXPERT=y
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y

debian-bookworm-gcc-arm32-debug-staticmem:
  extends: .gcc-arm32-cross-build-debug
  variables:
    CONTAINER: debian:bookworm-arm64v8-arm32-gcc
    HYPERVISOR_ONLY: y
    EXTRA_XEN_CONFIG: |
      CONFIG_EXPERT=y
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y

# Arm builds

debian-bookworm-gcc-arm64:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: debian:bookworm-arm64v8

debian-bookworm-gcc-debug-arm64:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: debian:bookworm-arm64v8

debian-bookworm-gcc-arm64-randconfig:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: debian:bookworm-arm64v8
    RANDCONFIG: y

debian-bookworm-gcc-debug-arm64-randconfig:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: debian:bookworm-arm64v8
    RANDCONFIG: y

alpine-3.18-gcc-arm64:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: alpine:3.18-arm64v8

alpine-3.18-gcc-debug-arm64:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: alpine:3.18-arm64v8

alpine-3.18-gcc-arm64-randconfig:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: alpine:3.18-arm64v8
    RANDCONFIG: y

alpine-3.18-gcc-debug-arm64-randconfig:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: alpine:3.18-arm64v8
    RANDCONFIG: y

alpine-3.18-gcc-arm64-staticmem:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_EXPERT=y
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y

alpine-3.18-gcc-debug-arm64-staticmem:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_EXPERT=y
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y

alpine-3.18-gcc-arm64-static-shared-mem:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y
      CONFIG_STATIC_SHM=y

alpine-3.18-gcc-debug-arm64-static-shared-mem:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_UNSUPPORTED=y
      CONFIG_STATIC_MEMORY=y
      CONFIG_STATIC_SHM=y

alpine-3.18-gcc-arm64-boot-cpupools:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_EXPERT=y
      CONFIG_UNSUPPORTED=y
      CONFIG_SCHED_NULL=y
      CONFIG_BOOT_TIME_CPUPOOLS=y

alpine-3.18-gcc-debug-arm64-boot-cpupools:
  extends: .gcc-arm64-build-debug
  variables:
    CONTAINER: alpine:3.18-arm64v8
    EXTRA_XEN_CONFIG: |
      CONFIG_BOOT_TIME_CPUPOOLS=y

# RISC-V 64 cross-build
archlinux-current-gcc-riscv64:
  extends: .gcc-riscv64-cross-build
  variables:
    CONTAINER: archlinux:current-riscv64
    KBUILD_DEFCONFIG: tiny64_defconfig
    HYPERVISOR_ONLY: y

archlinux-current-gcc-riscv64-debug:
  extends: .gcc-riscv64-cross-build-debug
  variables:
    CONTAINER: archlinux:current-riscv64
    KBUILD_DEFCONFIG: tiny64_defconfig
    HYPERVISOR_ONLY: y

archlinux-current-gcc-riscv64-randconfig:
  extends: .gcc-riscv64-cross-build
  variables:
    CONTAINER: archlinux:current-riscv64
    KBUILD_DEFCONFIG: tiny64_defconfig
    RANDCONFIG: y
    EXTRA_FIXED_RANDCONFIG:
      CONFIG_COVERAGE=n

archlinux-current-gcc-riscv64-debug-randconfig:
  extends: .gcc-riscv64-cross-build-debug
  variables:
    CONTAINER: archlinux:current-riscv64
    KBUILD_DEFCONFIG: tiny64_defconfig
    RANDCONFIG: y
    EXTRA_FIXED_RANDCONFIG:
      CONFIG_COVERAGE=n

# Power cross-build
debian-bullseye-gcc-ppc64le:
  extends: .gcc-ppc64le-cross-build
  variables:
    CONTAINER: debian:bullseye-ppc64le
    KBUILD_DEFCONFIG: ppc64_defconfig
    HYPERVISOR_ONLY: y

debian-bullseye-gcc-ppc64le-debug:
  extends: .gcc-ppc64le-cross-build-debug
  variables:
    CONTAINER: debian:bullseye-ppc64le
    KBUILD_DEFCONFIG: ppc64_defconfig
    HYPERVISOR_ONLY: y

# Yocto test jobs
yocto-qemuarm64:
  extends: .yocto-test-arm64
  variables:
    YOCTO_BOARD: qemuarm64
  when: manual

yocto-qemuarm:
  extends: .yocto-test-arm64
  variables:
    YOCTO_BOARD: qemuarm
    YOCTO_OUTPUT: --copy-output
  when: manual

yocto-qemux86-64:
  extends: .yocto-test-arm64
  variables:
    YOCTO_BOARD: qemux86-64
  when: manual

# Cppcheck analysis jobs

debian-bookworm-gcc-cppcheck:
  extends: .gcc-x86-64-cross-build
  variables:
    CONTAINER: debian:bookworm-cppcheck
    CROSS_COMPILE: /usr/bin/x86_64-linux-gnu-
    CPPCHECK: y
    HYPERVISOR_ONLY: y

debian-bookworm-gcc-arm32-cppcheck:
  extends: .gcc-arm32-cross-build
  variables:
    CONTAINER: debian:bookworm-cppcheck
    CROSS_COMPILE: /usr/bin/arm-linux-gnueabihf-
    CPPCHECK: y
    HYPERVISOR_ONLY: y

debian-bookworm-gcc-arm64-cppcheck:
  extends: .gcc-arm64-build
  variables:
    CONTAINER: debian:bookworm-cppcheck
    CPPCHECK: y
    HYPERVISOR_ONLY: y

# Build jobs not needed for tests

alpine-3.18-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: alpine:3.18

alpine-3.18-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: alpine:3.18

archlinux-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: archlinux:current
  allow_failure: true

archlinux-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: archlinux:current
  allow_failure: true

centos-7-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: centos:7

centos-7-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: centos:7

debian-stretch-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: debian:stretch

debian-stretch-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: debian:stretch

debian-stretch-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: debian:stretch

debian-stretch-32-clang-debug:
  extends: .clang-x86-32-build-debug
  variables:
    CONTAINER: debian:stretch-i386

debian-stretch-32-gcc-debug:
  extends: .gcc-x86-32-build-debug
  variables:
    CONTAINER: debian:stretch-i386

debian-buster-gcc-ibt:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: debian:buster-gcc-ibt
    RANDCONFIG: y
    EXTRA_FIXED_RANDCONFIG: |
      CONFIG_XEN_IBT=y

debian-bookworm-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: debian:bookworm

debian-bookworm-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: debian:bookworm

debian-bookworm-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: debian:bookworm

debian-bookworm-gcc-randconfig:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: debian:bookworm
    RANDCONFIG: y

debian-bookworm-gcc-debug-randconfig:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: debian:bookworm
    RANDCONFIG: y

debian-bookworm-32-clang-debug:
  extends: .clang-x86-32-build-debug
  variables:
    CONTAINER: debian:bookworm-i386

debian-bookworm-32-gcc-debug:
  extends: .gcc-x86-32-build-debug
  variables:
    CONTAINER: debian:bookworm-i386

fedora-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: fedora:29

fedora-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: fedora:29

# Ubuntu Trusty's Clang is 3.4 while Xen requires 3.5

ubuntu-trusty-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: ubuntu:trusty

ubuntu-trusty-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:trusty

ubuntu-xenial-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: ubuntu:xenial

ubuntu-xenial-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:xenial

ubuntu-xenial-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: ubuntu:xenial

ubuntu-xenial-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:xenial

ubuntu-bionic-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: ubuntu:bionic

ubuntu-bionic-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:bionic

ubuntu-bionic-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: ubuntu:bionic

ubuntu-bionic-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:bionic

ubuntu-focal-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: ubuntu:focal

ubuntu-focal-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:focal

ubuntu-focal-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: ubuntu:focal

ubuntu-focal-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: ubuntu:focal

opensuse-leap-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: suse:opensuse-leap

opensuse-leap-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: suse:opensuse-leap

opensuse-leap-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: suse:opensuse-leap

opensuse-leap-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: suse:opensuse-leap

opensuse-tumbleweed-clang:
  extends: .clang-x86-64-build
  variables:
    CONTAINER: suse:opensuse-tumbleweed
  allow_failure: true

opensuse-tumbleweed-clang-debug:
  extends: .clang-x86-64-build-debug
  variables:
    CONTAINER: suse:opensuse-tumbleweed
  allow_failure: true

opensuse-tumbleweed-gcc:
  extends: .gcc-x86-64-build
  variables:
    CONTAINER: suse:opensuse-tumbleweed
  allow_failure: true

opensuse-tumbleweed-gcc-debug:
  extends: .gcc-x86-64-build-debug
  variables:
    CONTAINER: suse:opensuse-tumbleweed
  allow_failure: true
