include:
    - project: 'steam/steam-ci-pipeline'
      file: '/steam-gitlab-ci-common.yml'

    - project: 'steam/steam-ci-pipeline'
      file: '/steam-gitlab-ci-pipeline.yml'

variables:
    BUILD_IMAGE: registry.gitlab.steamos.cloud/steamrt/scout/sdk:beta
    STEAM_CI_USE_BINARIES_FROM: autopkgtest
    STEAM_CI_DEPENDENCIES: >-
        debhelper
        glslang-tools
        gtk-doc-tools
        libelf-dev
        libegl1-mesa-dev
        libgl1-mesa-dev
        libgles2-mesa-dev
        libglib2.0-dev
        libjson-glib-dev
        libtheora-dev
        libva-dev
        libvdpau-dev
        libvulkan-dev
        libx11-dev
        libxcb1-dev
        libxcomposite-dev
        locales
        meson
        pandoc
        python3
        python3.5

    DEBIAN_FRONTEND: noninteractive

    SCOUT_DOCKER_REGISTRY: registry.gitlab.steamos.cloud
    SCOUT_DOCKER_IMAGE: steamrt/scout/sdk:beta
    SCOUT_APT_SOURCES_FILE: ''
    DEVEL_DOCKER_REGISTRY: ''
    DEVEL_DOCKER_IMAGE: ''
    # Set non-empty to allow
    CI_ALLOW_MISSING_SOURCES: ''

stages:
    - build
    - test

build:devel:
    stage: build
    tags:
        - docker
        - linux
    rules:
        - if: '$DEVEL_DOCKER_REGISTRY != "" && $DEVEL_DOCKER_IMAGE != ""'
    image: "${DEVEL_DOCKER_REGISTRY}/${DEVEL_DOCKER_IMAGE}"
    script:
        - |
            set -eux

            apt-get -y --no-install-recommends install \
            clang \
            clang-tools \
            ${NULL+}

            meson --werror -Dman=true _build-devel
            ninja -C _build-devel
            ninja -C _build-devel install
            meson test --verbose -C _build-devel

            export CC=clang
            export CXX=clang++

            meson \
                -Db_lundef=false \
                -Db_sanitize=address,undefined \
                --werror \
                _build-clang-asan
            ninja -C _build-clang-asan
            ninja -C _build-clang-asan scan-build
            ninja -C _build-clang-asan install
            meson test --verbose -C _build-clang-asan

    artifacts:
        paths:
            - _build-devel/meson-logs/*.txt
            - _build-clang-asan/meson-logs/*.txt

build:scout:
    stage: build
    tags:
        - docker
        - linux
    image: "${SCOUT_DOCKER_REGISTRY}/${SCOUT_DOCKER_IMAGE}"
    script:
        - |
            set -eux

            if [ -n "${SCOUT_APT_SOURCES_FILE}" ]; then
                cp "${SCOUT_APT_SOURCES_FILE}" /etc/apt/sources.list
                echo >> /etc/apt/sources.list

                if [ -n "${STEAM_CI_EXTRA_APT_SOURCES-}" ]; then
                  echo "${STEAM_CI_EXTRA_APT_SOURCES}" | while read -r first rest; do
                    if [ "x$first" = xboth ]; then
                      echo "deb $rest" >> /etc/apt/sources.list
                      echo "deb-src $rest" >> /etc/apt/sources.list
                    else
                      echo "$first $rest" >> /etc/apt/sources.list
                    fi
                  done
                fi

                apt-get -y update
            fi

            # g++ 4.6 is too old (see also debian/rules)
            export CXX=g++-4.8

            meson \
              --prefix="$(pwd)/_build-scout/prefix" \
              -Dsrcdir=src \
              --werror \
              _build-scout
            ninja -C _build-scout
            G_MESSAGES_DEBUG=all meson test --verbose -C _build-scout
            ninja -C _build-scout install

    artifacts:
        paths:
            - _build-scout/meson-logs/*.txt

autopkgtest:
    stage: test
    needs:
        - build
    variables:
        STEAM_CI_INSTALL_SCRIPT: |
            # Workaround for the build regression described in !88
            apt-get -y remove libsteam-runtime-tools-0-helpers

# vim:set sw=4 sts=4 et:
