Skip to content

Commit

Permalink
Behavioral simplification: Avoid 3x duplication with checkout-submodu…
Browse files Browse the repository at this point in the history
…le.yml.

This extracts 3 copy-pasted cmd scripts into 1 PowerShell script.

We no longer need to use Azure Pipelines variables to communicate the SHA.

Each remote is now named submodule-upstream for uniformity, as the name doesn't matter.

I've performed a few additional simplifications that I believe are proper, but we'll need to watch out for problems when agents reuse repos:

* After top-level self-checkout, each submodule directory should exist, so we shouldn't have to force-create it.
* If the .git directory doesn't exist in the submodule, we shouldn't need to obliterate all other files there. We're going to perform a checkout and clean that should restore us to a known good state.
* If the .git directory already exists, running `git init` again is harmless by design.
* Instead of the "run `git remote get-url` and look for failure" technique, we can check the output of `git remote` to make `git remote add` idempotent.
  • Loading branch information
StephanTLavavej committed Apr 17, 2024
1 parent 6439b1a commit a9370ed
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 93 deletions.
17 changes: 14 additions & 3 deletions azure-devops/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ jobs:
timeoutInMinutes: 30
steps:
- template: checkout-self.yml
- template: checkout-submodules.yml
- template: checkout-submodule.yml
parameters:
buildBenchmarks: ${{ parameters.buildBenchmarks }}
skipTesting: ${{ parameters.skipTesting }}
enabled: ${{ not(parameters.skipTesting) }}
path: 'llvm-project'
url: 'https://github.com/llvm/llvm-project.git'
- template: checkout-submodule.yml
parameters:
enabled: true
path: 'boost-math'
url: 'https://github.com/boostorg/math.git'
- template: checkout-submodule.yml
parameters:
enabled: ${{ parameters.buildBenchmarks }}
path: 'benchmarks/google-benchmark'
url: 'https://github.com/google/benchmark.git'
- template: cmake-configure-build.yml
parameters:
hostArch: ${{ parameters.hostArch }}
Expand Down
31 changes: 31 additions & 0 deletions azure-devops/checkout-submodule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

parameters:
- name: enabled
type: boolean
- name: path
type: string
- name: url
type: string
steps:
- task: PowerShell@2
displayName: 'Checkout ${{ parameters.path }} Submodule'
condition: and(succeeded(), ${{ parameters.enabled }})
inputs:
targetType: inline
script: |
$submodule = '${{ parameters.path }}'
$rawStatus = git submodule status --cached $submodule
$sha = $rawStatus -replace '^[ \-+]([0-9a-f]+) .*$', '$1'
cd $submodule
git init
if ((git remote) -eq $null) {
git remote add submodule-upstream ${{ parameters.url }}
}
git fetch --filter=tree:0 --depth=1 submodule-upstream $sha
if ($submodule -eq 'llvm-project') {
git sparse-checkout set --sparse-index libcxx/test libcxx/utils/libcxx llvm/utils/lit
}
git reset --quiet --hard FETCH_HEAD
git clean --quiet -x -d -f -f
90 changes: 0 additions & 90 deletions azure-devops/checkout-submodules.yml

This file was deleted.

0 comments on commit a9370ed

Please sign in to comment.