stages:
  - container
  - build
  - pages

variables:
  FDO_UPSTREAM_REPO: 'pipewire/wireplumber'
  # change to build against a different tag or branch of pipewire
  PIPEWIRE_HEAD: 'master'

# ci-templates as of May 1st 2020
.templates_sha: &templates_sha 59de540b620c45739871d1a073d76d5521989d11

include:
  - project: 'freedesktop/ci-templates'
    ref: *templates_sha
    file: '/templates/fedora.yml'

.fedora:
  variables:
    # Update this tag when you want to trigger a rebuild
    FDO_DISTRIBUTION_TAG: '2020-08-31.1'
    FDO_DISTRIBUTION_VERSION: '32'
    # findutils: used by the .build script below
    # cmake: required for cpptoml submodule & hotdoc
    # dbus-devel: required by pipewire
    # dbus-daemon: required by GDBus unit tests
    # libxml, json-glib: required by hotdoc
    FDO_DISTRIBUTION_PACKAGES: >-
      findutils
      gcc
      gcc-c++
      git
      meson
      cmake
      glib2-devel
      gobject-introspection-devel
      dbus-devel
      dbus-daemon
      libxml2-devel
      json-glib-devel
    # build hotdoc via pip, since there is no rpm package and make sure
    # to remove its build-deps afterwards to save space.
    # also install glib2-doc (required to make documentation links to GLib work)
    # manually, to remove the 'tsflags=nodocs' flag that is enabled by default
    # in the fedora docker image
    FDO_DISTRIBUTION_EXEC: >-
      dnf -y install python3-pip make python3-devel flex clang ;
      HOTDOC_BUILD_C_EXTENSION=enabled pip3 install --no-cache-dir hotdoc ;
      rm -rf ~/.cache/pip ;
      dnf -y remove python3-pip make python3-devel flex clang ;
      dnf -y install glib2-doc --setopt='tsflags='

.build:
  before_script:
    # setup the environment
    - export BUILD_ID="$CI_JOB_NAME"
    - export PREFIX="$PWD/prefix-$BUILD_ID"
    - export PW_BUILD_DIR="$PWD/build-pipewire-$BUILD_ID"
    # Build pipewire
    # Fedora also ships that, but without the test plugins that we need...
    - git clone --depth=1 --branch="$PIPEWIRE_HEAD"
        https://gitlab.freedesktop.org/pipewire/pipewire.git
    - meson "$PW_BUILD_DIR" pipewire --prefix="$PREFIX"
        -Dpipewire-alsa=false -Dpipewire-pulseaudio=false -Dpipewire-jack=false
        -Dalsa=false -Dv4l2=false -Djack=false -Dbluez5=false -Dvulkan=false
        -Dgstreamer=false -Dsystemd=false
        -Ddocs=false -Dman=false -Dexamples=false -Dpw-cat=false
        -Dvideotestsrc=true -Daudiotestsrc=true -Dtest=true
    - ninja -C "$PW_BUILD_DIR" install
    # misc environment only for wireplumber
    - export WP_BUILD_DIR="$PWD/build-wireplumber-$BUILD_ID"
    - export XDG_RUNTIME_DIR="$(mktemp -p $PWD -d xdg-runtime-XXXXXX)"
    - export PKG_CONFIG_PATH="$(dirname $(find "$PREFIX" -name 'libpipewire-*.pc')):$PKG_CONFIG_PATH"
  script:
    # Build wireplumber
    - meson "$WP_BUILD_DIR" . --prefix="$PREFIX"
        -Dintrospection=enabled -Ddoc=enabled
    - cd "$WP_BUILD_DIR"
    - ninja
    - ninja test
    - ninja install
  artifacts:
    name: wireplumber-$CI_COMMIT_SHA
    when: always
    paths:
      - build-*/meson-logs
      - prefix-*

container_fedora:
  extends:
    - .fedora
    - .fdo.container-build@fedora
  stage: container

build_on_fedora:
  extends:
    - .fedora
    - .fdo.distribution-image@fedora
    - .build
  stage: build

pages:
  stage: pages
  dependencies:
    - build_on_fedora
  script:
    - export PREFIX="$PWD/prefix-build_on_fedora"
    - mkdir public
    - cp -R $PREFIX/share/doc/wireplumber/html/* public/
  artifacts:
    paths:
      - public
  only:
    - master
