# Linux-specific builder configurations and build commands

## Base images

### CentOS
#
# CentOS 7 is the primary deployment platform. This gains us maximum
# compatibility with many Linux distros while also providing easy ways to get
# newer compilers.

.linux:
    variables:
        GIT_CLONE_PATH: $CI_BUILDS_DIR/gitlab-kitware-sciviz-ci
        GIT_SUBMODULE_STRATEGY: none

.centos7:
    extends: .linux
    image: "kitware/paraview:ci-centos7-20201103"

    variables:
        LAUNCHER: "scl enable devtoolset-7 --"

.fedora35:
    extends: .linux
    image: "kitware/paraview:ci-fedora35-20240723"

.el7_mindeps:
    extends: .linux
    image: "kitware/paraview:ci-el7-mindeps-20240521"

    variables:
        LAUNCHER: "scl enable rh-python38 --"

.el8_icc:
    extends: .linux
    image: "kitware/paraview:ci-el8-icc-20240521"

    variables:
        CC: icx
        CXX: icpx
        FC: ifx

.fedora_mpich_addon:
    variables:
        MODULES: mpi/mpich-x86_64
        # Even with SHM size of 512m, SIGBUS still happened. Let's just use the
        # network instead for reliability.
        # https://wiki.mpich.org/mpich/index.php/Frequently_Asked_Questions#Q:_Why_MPI_Put_raises_SIGBUS_error_inside_docker.3F
        MPIR_CVAR_NOLOCAL: 1

.fedora_openmpi_addon:
    variables:
        # Needed to work with OpenMPI
        OMPI_ALLOW_RUN_AS_ROOT: 1
        OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1
        MODULES: mpi/openmpi-x86_64

.el8_intelmpi_addon:
    variables:
        CMAKE_PREFIX_PATH: /usr/local/intelmpi
        # Disable shared memory; it doesn't work so well inside of containers.
        I_MPI_SHM: disable

.el7_mindeps_shared_mpi_python:
    extends:
        - .el7_mindeps
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: el7_shared_mindeps_mpi_python

.el8_shared_icc_mpi_python:
    extends:
        - .el8_icc
        - .el8_intelmpi_addon

    variables:
        CMAKE_CONFIGURATION: el8_shared_icc_mpi_python

.fedora35_static_mpi_offscreen_osmesa_python:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_static_mpi_offscreen_osmesa_python

.fedora35_shared_mpi_core:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_shared_mpi_core

.fedora35_shared_mpi_python_core:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_shared_mpi_python_core

.fedora35_shared_debug_mpi_python_qt:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_shared_mpi_python_qt
        CMAKE_BUILD_TYPE: Debug

.fedora35_shared_mpi_python_qt_vtkmoverride:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_shared_mpi_python_qt_vtkmoverride

.fedora35_tidy:
    extends:
        - .fedora35
        - .fedora_mpich_addon

    variables:
        CMAKE_CONFIGURATION: fedora35_shared_mpi_python_qt_tidy

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

.linux_tester_tags:
    tags:
        - docker
        - paraview
        - linux-x86_64
        - x11-gnome

## Linux-specific scripts

.before_script_linux: &before_script_linux
    - .gitlab/ci/cmake.sh
    - .gitlab/ci/cmake.sh mindeps
    - .gitlab/ci/ninja.sh
    - .gitlab/ci/doxygen.sh
    - .gitlab/ci/sccache.sh
    - export PATH=$PWD/.gitlab:$PWD/.gitlab/cmake/bin:$PWD/.gitlab/doxygen/bin:$PATH
    - cmake --version
    - ninja --version
    - doxygen --version
    - "git submodule update --init --recursive || :"
    - git submodule foreach --recursive cmake -P "$PWD/.gitlab/ci/fetch_submodule.cmake"
    - git submodule sync --recursive
    - git submodule update --init --recursive
    # Load any modules that may be necessary.
    - '[ -n "$MODULES" ] && . /etc/profile.d/modules.sh && module load $MODULES'
    # Enable the Intel compiler if required.
    - '[ "$CC" = "icx" ] && source /opt/intel/oneapi/setvars.sh || true'

.cmake_build_linux:
    stage: build
    extends: .warning_policy

    script:
        - *before_script_linux
        - .gitlab/ci/clang-tidy-cache.sh
        - sccache --start-server
        - sccache --show-stats
        - $LAUNCHER ctest -VV -S .gitlab/ci/ctest_configure.cmake
        - $LAUNCHER 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

.cmake_test_linux:
    stage: test

    script:
        - *before_script_linux
        # For libnvindex.so
        - export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
        - ctest -V --output-on-failure -S .gitlab/ci/ctest_test.cmake

    interruptible: true

.cmake_translations_linux:
    stage: test
    environment:
      name: translations

    script:
        - echo "Pushing translation artifacts"
        - git config --global user.email "kwrobot+paraview-ci@kitware.com"
        - git config --global user.name "gitlab-ci"
        - git clone https://gitlab.kitware.com/paraview/paraview-translations.git
        - cmake -DNEW_TRANSLATIONS_DIR=./translations -DTRANSLATIONS_DIR=./paraview-translations/en/ -P .gitlab/ci/update_translations.cmake
        - cd paraview-translations
        - cmake -B build -DQt5_DIR=/lib64/cmake/Qt5
        - cmake --build ./build/ --target files_update
        - if [ -n "$( git status -s )" ]; then git add -A; git commit -m "New strings from $CI_COMMIT_SHORT_SHA"; git push https://token:$PARAVIEW_TRANSLATIONS_TOKEN@gitlab.kitware.com/paraview/paraview-translations.git; else echo "No new string to push to paraview-translations for $CI_COMMIT_SHORT_SHA"; fi

    interruptible: true

.spack_build_linux:
    stage: build

    variables:
        # This is needed as `configure` on certain packages fails when run as
        # root
        FORCE_UNSAFE_CONFIGURE: 1

        spack: "$CI_BUILDS_DIR/spack/bin/spack -C $CI_PROJECT_DIR/build/spack"
        paraview_spec: "paraview+osmesa^mesa~glx^mpich"

    before_script:
        - .gitlab/ci/sccache.sh
        - .gitlab/ci/cmake.sh
        - export PATH=$PWD/.gitlab:$PWD/.gitlab/cmake/bin:$PATH
        - cmake --version
        - "git submodule update --init --recursive || :"
        - git submodule foreach --recursive cmake -P "$PWD/.gitlab/ci/fetch_submodule.cmake"
        - git submodule sync --recursive
        - git submodule update --init --recursive
        - sccache --start-server
        - sccache --show-stats
        - .gitlab/ci/spack.sh
        - $LAUNCHER $spack repo add $PWD/Utilities/spack/repo
        - $LAUNCHER $spack compiler find
        - $LAUNCHER $spack compiler info gcc@7.3.1
    script:
        - TRACK="Experimental"
        - if [ "$CI_PIPELINE_SOURCE" == "schedule" ] && [ "$CI_PROJECT_PATH" == "paraview/paraview" ]; then TRACK="master-packages" ; fi
        - if [ "$CI_MERGE_REQUEST_ID" ]; then TRACK="merge-requests" ; fi
        - $LAUNCHER $spack spec $paraview_spec
        - $LAUNCHER $spack install --no-check-signature --only dependencies -j $(nproc) $paraview_spec
        - $LAUNCHER $spack clean
        - export dependency_specs=`$LAUNCHER $spack find --format "{name}{@version}{%compiler}"`
        - $LAUNCHER $spack install --no-check-signature -j $(nproc) --cdash-upload-url="http://open.cdash.org/submit.php?project=ParaView" --cdash-track $TRACK --cdash-build="[paraview-spack-$paraview_spec]-$CI_COMMIT_REF_NAME" $paraview_spec
        - eval `$spack load --sh paraview`
        - pvserver --version
        - .gitlab/sccache --show-stats

    interruptible: true
    timeout: 3 hours

.doxygen_build_linux:
    stage: build
    environment:
      name: documentation
      url: https://www.paraview.org/paraview-docs/latest/cxx/

    needs: []

    script:
        - *before_script_linux
        - if [ -n "$RSYNC_SSH_PRIVATE_KEY" ]; then
            chmod 600 $RSYNC_SSH_PRIVATE_KEY;
            MAYBE_SSH_KEY_PATH="-k $RSYNC_SSH_PRIVATE_KEY";
          fi
        - if [ -n "$CI_COMMIT_TAG" ]; then
            CURRENT_RELEASE="$CI_COMMIT_TAG";
            MAYBE_UPDATE_LATEST="-u";
          fi
        - $LAUNCHER cmake -S $GIT_CLONE_PATH -B $GIT_CLONE_PATH/build
            -GNinja
            -DDOCUMENTATION_HTML_TARZ=ON
            -DPARAVIEW_BUILD_DEVELOPER_DOCUMENTATION=ON
            -DPARAVIEW_USE_MPI=ON
            -DPARAVIEW_USE_PYTHON=ON
        - $LAUNCHER cmake --build $GIT_CLONE_PATH/build -j $(nproc) &> $GIT_CLONE_PATH/compile_output.log
        - $LAUNCHER cmake --build $GIT_CLONE_PATH/build --target ParaViewDoc-TGZ &> $GIT_CLONE_PATH/doxygen_output.log
        - $LAUNCHER bash -x $GIT_CLONE_PATH/Utilities/DocsUploader/Scripts/paraview_docs_uploader
            -s "$GIT_CLONE_PATH"
            -b "$GIT_CLONE_PATH/build"
            -w "$GIT_CLONE_PATH"
            -v "$CURRENT_RELEASE"
            $MAYBE_SSH_KEY_PATH
            $MAYBE_UPDATE_LATEST
            &> $GIT_CLONE_PATH/prepare_output.log

    variables:
        CMAKE_PREFIX_PATH: "/usr/lib64/openmpi:$CMAKE_PREFIX_PATH"
        CURRENT_RELEASE: nightly
        MAYBE_SSH_KEY_PATH:
        MAYBE_UPDATE_LATEST:

    interruptible: true
    timeout: 3 hours
