## @file
# Azure Pipeline build file for building a platform.
#
# Platform: OVMF
# OS: Ubuntu
# Toolchain: GCC5
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
trigger:
  - master
  - stable/*
pr:
  - master
  - stable/*

variables:
  - template: ../../../.azurepipelines/templates/defaults.yml

jobs:
  - job: Platform_CI
    variables:
      package: 'OvmfPkg'
      vm_image: 'ubuntu-22.04'
      should_run: true
      run_flags: "MAKE_STARTUP_NSH=TRUE QEMU_HEADLESS=TRUE"

    #Use matrix to speed up the build process
    strategy:
        matrix:
          OVMF_IA32_DEBUG:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32"
            Build.Flags: ""
            Build.Target: "DEBUG"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_IA32_RELEASE:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32"
            Build.Flags: ""
            Build.Target: "RELEASE"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_IA32_NOOPT:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32"
            Build.Flags: ""
            Build.Target: "NOOPT"
            Run.Flags: $(run_flags)
            Run: $(should_run)

          OVMF_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_X64_RELEASE:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "RELEASE"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_X64_NOOPT:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "NOOPT"
            Run.Flags: $(run_flags)
            Run: $(should_run)

          OVMF_IA32X64_DEBUG:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32,X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_IA32X64_RELEASE:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32,X64"
            Build.Flags: ""
            Build.Target: "RELEASE"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_IA32X64_NOOPT:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32,X64"
            Build.Flags: ""
            Build.Target: "NOOPT"
            Run.Flags: $(run_flags)
            Run: $(should_run)

          OVMF_IA32X64_FULL_DEBUG:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32,X64"
            Build.Flags: "BLD_*_SECURE_BOOT_ENABLE=1 BLD_*_SMM_REQUIRE=1 BLD_*_TPM2_ENABLE=1 BLD_*_NETWORK_TLS_ENABLE=1 BLD_*_NETWORK_IP6_ENABLE=1 BLD_*_NETWORK_HTTP_BOOT_ENABLE=1"
            Build.Target: "DEBUG"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          OVMF_IA32X64_FULL_RELEASE:
            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
            Build.Arch: "IA32,X64"
            Build.Flags: "BLD_*_SECURE_BOOT_ENABLE=1 BLD_*_SMM_REQUIRE=1 BLD_*_TPM2_ENABLE=1 BLD_*_NETWORK_TLS_ENABLE=1 BLD_*_NETWORK_IP6_ENABLE=1 BLD_*_NETWORK_HTTP_BOOT_ENABLE=1"
            Build.Target: "RELEASE"
            Run.Flags: $(run_flags)
            Run: $(should_run)
          # This currently creates a very large image which is too big for the FDF declared range,
          # skip this build for now.
          #
          # OVMF_IA32X64_FULL_NOOPT:
          #   Build.File: "$(package)/PlatformCI/PlatformBuild.py"
          #   Build.Arch: "IA32,X64"
          #   Build.Flags: "BLD_*_SECURE_BOOT_ENABLE=1 BLD_*_SMM_REQUIRE=1 BLD_*_TPM2_ENABLE=1 BLD_*_NETWORK_TLS_ENABLE=1 BLD_*_NETWORK_IP6_ENABLE=1 BLD_*_NETWORK_HTTP_BOOT_ENABLE=1"
          #   Build.Target: "NOOPT"
          #   Run.Flags: $(run_flags)
          #   Run: $(should_run)

          AMDSEV_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/AmdSevBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # restricted + stripped down build
            # can't boot to uefi shell -> skip test
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          BHYVE_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/BhyveBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # this build is for freebsd bhyve not qemu-kvm
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          CLOUDHV_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/CloudHvBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # this build is for cloud-hypervisor not qemu-kvm
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          MICROVM_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/MicrovmBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # no storage supported by microvm build
            # can't boot to uefi shell -> skip test
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          OVMF_XEN_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/XenBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # this build is for xen not qemu-kvm
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          INTELTDX_X64_DEBUG:
            Build.File: "$(package)/PlatformCI/IntelTdxBuild.py"
            Build.Arch: "X64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # no storage supported by microvm build
            # can't boot to uefi shell -> skip test
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

          QEMU_RISCV64_DEBUG:
            Build.File: "$(package)/PlatformCI/QemuBuild.py"
            Build.Arch: "RISCV64"
            Build.Flags: ""
            Build.Target: "DEBUG"
            # this build is for RISC-V qemu virt not qemu-kvm
            Run.Flags: "QEMU_SKIP=TRUE"
            Run: $(should_run)

    workspace:
      clean: all

    pool:
      vmImage: $(vm_image)

    container: ${{ variables.default_linux_image }}

    steps:
    - template: ../../../.azurepipelines/templates/platform-build-run-steps.yml
      parameters:
        tool_chain_tag: GCC5
        build_pkg: $(package)
        build_target: $(Build.Target)
        build_arch: $(Build.Arch)
        build_file: $(Build.File)
        build_flags: $(Build.Flags)
        run_flags: $(Run.Flags)
        usePythonVersion: '' # use Python from the container image