# Linux-specific builder configurations and build commands

## Base configurations
.linux:
    variables:
        GIT_CLONE_PATH: $CI_BUILDS_DIR/kitware-lidarview-ci
        GIT_SUBMODULE_STRATEGY: none

.ubuntu22:
    extends: .linux
    image: "gitlab.kitware.com:4567/lidarview/lidarview:ci-ubuntu22-20241015"

.ubuntu22_debug:
    extends: .ubuntu22

    variables:
        CMAKE_CONFIGURATION: ubuntu22_debug

.ubuntu22_debug_tidy:
    extends: .ubuntu22_debug

    variables:
        CMAKE_CONFIGURATION: ubuntu22_debug_tidy

## Tags

.linux_builder_tags:
    tags:
        - build
        - docker
        - linux-x86_64
        - lidarview

.linux_tester_tags:
    tags:
        - docker
        - lidarview
        - linux-x86_64

## Linux-specific scripts

.before_script_linux: &before_script_linux
    - .gitlab/ci/cmake.sh
    - .gitlab/ci/ninja.sh
    - export PATH=$PWD/.gitlab:$PWD/.gitlab/cmake/bin:$PATH
    - cmake --version
    - ninja --version
    - "git submodule update --init --recursive || :"
    - git submodule sync --recursive
    - git submodule update --init --recursive --force
    - .gitlab/ci/checkout_trigger_submodule.sh

.cmake_build_linux:
    stage: build

    script:
        - *before_script_linux
        - cmake -S $CI_PROJECT_DIR -B $CI_PROJECT_DIR/build -C .gitlab/ci/configure_$CMAKE_CONFIGURATION.cmake -GNinja
        - cmake --build $CI_PROJECT_DIR/build --parallel 8
    interruptible: true

.cmake_test_linux:
    stage: test

    script:
        - *before_script_linux
        - cp .gitlab/ci/CMakePresets.json $CI_PROJECT_DIR
        - xvfb-run ctest --preset ci_$CMAKE_CONFIGURATION

    interruptible: true

.clang_format_check:
    stage: analyse

    script:
        - *before_script_linux
        - git fetch --all
        - .gitlab/ci/clang_format_check.sh
        - .gitlab/ci/json_schema_check.sh
    allow_failure:
        exit_codes: 1

    interruptible: true

.clang_tidy_check:
    stage: analyse

    script:
        - *before_script_linux
        - git fetch --all
        - cp .clang-tidy $CI_PROJECT_DIR/build
        - .gitlab/ci/clang_tidy_check.sh
    allow_failure:
        exit_codes: 1

    interruptible: true
