Use vcpkg cache (#646)
This commit is contained in:
parent
caf9fbc7d6
commit
5ddeaabab9
@ -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/<tag>`)
|
||||
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 }}'], ''))
|
||||
)
|
||||
33
eng/scripts/vcpkg.ps1
Normal file
33
eng/scripts/vcpkg.ps1
Normal file
@ -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
|
||||
}
|
||||
1
eng/vcpkg-commit.txt
Normal file
1
eng/vcpkg-commit.txt
Normal file
@ -0,0 +1 @@
|
||||
tags/2020.06
|
||||
Loading…
Reference in New Issue
Block a user