From 5ddeaabab9243a232f82cfa6b4d311932a8a691c Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Thu, 17 Sep 2020 21:16:09 -0700 Subject: [PATCH] Use vcpkg cache (#646) --- eng/pipelines/templates/steps/vcpkg.yml | 149 ++++-------------------- eng/scripts/vcpkg.ps1 | 33 ++++++ eng/vcpkg-commit.txt | 1 + 3 files changed, 59 insertions(+), 124 deletions(-) create mode 100644 eng/scripts/vcpkg.ps1 create mode 100644 eng/vcpkg-commit.txt diff --git a/eng/pipelines/templates/steps/vcpkg.yml b/eng/pipelines/templates/steps/vcpkg.yml index fb638baac..7e35ad37f 100644 --- a/eng/pipelines/templates/steps/vcpkg.yml +++ b/eng/pipelines/templates/steps/vcpkg.yml @@ -1,72 +1,34 @@ -# Assumes that the VM image is in a variable called OSVmImage - parameters: # Use the variable name itself (no $() or other wrapping syntax). This is # because we use runtime and macro expressions for conditions and script # invocations DependenciesVariableName: vcpkg.deps - # Ref at which to check out (can be commit SHA or tag in the form of - # `tags/`) - VcpkgVersion: tags/2020.06 - steps: - # Set VCPKG_INSTALLATION_ROOT location for cache on Mac OS hosts - - task: Bash@3 - inputs: - targetType: inline - workingDirectory: $(Agent.TempDirectory) - script: | - echo "##vso[task.prependpath]$(Agent.TempDirectory)/vcpkg" - echo "##vso[task.setvariable variable=VCPKG_INSTALLATION_ROOT;]$(Agent.TempDirectory)/vcpkg" - displayName: MacOS - Set VCPKG_INSTALLATION_ROOT + - pwsh: | + $TargetPath = "$(Agent.TempDirectory)/vcpkg" + Remove-Item -Path $TargetPath -Recurse -Force -ErrorAction Ignore + New-Item -ItemType Directory -Path $TargetPath -Force + + $VcpkgCommit = $(Get-Content eng/vcpkg-commit.txt) + Write-Host "Target Path for vcpkg: $TargetPath" + Write-Host "Vcpkg SHA: $VcpkgCommit" + + Write-Host "##vso[task.prependpath]$TargetPath" + Write-Host "##vso[task.setvariable variable=VCPKG_INSTALLATION_ROOT]$TargetPath" + Write-Host "##vso[task.setvariable variable=VcpkgCommit]$VcpkgCommit" + displayName: Set Vcpkg Variables condition: >- and( succeeded(), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), - contains(variables['OSVmImage'], 'macOS') + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) ) - # Set MacOS specific build environment features for vcpkg - - task: Bash@3 - inputs: - targetType: inline - script: | - sudo xcode-select --switch /Applications/Xcode_11.3.1.app - echo "xcode path:" - sudo xcode-select --print-path - - # Install gcc 9 - brew install gcc@9 - gcc --version - displayName: MacOS - Set tools versions - condition: >- - and( - succeeded(), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), - contains(variables['OSVmImage'], 'macOS') - ) - - # Clear the vcpkg folder so the cache can successfully deploy to that location - - bash: | - id - sudo rm -rf $(VCPKG_INSTALLATION_ROOT) - sudo mkdir -p $(VCPKG_INSTALLATION_ROOT) - sudo chown `id --name -u`.`id --name -g` $(VCPKG_INSTALLATION_ROOT) - displayName: Linux - Clear vcpkg folder - condition: >- - and( - succeeded(), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), - contains(variables['OSVmImage'], 'ubuntu') - ) - - # Attempt to restore vcpkg from the cache - task: Cache@2 inputs: key: >- $(Agent.JobName) - | "${{ parameters.VcpkgVersion }}" + | "$(VcpkgCommit)" | $(Agent.Os) | $(${{ parameters.DependenciesVariableName }}) path: $(VCPKG_INSTALLATION_ROOT) @@ -79,79 +41,18 @@ steps: not(eq(variables['Skip.VcpkgCache'], 'true')) ) - # Install vcpkg on MacOS - - task: Bash@3 + - task: PowerShell@2 inputs: - targetType: inline - workingDirectory: $(Agent.TempDirectory) - script: | - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - git rev-parse --verify HEAD - git checkout ${{ parameters.VcpkgVersion }} - git status - - ./bootstrap-vcpkg.sh - - # Validate that vcpkg bootstrap succeeded - ./vcpkg version - if [ $? -ne 0 ] - then - echo "./bootstrap-vcpkg.sh FAILED" - exit 1 - fi - - echo "##vso[task.prependpath]$(pwd)" - echo "##vso[task.setvariable variable=VCPKG_INSTALLATION_ROOT;]$(pwd)" + targetType: filePath + filePath: eng/scripts/vcpkg.ps1 + arguments: >- + -Ref $(VcpkgCommit) + -Dependencies "$(${{ parameters.DependenciesVariableName }})" + -VcpkgPath $(VCPKG_INSTALLATION_ROOT) + pwsh: true condition: >- and( succeeded(), - ne(variables['VcpkgRestoredFromCache'], 'true'), - not(contains(variables['OSVmImage'], 'windows')), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), + ne(variables['VcpkgRestoredFromCache'], true) ) - displayName: MacOS & Linux - vcpkg bootstrap - - # Update vcpkg and re-bootstrap on non-Mac OS'. Vcpkg is installed on the - # image at a given time stamp and not moved forward until some update - # procedure is run. - - task: Bash@3 - inputs: - targetType: inline - script: | - cd $VCPKG_INSTALLATION_ROOT - - # Sometimes the image has changes in the git tree. Reset to HEAD and - # then pull - git reset --hard HEAD - git fetch --tags - git pull origin master - git checkout ${{ parameters.VcpkgVersion }} - - ./bootstrap-vcpkg.sh - condition: >- - and( - succeeded(), - ne(variables['VcpkgRestoredFromCache'], 'true'), - not(contains(variables['OSVmImage'], 'macOS')), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) - ) - displayName: Non-MacOS - vcpkg bootstrap - - - script: vcpkg version - displayName: vcpkg version - condition: >- - and( - succeeded(), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) - ) - - - script: | - vcpkg install $(${{ parameters.DependenciesVariableName }}) - displayName: Install Dependencies (vcpkg) - # Execute only if there is at least one dependency to be installed - condition: >- - and( - succeeded(), - not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) - ) \ No newline at end of file diff --git a/eng/scripts/vcpkg.ps1 b/eng/scripts/vcpkg.ps1 new file mode 100644 index 000000000..8c43899b6 --- /dev/null +++ b/eng/scripts/vcpkg.ps1 @@ -0,0 +1,33 @@ +[CmdletBinding()] +Param ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] $Ref = (Get-Content "$PSScriptRoot/../vcpkg-commit.txt"), + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $Dependencies, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] $VcpkgPath = "$PSScriptRoot/../../vcpkg" +) + +$initialDirectory = Get-Location + +try { + git clone https://github.com/Microsoft/vcpkg $VcpkgPath + Set-Location $VcpkgPath + git fetch --tags + git checkout $Ref + + if ($IsWindows) { + .\bootstrap-vcpkg.bat + .\vcpkg.exe install $Dependencies.Split(' ') + } else { + ./bootstrap-vcpkg.sh + ./vcpkg install $Dependencies.Split(' ') + } +} finally { + Set-Location $initialDirectory +} \ No newline at end of file diff --git a/eng/vcpkg-commit.txt b/eng/vcpkg-commit.txt new file mode 100644 index 000000000..57f9c9d03 --- /dev/null +++ b/eng/vcpkg-commit.txt @@ -0,0 +1 @@ +tags/2020.06 \ No newline at end of file