# macOS-specific builder configurations and build commands

## Base configurations

.macos:
    variables:
        GIT_CLONE_PATH: "$CI_BUILDS_DIR/paraview-ci-ext/$CI_CONCURRENT_ID"
        # TODO: Factor this out so that each job selects the Xcode version to
        # use so that different versions can be tested in a single pipeline.
        DEVELOPER_DIR: "/Applications/Xcode-16.1.app/Contents/Developer"

### Build and test

.macos_build:
    extends: .macos

    variables:
        # Note that shell runners only support runners with a single
        # concurrency level. We can't use `$CI_CONCURRENCY_ID` because this may
        # change between the build and test stages which CMake doesn't support.
        # Even if we could, it could change if other runners on the machine
        # could run at the same time, so we drop it.
        GIT_CLONE_PATH: "$CI_BUILDS_DIR/paraview-ci"

.macos_arm64_python_qt:
    extends: .macos_build

    variables:
        CMAKE_CONFIGURATION: macos_arm64_python_qt

.macos_x86_64_python_qt:
    extends: .macos_build

    variables:
        CMAKE_CONFIGURATION: macos_x86_64_python_qt

## Tags

.macos_x86_64_builder_tags:
    tags:
        - paraview
        - macos-x86_64
        - shell
        - xcode-16.1
        - nonconcurrent

.macos_arm64_builder_tags:
    tags:
        - paraview
        - macos-arm64
        - shell
        - xcode-16.1
        - nonconcurrent

## macOS-specific scripts

.before_script_macos: &before_script_macos
    - .gitlab/ci/cmake.sh
    - .gitlab/ci/ninja.sh
    - export PATH=$PWD/.gitlab:$PWD/.gitlab/cmake/bin:$PATH
    - cmake --version
    - ninja --version
    # Download Qt
    - cmake -P .gitlab/ci/download_qt.cmake
    - cmake -P .gitlab/ci/download_cdi.cmake
    - export CMAKE_PREFIX_PATH=$PWD/.gitlab/qt:$PWD/.gitlab/cdi
    - git submodule foreach --recursive cmake -P "$PWD/.gitlab/ci/fetch_submodule.cmake"
    - git submodule sync --recursive
    - git submodule update --init --recursive

.cmake_build_macos:
    stage: build
    extends: .warning_policy

    script:
        - *before_script_macos
        - .gitlab/ci/sccache.sh
        # Build and activate the venv
        # - python3 -m venv build/ci-venv
        # - . ./build/ci-venv/bin/activate
        # - pip install -qq -r .gitlab/ci/requirements-phase1.txt
        # - pip install -qq -r .gitlab/ci/requirements-phase2.txt
        # Allow the server to already be running.
        - "sccache --start-server || :"
        - sccache --show-stats
        - ctest -VV -S .gitlab/ci/ctest_configure.cmake
        - ctest -VV -S .gitlab/ci/ctest_build.cmake &> $GIT_CLONE_PATH/compile_output.log
        - sccache --show-stats
        - exec .gitlab/ci/check_warnings.sh .

    interruptible: true
    timeout: 2 hours

.cmake_test_macos:
    stage: test

    script:
        - *before_script_macos
        # Reuse the venv from the build step (avoids version changes between
        # build and testing).
        # - . ./build/ci-venv/bin/activate
        - ctest --output-on-failure -V -S .gitlab/ci/ctest_test.cmake
    interruptible: true
    timeout: 2 hours
