# -*- mode: yaml -*-

jobs:
- job: linux_conda
  pool:
    vmImage: ubuntu-16.04
  timeoutInMinutes: 60
  steps:
  - bash: echo "##vso[task.prependpath]$CONDA/bin"
    displayName: Add conda to PATH
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      conda create --yes --quiet --name pdal

      source activate pdal
      conda config --set always_yes True --set show_channel_urls True
      conda config --add channels conda-forge
      conda config --set channel_priority strict
      conda install --yes --quiet --name pdal -c conda-forge gdal=3.0.2=py37hbb6b9fb_8 python=3.7 abseil-cpp conda-build ninja  conda-forge-ci-setup=2 -y
      conda install --yes --quiet --name pdal -c conda-forge pdal  --only-deps -y
    displayName: Install PDAL dependencies
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      source activate pdal
      echo "current directory:" `pwd`
      mkdir build
      cd build
      LDFLAGS="$LDFLAGS -Wl,-rpath-link,$CONDA_PREFIX/lib" cmake   -G Ninja  \
        -DCMAKE_LIBRARY_PATH:FILEPATH="$CONDA_PREFIX/lib" \
        -DCMAKE_INCLUDE_PATH:FILEPATH="$CONDA_PREFIX/include" \
        -DCMAKE_FIND_FRAMEWORK="NEVER" \
        -DCMAKE_BUILD_TYPE=Debug \
        -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
        -DBUILD_PLUGIN_PGPOINTCLOUD=ON \
        -DBUILD_PLUGIN_NITF=ON \
        -DBUILD_PLUGIN_ICEBRIDGE=ON \
        -DBUILD_PLUGIN_HDF=ON \
        -DBUILD_PLUGIN_TILEDB=ON \
        -DBUILD_PGPOINTCLOUD_TESTS=OFF \
        -DWITH_LAZPERF=ON \
        -DWITH_ZSTD=ON \
        -DWITH_LASZIP=ON \
        ..
    displayName: 'CMake'
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      cd build
      source activate pdal
      ninja
    displayName: 'Build'
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      cd build
      export PDAL_DRIVER_PATH=`pwd`/lib
      source activate pdal
      ctest -V
    displayName: 'Test'
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      export PDAL_TEST_DIR=`pwd`/test
      cd build
      source activate pdal
      ls build/lib/*
      ninja install
    displayName: 'Install'
  - script: |
      . /opt/conda/etc/profile.d/conda.sh
      export BASE=`pwd`
      source activate pdal
      for EXAMPLE in writing writing-filter writing-kernel writing-reader writing-writer
      do
          cd $BASE/examples/$EXAMPLE
          mkdir -p _build || exit 1
          cd _build || exit 1
          cmake -G "Ninja" .. -DPDAL_DIR=$CONDA_PREFIX/lib/cmake/PDAL && ninja
      done
    displayName: 'Examples'

