|
1 | 1 | $ErrorActionPreference = 'Stop' |
2 | 2 |
|
| 3 | +$LIBGIT2_VERSION = $env:LIBGIT2_VERSION |
| 4 | +$LIBGIT2_SRC = $env:LIBGIT2_SRC |
| 5 | +if (-not $LIBGIT2_SRC) { |
| 6 | + $LIBGIT2_SRC = "build/libgit2_src" |
| 7 | +} |
| 8 | + |
| 9 | +# Prefer CMAKE_INSTALL_PREFIX, then LIBGIT2, then the default Program Files location. |
| 10 | +$INSTALL_PREFIX = $env:CMAKE_INSTALL_PREFIX |
| 11 | +if (-not $INSTALL_PREFIX) { |
| 12 | + $INSTALL_PREFIX = $env:LIBGIT2 |
| 13 | +} |
| 14 | +if (-not $INSTALL_PREFIX) { |
| 15 | + $INSTALL_PREFIX = "$env:ProgramFiles\libgit2" |
| 16 | +} |
| 17 | + |
| 18 | +# Use cached dependencies if they match the requested version. |
| 19 | +if ((Test-Path -Path "$INSTALL_PREFIX\versions.txt") -and $LIBGIT2_VERSION) { |
| 20 | + $cached = Get-Content "$INSTALL_PREFIX\versions.txt" |
| 21 | + $matches = $cached | Select-String "^LIBGIT2_VERSION=$LIBGIT2_VERSION$" |
| 22 | + if ($matches) { |
| 23 | + Write-Host "Using cached dependencies" |
| 24 | + exit 0 |
| 25 | + } |
| 26 | +} |
| 27 | + |
3 | 28 | if (!(Test-Path -Path "build")) { |
4 | 29 | # in case the pygit2 package build/ workspace has not been created by cibuildwheel yet |
5 | 30 | mkdir build |
6 | 31 | } |
7 | | -if (Test-Path -Path "$env:LIBGIT2_SRC") { |
8 | | - Set-Location "$env:LIBGIT2_SRC" |
| 32 | +if (Test-Path -Path "$LIBGIT2_SRC") { |
| 33 | + Set-Location "$LIBGIT2_SRC" |
9 | 34 | # for local runs, reuse build/libgit_src if it exists |
10 | 35 | if (Test-Path -Path build) { |
11 | 36 | # purge previous build env (likely for a different arch type) |
12 | 37 | Remove-Item -Recurse -Force build |
13 | 38 | } |
14 | 39 | # ensure we are checked out to the right version |
15 | 40 | git fetch --depth=1 --tags |
16 | | - git checkout "v$env:LIBGIT2_VERSION" |
| 41 | + git checkout "v$LIBGIT2_VERSION" |
17 | 42 | } else { |
18 | 43 | # from a fresh run (like in CI) |
19 | | - git clone --depth=1 -b "v$env:LIBGIT2_VERSION" https://github.com/libgit2/libgit2.git $env:LIBGIT2_SRC |
20 | | - Set-Location "$env:LIBGIT2_SRC" |
| 44 | + git clone --depth=1 -b "v$LIBGIT2_VERSION" https://github.com/libgit2/libgit2.git $LIBGIT2_SRC |
| 45 | + Set-Location "$LIBGIT2_SRC" |
21 | 46 | } |
22 | | -cmake -B build -S . -DBUILD_TESTS=OFF |
| 47 | +cmake -B build -S . -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" |
23 | 48 | cmake --build build/ --config=Release --target install |
| 49 | + |
| 50 | +# Record version so the cache can be reused. |
| 51 | +"LIBGIT2_VERSION=$LIBGIT2_VERSION" | Set-Content "$INSTALL_PREFIX\versions.txt" -NoNewline |
0 commit comments