8000 Add script to update libgit2 · rlazev/libgit2sharp@17e8c95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17e8c95

Browse files
committed
Add script to update libgit2
A call to ".\UpdateLibgit2ToSha.ps1 deadbeef" will: - Fetch libgit2 - Checkout the sha, if it exists as a commit - Build 32- and 64-bit variants of the library, and copy them to NativeBinaries - Update the libgit2_sha.txt file
1 parent 4930ffb commit 17e8c95

File tree

1 file changed

+144
-0
lines changed

1 file changed

+ 8000 144
-0
lines changed

UpdateLibgit2ToSha.ps1

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<#
2+
.SYNOPSIS
3+
Builds a version of libgit2 and copies it to Lib/NativeBinaries.
4+
.PARAMETER sha
5+
Desired libgit2 version. This is run through `git rev-parse`, so branch names are okay too.
6+
.PARAMETER vs
7+
Version of Visual Studio project files to generate. Cmake supports "10" (default) and "11".
8+
.PARAMETER test
9+
If set, run the libgit2 tests on the desired version.
10+
.PARAMETER debug
11+
If set, build the "Debug" configuration of libgit2, rather than "RelWithDebInfo" (default).
12+
#>
13+
14+
Param(
15+
[string]$sha = 'HEAD',
16+
[string]$vs = '10',
17+
[switch]$test,
18+
[switch]$debug
19+
)
20+
21+
Set-StrictMode -Version Latest
22+
23+
$self = Split-Path -Leaf $MyInvocation.MyCommand.Path
24+
$libgit2sharpDirectory = Split-Path $MyInvocation.MyCommand.Path
25+
$libgit2Directory = Join-Path $libgit2sharpDirectory "libgit2"
26+
$x86Directory = Join-Path $libgit2sharpDirectory "Lib\NativeBinaries\x86"
27+
$x64Directory = Join-Path $libgit2sharpDirectory "Lib\NativeBinaries\amd64"
28+
29+
$build_clar = 'OFF'
30+
if ($test.IsPresent) { $build_clar = 'ON' }
31+
$configuration = "RelWithDebInfo"
32+
if ($debug.IsPresent) { $configuration = "Debug" }
33+
34+
function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
35+
$output = ""
36+
if ($Quiet) {
37+
$output = & $Command 2>&1
38+
} else {
39+
& $Command
40+
}
41+
42+
if (!$Fatal) {
43+
return
44+
}
45+
46+
$exitCode = 0
47+
if ($LastExitCode -ne 0) {
48+
$exitCode = $LastExitCode
49+
} elseif (!$?) {
50+
$exitCode = 1
51+
} else {
52+
return
53+
}
54+
55+
$error = "``$Command`` failed"
56+
if ($output) {
57+
Write-Host -ForegroundColor yellow $output
58+
$error += ". See output above."
59+
}
60+
Throw $error
61+
}
62+
63+
function Find-CMake {
64+
# Look for cmake.exe in $Env:PATH.
65+
$cmake = @(Get-Command cmake.exe)[0] 2>$null
66+
if ($cmake) {
67+
$cmake = $cmake.Definition
68+
} else {
69+
# Look for the highest-versioned cmake.exe in its default location.
70+
$cmake = @(Resolve-Path (Join-Path ${Env:ProgramFiles(x86)} "CMake *\bin\cmake.exe"))
71+
if ($cmake) {
72+
$cmake = $cmake[-1].Path
73+
}
74+
}
75+
if (!$cmake) {
76+
throw "Error: Can't find cmake.exe"
77+
}
78+
$cmake
79+
}
80+
81+
function Find-Git {
82+
$git = @(Get-Command git)[0] 2>$null
83+
if ($git) {
84+
$git = $git.Definition
85+
Write-Host -ForegroundColor Gray "Using git: $git"
86+
& $git --version | write-host -ForegroundColor Gray
87+
return $git
88+
}
89+
throw "Error: Can't find git"
90+
}
91+
92+
Push-Location $libgit2Directory
93+
94+
& {
95+
trap {
96+
Pop-Location
97+
break
98+
}
99+
100+
$cmake = Find-CMake
101+
$ctest = Join-Path (Split-Path -Parent $cmake) "ctest.exe"
102+
$git = Find-Git
103+
104+
Write-Output "Fetching..."
105+
Run-Command -Quiet { & $git fetch }
106+
107+
Write-Output "Verifying $sha..."
108+
$sha = & $git rev-parse $sha
109+
if ($LASTEXITCODE -ne 0) {
110+
write-host -foregroundcolor red "Error: invalid SHA. USAGE: $self <SHA>"
111+
popd
112+
break
113+
}
114+
115+
Write-Output "Checking out $sha..."
116+
Run-Command -Quiet -Fatal { & $git checkout $sha }
117+
118+
Write-Output "Building 32-bit..."
119+
Run-Command -Quiet { & remove-item build -recurse -force }
120+
Run-Command -Quiet { & mkdir build }
121+
cd build
122+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" .. }
123+
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
124+
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
125+
cd $configuration
126+
Run-Command -Quiet { & rm *.exp }
127+
Run-Command -Quiet -Fatal { & copy -fo * $x86Directory }
128+
129+
Write-Output "Building 64-bit..."
130+
cd ..
131+
Run-Command -Quiet { & mkdir build64 }
132+
cd build64
133+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs Win64" -D THREADSAFE=ON -D "BUILD_CLAR=$build_clar" ../.. }
134+
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
135+
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
136+
cd $configuration
137+
Run-Command -Quiet { & rm *.exp }
138+
Run-Command -Quiet -Fatal { & copy -fo * $x64Directory }
139+
140+
Write-Output "Done!"
141+
pop-location
142+
sc -Encoding UTF8 libgit2sharp\libgit2_hash.txt $sha
143+
}
144+
exit

0 commit comments

Comments
 (0)
1618
0