#
# Copyright(c) 2021 ZettaScale Technology and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
# v. 1.0 which is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#

trigger: [ '*' ]
pr: [ '*' ]


variables:
  cyclonedds_uri: '<CycloneDDS><Domain><Internal><EnableExpensiveChecks>rhc,whc</EnableExpensiveChecks><LivelinessMonitoring>true</LivelinessMonitoring></Internal><Tracing><Verbosity>config</Verbosity><OutputFile>stderr</OutputFile></Tracing></Domain></CycloneDDS>'

jobs:
- job: BuildAndTest
  pool:
    vmImage: $(image)
  strategy:
    matrix:
      #gcc-12.2 is the first version of gcc's static analyzer that accepts this code
      #without -Wno-analyzer-malloc-leak without any false positives.  Ubuntu is far
      #behind in gcc versions, and so falling back to macOS is the most pragmatic
      #option at this time.
      #'Ubuntu 22.04 LTS with GCC 12 (Debug, x86_64)':
      #  image: ubuntu-22.04
      #  analyzer: on
      #  # not enabling "undefined" because of some false positives
      #  sanitizer: address
      #  cc: gcc-12
      #  coverage: on
      'Ubuntu 20.04 LTS with GCC 10 (Release, x86_64)':
        image: ubuntu-20.04
        build_type: Release
        sanitizer: undefined
        cc: gcc-10
      'Ubuntu 22.04 LTS with GCC 10 (Debug, x86_64, Iceoryx)':
        image: ubuntu-22.04
        #analyzer: on  # disabled for now because of warnings
        sanitizer: address,undefined
        iceoryx: on
        cc: gcc-10
        coverage: on
      'Ubuntu 22.04 LTS with GCC 10 (Release, x86_64)':
        image: ubuntu-22.04
        build_type: Release
        sanitizer: undefined
        cc: gcc-10
      'Ubuntu 22.04 LTS with GCC 10 (Debug, x86_64, security only)':
        image: ubuntu-22.04
        sanitizer: address,undefined
        ssl: off
        lifespan: off
        deadline: off
        type_discovery: off
        topic_discovery: off
        idlc_xtests: off # temporary disabled because of passing -t option to idlc in this test for recursive types
        cc: gcc-10
      'Ubuntu 22.04 LTS with GCC 10 (Debug, x86_64, no tests)':
        image: ubuntu-22.04
        cc: gcc-10
        testing: off
        idlc_xtests: off
      'Ubuntu 22.04 LTS with Clang 12 (Debug, x86_64)':
        image: ubuntu-22.04
        analyzer: on
        sanitizer: address,undefined
        cc: clang-12
      'Ubuntu 22.04 LTS with Clang 12 (Debug, x86_64, no security)':
        image: ubuntu-22.04
        sanitizer: address,undefined
        security: off
        cc: clang-12
      'Ubuntu 22.04 LTS with Clang 12 (Release, x86_64, no topic discovery)':
        image: ubuntu-22.04
        build_type: Release
        sanitizer: undefined
        topic_discovery: off
        idlc_xtests: off # temporary disabled because of passing -t option to idlc in this test for recursive types
        cc: clang-12
      'macOS 11 with Clang 12 (Debug, x86_64)':
        image: macOS-11
        sanitizer: address,undefined
        deadline_update_skip: on
        cc: clang
      'macOS 11 with Clang 12 (Release, x86_64)':
        image: macOS-11
        build_type: Release
        sanitizer: undefined
        deadline_update_skip: on
        cc: clang
      'macOS 11 with Clang 13 (Release, x86_64)':
        image: macOS-11
        build_type: Release
        sanitizer: undefined
        deadline_update_skip: on
        cc: clang
        coverage: on
      'macOS 12 with gcc 12 (Debug, analyzer, x86_64)':
        image: macOS-12
        sanitizer: undefined
        deadline_update_skip: on
        cc: gcc-12
        analyzer: on
      # 32-bit Windows: without SSL/security because Chocolateley only provides 64-bit OpenSSL
      'Windows 2019 with Visual Studio 2019 (Visual Studio 2017, Debug, x86, no security)':
        arch: x86
        image: windows-2019
        ssl: off
        security: off
        idlc_xtests: off
        generator: 'Visual Studio 16 2019'
        toolset: v141
      'Windows 2019 with Visual Studio 2019 (Debug, x86_64)':
        image: windows-2019
        idlc_xtests: off
        generator: 'Visual Studio 16 2019'
      'Windows 2019 with Visual Studio 2019 (Release, x86_64, no tests)':
        image: windows-2019
        build_type: Release
        testing: off
        idlc_xtests: off
        generator: 'Visual Studio 16 2019'
      'Windows 2019 with Visual Studio 2019 (RelWithDebInfo, x86_64)':
        image: windows-2019
        build_type: RelWithDebInfo
        idlc_xtests: off
        generator: 'Visual Studio 16 2019'
      #'Windows 2019 with GCC 10 (Debug, x86_64)':
      #  image: windows-2019
      #  build_type: Debug
      #  idlc_xtests: off
      #  generator: 'MinGW Makefiles'
      #  cc: 'C:/msys64/mingw64/bin/gcc.exe'
      #  cxx: 'C:/msys64/mingw64/bin/g++.exe'

  steps:
    - template: /.azure/templates/build-test.yml

- job: CoverageAndTestsReport
  dependsOn: BuildAndTest
  condition: succeededOrFailed()  # Always run, even when failed tests, because they should be reported in the dasboard of course!
  pool:
    vmImage: ubuntu-20.04
  steps:
  - bash: |
      mkdir coverage
  - task: DownloadPipelineArtifact@2
    inputs:
      path: coverage
    displayName: Download Coverage
  - task: UsePythonVersion@0
  - bash: |
      python -m pip install gcovr==5.0 --user --upgrade
      ls coverage
      gcovr -a coverage/**/*.json --xml-pretty --output coverage.xml
    displayName: Combine coverage reports
  - task: PublishCodeCoverageResults@1
    displayName: Publish Cobertura Coverage Report
    inputs:
      codeCoverageTool: Cobertura
      summaryFileLocation: coverage.xml
