From c7d994f08fd883d0d068ffe84396485d2529d0b7 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Fri, 31 Jul 2020 15:10:09 -0700 Subject: [PATCH] Use vcpkg caching (#361) * Use vcpkg caching * fetch tags * Supply OSVmImage to doc generation so vcpkg.yml can include/exclude the correct set of steps --- .../templates/jobs/archetype-sdk-client.yml | 3 +- eng/pipelines/templates/steps/vcpkg.yml | 121 +++++++++++++++++- 2 files changed, 117 insertions(+), 7 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index b4c9d7896..ad401c812 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -81,8 +81,9 @@ jobs: - ${{ if ne(parameters.ServiceDirectory, 'not-specified' )}}: - job: GenerateReleaseArtifacts pool: - vmImage: windows-2019 + vmImage: $(OSVmImage) variables: + OSVmImage: windows-2019 VcpkgDependencies: curl[winssl] libxml2 VCPKG_DEFAULT_TRIPLET: 'x64-windows-static' steps: diff --git a/eng/pipelines/templates/steps/vcpkg.yml b/eng/pipelines/templates/steps/vcpkg.yml index 0dc5414f6..fb638baac 100644 --- a/eng/pipelines/templates/steps/vcpkg.yml +++ b/eng/pipelines/templates/steps/vcpkg.yml @@ -6,8 +6,28 @@ parameters: # 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: - # Mac OS specific requirements + # 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 + condition: >- + and( + succeeded(), + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), + contains(variables['OSVmImage'], 'macOS') + ) + + # Set MacOS specific build environment features for vcpkg - task: Bash@3 inputs: targetType: inline @@ -19,10 +39,56 @@ steps: # 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 }}" + | $(Agent.Os) + | $(${{ parameters.DependenciesVariableName }}) + path: $(VCPKG_INSTALLATION_ROOT) + cacheHitVar: VcpkgRestoredFromCache + displayName: Vcpkg Cache + condition: >- + and( + succeeded(), + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')), + not(eq(variables['Skip.VcpkgCache'], 'true')) + ) + + # Install vcpkg on MacOS + - task: Bash@3 + 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 @@ -37,12 +103,55 @@ steps: echo "##vso[task.prependpath]$(pwd)" echo "##vso[task.setvariable variable=VCPKG_INSTALLATION_ROOT;]$(pwd)" - # Execute only for Mac and if there is at least one dependency to be installed - condition: and(succeeded(), contains(variables['OSVmImage'], 'macOS'), not(eq(variables['${{ parameters.DependenciesVariableName }}'], ''))) - displayName: vcpkg bootstrap + condition: >- + and( + succeeded(), + ne(variables['VcpkgRestoredFromCache'], 'true'), + not(contains(variables['OSVmImage'], 'windows')), + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) + ) + 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: vcpkg install dependencies + displayName: Install Dependencies (vcpkg) # Execute only if there is at least one dependency to be installed - condition: and(succeeded(), not(eq(variables['${{ parameters.DependenciesVariableName }}'], ''))) + condition: >- + and( + succeeded(), + not(eq(variables['${{ parameters.DependenciesVariableName }}'], '')) + ) \ No newline at end of file