parameters:
  name: Windows_x64
  arquitecture: 'x64'
  qt_version: '5.12.4'
  qt_spec: 'msvc2017_64'
  qt_aqt_spec: 'win64_msvc2017_64'
  vc_redist_url: 'https://go.microsoft.com/fwlink/?LinkId=746572'
  vc_redist_file_name: 'vc_redist.x64.exe'
  vc_vars: 'vcvars64.bat'

jobs:
- job: ${{ parameters.name }}
  dependsOn: CodeFormatValidation
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - script: |
      pip install aqtinstall
      mkdir C:\Qt
      python -m aqt install -O c:\Qt ${{ parameters.qt_version }} windows desktop ${{ parameters.qt_aqt_spec }}
      dir C:\Qt\Qt${{ parameters.qt_version }}\${{ parameters.qt_version }}\${{ parameters.qt_spec }}\bin
      choco install -y wget
      choco install innosetup 
      wget "https://sourceforge.net/projects/sevenzip/files/7-Zip/18.05/7z1805-src.7z" -P $(Build.SourcesDirectory)\compressed_archive
      7z x $(Build.SourcesDirectory)\compressed_archive\7z1805-src.7z -o$(Build.SourcesDirectory)\compressed_archive\lib7zip
      wget "${{ parameters.vc_redist_url }}" -O $(Build.SourcesDirectory)\${{ parameters.vc_redist_file_name }}
    displayName: 'Install dependencies'
  - script: |
      call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\${{ parameters.vc_vars }}"
      set PATH=C:\Qt\Qt${{ parameters.qt_version }}\${{ parameters.qt_version }}\${{ parameters.qt_spec }}\bin;%PATH%
      set DEFINES_VAR=DEFINES+="BUILD_NUMBER=\\\\\\\"$(Build.BuildNumber)\\\\\\\""
      qmake CONFIG+="7zip" %DEFINES_VAR%
      nmake
    displayName: 'Build'
  - script: |
      set PATH=%PATH%;C:\Qt\Qt${{ parameters.qt_version }}\${{ parameters.qt_version }}\${{ parameters.qt_spec }}\bin;%PATH%
      cd $(Build.SourcesDirectory)\ci\win
      .\create_installer.cmd ${{ parameters.arquitecture }} 7z $(Build.BuildNumber)
    displayName: 'Create installer'
  - task: CopyFiles@2
    inputs:
      sourceFolder: $(Build.SourcesDirectory)\ci\win\Output\
      contents: '*'
      targetFolder: $(Build.ArtifactStagingDirectory)
  - task: PublishPipelineArtifact@1
    inputs:
      path: $(Build.ArtifactStagingDirectory)
      artifactName: Windows ${{ parameters.arquitecture }} $(Build.BuildNumber) 7z Installer
  

    
