#
# Python wheels build is now done in Github Actions + Cirrus CI(for arm build)
# so python build is disabled in Azure pipelines.
# 

variables:
  # https://cibuildwheel.readthedocs.io/en/stable/cpp_standards/
  # cibuildwheel now supports python 3.6+(as of 2022 Oct)
  #CIBW_SKIP: "pp*"
  CIBW_BEFORE_BUILD: "pip install pybind11"
  CIBW_ARCHS_LINUXBEFORE_BUILD: "pip install pybind11"
  # disable aarch64 build for a while since it(pulling docker aarch64 image)  exceeds Azure's 60 min limit
  # NOTE: aarch64 linux support in Azure pipeline is not yet officially supported(as of 2022 Oct) https://github.com/microsoft/azure-pipelines-agent/issues/3935
  #CIBW_ARCHS_LINUX: auto aarch64
  CIBW_ARCHS_MACOS: x86_64 universal2 arm64
  #CIBW_BEFORE_BUILD_MACOS: "pip install -U pip setuptools"
  #CIBW_BEFORE_BUILD_LINUX: "pip install -U pip setuptools"
  #CIBW_TEST_COMMAND: TODO "python -c \"import tinyobjloader; tinyobjloader.test()\""
  CIBW_BUILD_VERBOSITY: "2"
  #CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
  #CIBW_MANYLINUX_I686_IMAGE: manylinux2014

jobs:
  - job: unit_linux
    pool: { vmImage: "ubuntu-latest" }
    steps:
      - script: |
          cd tests
          make && ./tester
        displayName: Run unit tests

  - job: python_format
    pool: { vmImage: "ubuntu-latest" }
    steps:
      - task: UsePythonVersion@0
      - script: |
          # 19.10b0 triggers 'cannot import name '_unicodefun' from 'click'' error.
          # https://stackoverflow.com/questions/71673404/importerror-cannot-import-name-unicodefun-from-click
          #pip install black==19.10b0
          #pip install black==22.3.0
          pip install black==22.10.0

          black --check python/
        displayName: Check Python code format

  # Disabled: python build
  ##
  ## Ubuntu16.04 seems now deprecated(as of 2021/12/01),
  ## so use `ubuntu-latest`
  #- job: linux
  #  pool: {vmImage: "ubuntu-latest"}
  #  steps:
  #    - task: UsePythonVersion@0
  #    - bash: |
  #        python3 -m pip install --upgrade pip
  #        pip3 install cibuildwheel twine

  #        # Use pipx to build source dist
  #        pip3 install pipx

  #        # Source dist
  #        pipx run build --sdist
  #        ls -la dist/*

  #        # build binary wheels
  #        cibuildwheel --platform linux --output-dir wheelhouse .

  #    - task: CopyFiles@2
  #      inputs:
  #        contents: 'wheelhouse/**'
  #        targetFolder: $(Build.ArtifactStagingDirectory)

  #    - task: CopyFiles@2
  #      inputs:
  #        contents: 'dist/**'
  #        targetFolder: $(Build.ArtifactStagingDirectory)

  #    - task: PublishBuildArtifacts@1
  #      inputs:
  #        path: $(Build.ArtifactStagingDirectory)
  #        artifactName: tinyobjDeployLinux

  #- job: macos
  #  pool: {vmImage: 'macOS-latest'}
  #  variables:
  #    # Support C++11: https://github.com/joerick/cibuildwheel/pull/156
  #    MACOSX_DEPLOYMENT_TARGET: 10.9
  #  steps:
  #    - task: UsePythonVersion@0
  #    - bash: |
  #        python3 -m pip install --upgrade pip
  #        pip3 install cibuildwheel
  #        cibuildwheel --platform macos --output-dir wheelhouse .
  #    - task: CopyFiles@2
  #      inputs:
  #        contents: 'wheelhouse/*.whl'
  #        targetFolder: $(Build.ArtifactStagingDirectory)
  #    - task: PublishBuildArtifacts@1
  #      inputs:
  #        path: $(Build.ArtifactStagingDirectory)
  #        artifactName: tinyobjDeployMacOS

  #- job: windows
  #  pool: {vmImage: 'windows-latest'}
  #  steps:
  #    - task: UsePythonVersion@0
  #    - bash: |
  #        python -m pip install --upgrade pip
  #        pip install cibuildwheel
  #        cibuildwheel --platform windows --output-dir wheelhouse .
  #    - task: CopyFiles@2
  #      inputs:
  #        contents: 'wheelhouse/*.whl'
  #        targetFolder: $(Build.ArtifactStagingDirectory)
  #    - task: PublishBuildArtifacts@1
  #      inputs:
  #        path: $(Build.ArtifactStagingDirectory)
  #        artifactName: tinyobjDeployWindows

  #- job: deployPyPI
  #  # Based on vispy: https://github.com/vispy/vispy/blob/master/azure-pipelines.yml
  #  pool: {vmImage: 'ubuntu-latest'}
  #  condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
  #  dependsOn:
  #    - linux
  #    - macos
  #    - windows
  #  steps:
  #    - task: UsePythonVersion@0

  #    # TODO(syoyo): Use buildType: specific to download multiple artifacts at once?
  #    - task: DownloadBuildArtifacts@0
  #      inputs:
  #        artifactName: 'tinyobjDeployLinux'
  #        downloadPath: $(Pipeline.Workspace)

  #    - task: DownloadBuildArtifacts@0
  #      inputs:
  #        artifactName: 'tinyobjDeployMacOS'
  #        downloadPath: $(Pipeline.Workspace)

  #    - task: DownloadBuildArtifacts@0
  #      inputs:
  #        artifactName: 'tinyobjDeployWindows'
  #        downloadPath: $(Pipeline.Workspace)

  #    # Publish to PyPI through twine
  #    - bash: |
  #        cd $(Pipeline.Workspace)
  #        find .
  #        python -m pip install --upgrade pip
  #        pip install twine
  #        echo tinyobjDeployLinux/dist/*
  #        echo tinyobjDeployLinux/wheelhouse/* tinyobjDeployMacOS/wheelhouse/* tinyobjDeployWindows/wheelhouse/*
  #        twine upload -u "__token__" --skip-existing tinyobjDeployLinux/dist/* tinyobjDeployLinux/wheelhouse/* tinyobjDeployMacOS/wheelhouse/* tinyobjDeployWindows/wheelhouse/*
  #      env:
  #        TWINE_PASSWORD: $(pypiToken2)

trigger:
  branches:
    include:
      - '*'
  tags:
    include:
      - 'v*'

pr:
  branches:
    include:
      - "*"
