
stages:
  - containers
  - builds
  - sanity_checks

.git_build_vars: &git_build_vars |
  export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
  export SCRATCH_DIR="$PWD/scratch"
  export VROOT="$SCRATCH_DIR/vroot"
  export LIBDIR="$VROOT/lib"
  export LD_LIBRARY_PATH="$LIBDIR"
  export PATH="$VROOT/bin:$PATH"
  export PKG_CONFIG_PATH="$LIBDIR/pkgconfig"
  export CFLAGS="-Werror"

.native_git_build_job:
  extends: .gitlab_native_build_job
  before_script:
    - *git_build_vars
  script:
    - pushd "$PWD"
    - mkdir -p "$SCRATCH_DIR"
    - cd "$SCRATCH_DIR"
    - git clone --depth 1 https://gitlab.com/libvirt/libvirt.git
    - cd libvirt
    - meson build -Ddriver_libvirtd=disabled "--prefix=$VROOT" "--libdir=$LIBDIR"
    - ninja -C build install
    - popd
    - $PYTHON setup.py build
    - $PYTHON setup.py install
    - $PYTHON setup.py test
    - $PYTHON setup.py sdist
    - if test -x /usr/bin/rpmbuild && test "$RPM" != "skip" ; then rpmbuild --nodeps -ta dist/libvirt-python*tar.gz ; fi

.native_build_job:
  extends: .gitlab_native_build_job
  before_script:
    - export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
    - export CFLAGS="-Werror"
  script:
    - $PYTHON setup.py build
    - $PYTHON setup.py install
    - $PYTHON setup.py test
    - $PYTHON setup.py sdist
    - if test -x /usr/bin/rpmbuild && test "$RPM" != "skip" ; then rpmbuild --nodeps -ta dist/libvirt-python*tar.gz ; fi

include: '/ci/gitlab.yml'

api-coverage:
  image: $CI_REGISTRY_IMAGE/ci-centos-8:latest
  stage: sanity_checks
  needs:
    - job: x86_64-centos-8-git
      artifacts: true
  before_script:
    - *git_build_vars
  script:
    - LIBVIRT_API_COVERAGE=1 $PYTHON setup.py test
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'
      allow_failure: true
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
