forked from EventStore/EventStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.ps1
229 lines (203 loc) · 8.54 KB
/
dependencies.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Dependencies
Properties {
$baseDirectory = Resolve-Path .
#V8
$v8Repository = "https://github.com/v8/v8.git"
$v8Tag = "3.19.7"
$v8Directory = Join-Path $baseDirectory "v8"
#Python
$pythonRepository = "http://src.chromium.org/svn/trunk/tools/third_party/python_26"
$pythonRevision = "89111"
$pythonDirectory = Join-Path (Join-Path $baseDirectory "v8") (Join-Path "third_party" "python_26")
#GYP
$gypRepository = "http://gyp.googlecode.com/svn/trunk"
$gypRevision = "1642"
$gypDirectory = Join-Path $v8Directory (Join-Path "build" "gyp")
#Cygwin
$cygwinRepository = "http://src.chromium.org/svn/trunk/deps/third_party/cygwin"
$cygwinRevision = "66844"
$cygwinDirectory = Join-Path $v8Directory (Join-Path "third_party" "cygwin")
}
Task Get-Dependencies {
Get-GitRepoAtCommitOrRef -Verbose "V8" $v8Repository $v8Directory $v8Tag
Get-SvnRepoAtRevision -Verbose "Python" $pythonRepository $pythonDirectory $pythonRevision
Get-SvnRepoAtRevision -Verbose "GYP" $gypRepository $gypDirectory $gypRevision
Get-SvnRepoAtRevision -Verbose "CygWin" $cygwinRepository $cygwinDirectory $cygwinRevision
}
#This uses an exception for flow control in another script. I know it's bad,
# but can't think of a way to do this otherwise that doesn't involve repeating
# a load of variables or separating them into another file.
Task Test-Dependencies {
if (Test-Dependencies -eq $false) {
throw "Test-Dependencies Failure"
}
}
Function Test-Dependencies {
return (
(Test-GitRepositoryAtRef $v8Directory $v8Tag) -and
(Test-SvnRepoIsAtRevision $pythonDirectory $pythonRevision) -and
(Test-SvnRepoIsAtRevision $gypDirectory $gypRevision) -and
(Test-SvnRepoIsAtRevision $cygwinDirectory $cygwinRevision)
)
}
# Helper Functions - some of these rely on psake-provided constructs such as Exec { }.
Function Test-ShouldTryNetworkAccess {
#Opaque GUID from - http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2010/03/09/quicktip-how-do-you-check-internet-connectivity.aspx
$hasNetwork = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet
return ($hasNetwork -eq $true) -or ($forceNetwork -eq $true)
}
Function Test-GitRepositoryAtRef {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$localRepositoryDirectory,
[Parameter(Mandatory=$true)][string]$ref
)
Process {
try {
Push-Location $localRepositoryDirectory
$description = & { git describe --contains HEAD }
return ($description -eq $ref)
} catch {
return $false
} finally {
Pop-Location
}
}
}
Function Test-GitRefOrCommitExists {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$refOrCommit
)
Process {
try {
$output = Exec { git show --quiet -s --format=%H "$refOrCommit^{commit}" 2>$null }
return $true
} catch {
return $false
}
}
}
Function Get-GitRepoAtCommitOrRef
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$dependencyName,
[Parameter(Mandatory=$true)][string]$repositoryAddress,
[Parameter(Mandatory=$true)][string]$localPath,
[Parameter(Mandatory=$true)][string]$commitOrRef
)
Process {
Write-Host "Getting dependency $dependencyName via Git"
$localPathGitDirectory = Join-Path $localPath ".git/"
Write-Verbose "Testing for existence of: $localPathGitDirectory"
if ((Test-Path $localPathGitDirectory -PathType Container) -eq $true)
{
Write-Verbose "$localPathGitDirectory already exists"
Push-Location -ErrorAction Stop -Path $localPath
try {
if ((Test-GitRefOrCommitExists $commitOrRef) -eq $true) {
Write-Verbose "$commitOrRef exists in repository - checking out"
Exec { git checkout --quiet $commitOrRef}
} else {
Write-Verbose "$commitOrRef is not in repository"
if ((Test-ShouldTryNetworkAccess) -eq $true) {
Write-Verbose "Fetching from $repositoryAddress"
& { git fetch }
} else {
throw "$commitOrRef does not in the repository, and network connectivity is not detected. Pass forceNetwork = $true to try anyway."
}
Write-Verbose "Checking out $commitOrRef"
try {
& { git checkout --quiet $commitOrRef}
} catch {
throw "Cannot check out $commitOrRef - it does not exist not in the repository"
}
}
} finally {
Pop-Location -ErrorAction Stop
}
} else {
Write-Verbose "$localPathGitDirectory not found"
if ((Test-ShouldTryNetworkAccess) -eq $true) {
Write-Verbose "Cloning git repository from $repositoryAddress to $localPath"
Exec { git clone --quiet $repositoryAddress $localPath }
if ($commitOrRef -ne "") {
Push-Location -ErrorAction Stop -Path $localPath
try {
Write-Verbose "Checking out $commitOrRef"
Exec { git checkout --quiet $commitOrRef}
} catch {
Assert ($false) "Cannot check out $commitOrRef - it is not in the repository"
} finally {
Pop-Location -ErrorAction Stop
}
}
} else {
throw "Repository $localPathGitDirectory does not exist, and network connectivity is not detected. Pass forceNetwork = $true to try anyway."
}
}
}
}
Function Test-SvnRepoIsAtRevision {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$workingCopy,
[Parameter(Mandatory=$true)][string]$revision
)
Process {
try {
Push-Location $workingCopy
[xml]$svnInfo = Exec { svn info --xml }
$actualRevision = $svnInfo.info.entry.commit.GetAttribute("revision")
return ($actualRevision -eq $revision)
} catch {
return $false
} finally {
Pop-Location
}
}
}
Function Get-SvnRepoAtRevision
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][string]$dependencyName,
[Parameter(Mandatory=$true)][string]$repositoryAddress,
[Parameter(Mandatory=$true)][string]$localPath,
[Parameter(Mandatory=$true)][string]$revision
)
Process {
Write-Host "Getting dependency $dependencyName via Subversion"
$revisionString = "-r$revision"
$localPathSvnDirectory = Join-Path $localPath ".svn/"
Write-Verbose "Testing for existence of: $localPathSvnDirectory"
if ((Test-Path $localPathSvnDirectory -PathType Container) -eq $true)
{
Write-Verbose "$localPathSvnDirectory already exists"
Push-Location -ErrorAction Stop -Path $localPath
try {
if ((Test-SvnRepoIsAtRevision $localPath $revision) -eq $false) {
Write-Verbose "Updating to revision $revision"
if ((Test-ShouldTryNetworkAccess) -eq $true) {
Exec { svn update --quiet $revisionString }
} else {
Assert ($false) "SVN Repository can't be updated, as there is no network access. To try anyway, pass value '$true' as parameter 'forceNetwork'"
}
} else {
Write-Verbose "Already at revision $revision."
}
} finally {
Pop-Location -ErrorAction Stop
}
} else {
Write-Verbose "$localPathSvnDirectory not found"
Write-Verbose "Checking out svn repository from $repositoryAddress (revision $revision) to $localPath"
if ((Test-ShouldTryNetworkAccess) -eq $true) {
Exec { svn checkout --quiet $revisionString $repositoryAddress $localPath }
} else {
Assert ($false) "SVN Repository can't be checked out, as there is no network access. To try anyway, pass value '$true' as parameter 'forceNetwork'"
}
}
}
}