forked from kurrent-io/KurrentDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative-code.ps1
More file actions
291 lines (243 loc) · 12.1 KB
/
native-code.ps1
File metadata and controls
291 lines (243 loc) · 12.1 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# Event Store Build (.NET/Windows) - v8.ps1
# Use Invoke-psake ? to see further description
Framework "4.0x64"
Task default -depends ?
Task ? -description "Writes script documentation to the host" {
Write-Host "Builds the Event Store native portions. See default.ps1 for more info."
}
# Overridable version and other metadata
Properties {
$versionString = "0.0.0.0"
$productName = "Event Store Open Source"
$companyName = "Event Store LLP"
$copyright = "Copyright 2012 Event Store LLP. All rights reserved."
}
# Directories and solutions
Properties {
$baseDirectory = Resolve-Path .
$srcDirectory = Join-Path $baseDirectory (Join-Path "src" "EventStore")
$libsDirectory = Join-Path $srcDirectory "libs"
$v8Directory = Join-Path $baseDirectory "v8"
$pythonExecutable = Join-Path $v8Directory (Join-Path "third_party" (Join-Path "python_26" "python.exe"))
$js1Project = Join-Path $srcDirectory (Join-Path "EventStore.Projections.v8Integration" "EventStore.Projections.v8Integration.vcxproj")
$js1VersionResource = Join-Path $srcDirectory (Join-Path "EventStore.Projections.v8Integration" "EventStore.Projections.v8Integration.rc")
}
# Configuration
Properties {
if ($platform -eq "x64")
{
# The parameter to pass to Gyp to generate projects for the appropriate architecture
$v8PlatformParameter = "-Dtarget_arch=x64"
# The platform name for V8 (as generated by gyp)
$v8VisualStudioPlatform = "x64"
# The destination for the built V8 libraries to be copied to
$v8LibsDestination = Join-Path $libsDirectory "x64"
# The platform for JS1 (as defined in the project file)
$js1VisualStudioPlatform = "x64"
}
elseif ($platform -eq "x86")
{
# The parameter to pass to Gyp to generate projects for the appropriate architecture
$v8VisualStudioPlatform = "Win32"
# The platform name for V8 (as generated by Gyp)
$v8PlatformParameter = "-Dtarget_arch=Win32"
# The destination for the built V8 libraries to be copied to
$v8LibsDestination = Join-Path $libsDirectory "Win32"
# The platform for JS1 (as defined in the project file)
$js1VisualStudioPlatform = "Win32"
}
else
{
throw "Platform $platform is not supported."
}
if ($configuration -eq "release")
{
# The configuration name for V8 (as generated by Gyp)
$v8VisualStudioConfiguration = "Release"
# The destination V8 is built in (as generated by Gyp)
$v8OutputDirectory = Join-Path $v8Directory (Join-Path "build" (Join-Path "Release" "lib"))
# The configuration name for JS1 (as defined in the project file)
$js1VisualStudioConfiguration = "Release"
}
elseif ($configuration -eq "debug")
{
# The configuration name for V8 (as generated by Gyp)
$v8VisualStudioConfiguration = "Debug"
# The destination V8 is built in (as generated by Gyp)
$v8OutputDirectory = Join-Path $v8Directory (Join-Path "build" (Join-Path "Debug" "lib"))
# The configuration name for JS1 (as defined in the project file)
$js1VisualStudioConfiguration = "Debug"
}
else
{
throw "Configuration $configuration is not supported. If you think it should be, edit the Setup-ConfigurationParameters task to add it."
}
}
Task Build-NativeFull -Depends Clean-V8, Build-V8, Copy-V8ToLibs, Patch-JS1VersionResource, Build-JS1, Revert-JS1VersionResource
Task Build-NativeIncremental -Depends Build-V8, Copy-V8ToLibs, Patch-JS1VersionResource, Build-JS1, Revert-JS1VersionResource
Task Clean-V8 {
Push-Location $v8Directory
Exec { git clean --quiet -e gyp -fdx -- build }
Exec { git clean --quiet -dfx -- src }
Exec { git clean --quiet -dfx -- test }
Exec { git clean --quiet -dfx -- tools }
Exec { git clean --quiet -dfx -- preparser }
Exec { git clean --quiet -dfx -- samples }
Exec { git reset --quiet --hard }
Pop-Location
}
Task Build-V8 {
Push-Location $v8Directory
try {
$gypFile = Join-Path $v8Directory (Join-Path "build" "gyp_v8")
$commonGypiPath = Join-Path $v8Directory (Join-Path "build" "common.gypi")
$includeParameter = "-I$commonGypiPath"
if ($platformToolset -eq $null) {
$platformToolset = Get-BestGuessOfPlatformToolsetOrDie($v8VisualStudioPlatform)
}
Exec { & $pythonExecutable $gypFile $includeParameter $v8PlatformParameter }
Exec { msbuild .\build\all.sln /m /p:Configuration=$v8VisualStudioConfiguration /p:Platform=$v8VisualStudioPlatform /p:PlatformToolset=$platformToolset }
} finally {
Pop-Location
}
}
Task Patch-JS1VersionResource {
$commitHashAndTimestamp = Get-GitCommitHashAndTimestamp
$branchName = Get-GitBranchOrTag
Write-Verbose "Patching $js1VersionResource with product information."
Patch-VersionResource $js1VersionResource $versionString $versionString $branchName $commitHashAndTimestamp $productName $companyName $copyright
}
Task Revert-JS1VersionResource {
Write-Verbose "Reverting $js1VersionResource to original state."
& { git checkout --quiet $js1VersionResource }
}
Task Copy-V8ToLibs -Depends Build-V8 {
$v8IncludeDestination = Join-Path $libsDirectory "include"
$v8LibsSource = Join-Path $v8OutputDirectory "*.lib"
$v8IncludeSource = Join-Path $v8Directory (Join-Path "include" "*.h")
New-Item -ItemType Container -Path $v8LibsDestination -ErrorAction SilentlyContinue
Copy-Item $v8LibsSource $v8LibsDestination -Recurse -Force -ErrorAction Stop
New-Item -ItemType Container -Path $v8IncludeDestination -ErrorAction SilentlyContinue
Copy-Item $v8IncludeSource $v8IncludeDestination -Recurse -Force -ErrorAction Stop
Push-Location $v8LibsDestination
#V8 build changed at some point to include the platform in the
# name of the lib file. Where we use V8 we still use the old names
# so rename here if necessary.
foreach ($libFile in Get-ChildItem) {
$newName = $libFile.Name.Replace(".x64.lib", ".lib")
if ($newName -ne $libFile.Name) {
if (Test-Path $newName) {
Remove-Item $newName -Force
}
Rename-Item -Path $libFile -NewName $newName
}
}
Pop-Location
}
Task Build-JS1 {
if ($platformToolset -eq $null) {
$platformToolset = Get-BestGuessOfPlatformToolsetOrDie($js1VisualStudioPlatform)
Write-Verbose "Projections Integration PlatformToolset: Determined to be $platformToolset"
} else {
Write-Verbose "Projections Integration PlatformToolset: Set to $platformToolset"
}
Exec { msbuild $js1Project /p:Configuration=$js1VisualStudioConfiguration /p:Platform=$js1VisualStudioPlatform /p:PlatformToolset=$platformToolset }
}
# Helper Functions
Function Get-BestGuessOfPlatformToolsetOrDie {
[CmdletBinding()]
Param(
[Parameter()][string]$platform = "x64"
)
Process {
if (Test-Path 'Env:\ProgramFiles(x86)') {
$programFiles = ${env:ProgramFiles(x86)}
} else {
$programFiles = ${env:ProgramFiles}
}
$mscppDir = Join-Path $programFiles (Join-Path "MSBuild" (Join-Path "Microsoft.Cpp" "v4.0"))
Assert (Test-Path $mscppDir) "$mscppDir does not exist. It appears this machine either does not have MSBuild and C++ installed, or it's in a weird place. Specify the platform toolset manually as a parameter."
# Platform toolset for VS2010 might be here...
$potentialV110Dir = Join-Path $mscppDir "V110"
# Older ones might be in here...
$platformToolsetsDir = Join-Path $mscppDir (Join-Path "Platforms" (Join-Path $platform "PlatformToolsets"))
if ((Test-Path $platformToolsetsDir) -eq $false) {
if (Test-Path $potentialV110Dir) {
return "V110"
} else {
Assert ($false) "Can't find any supported platform toolset (V100, V110, Windows7.1SDK). It's possible that this detection is wrong, in which case you should specify the platform toolset manually as a parameter."
}
} else {
if (Test-Path (Join-Path $platformToolsetsDir "Windows7.1SDK")) {
return "Windows7.1SDK"
} elseif (Test-Path (Join-Path $platformToolsetsDir "V100")) {
return "V100"
} else {
#Failing that V110 toolset (VS2012)
if (Test-Path $potentialV110Dir) {
return "V110"
} else {
Assert ($false) "Can't find any supported platform toolset (V100, V110, Windows7.1SDK). It's possible that this detection is wrong, in which case you should specify the platform toolset manually as a parameter."
}
}
}
}
}
Function Get-GitCommitHashAndTimestamp
{
$lastCommitLog = Exec { git log --max-count=1 --pretty=format:%H@%aD HEAD } "Cannot execute git log. Ensure that the current directory is a git repository and that git is available on PATH."
return $lastCommitLog
}
Function Get-GitBranchOrTag
{
$revParse = Exec { git rev-parse --abbrev-ref HEAD } "Cannot execute git rev-parse. Ensure that the current directory is a git repository and that git is available on PATH."
if ($revParse -ne "HEAD") {
return $revParse
}
$describeTags = Exec { git describe --tags } "Cannot execute git describe. Ensure that the current directory is a git repository and that git is available on PATH."
return $describeTags
}
Function Patch-VersionResource {
Param(
[Parameter(Mandatory=$true)][string]$versionResourcePath,
[Parameter(Mandatory=$true)][string]$version,
[Parameter(Mandatory=$true)][string]$fileVersion,
[Parameter(Mandatory=$true)][string]$branch,
[Parameter(Mandatory=$true)][string]$commitHashAndTimestamp,
[Parameter(Mandatory=$true)][string]$productName,
[Parameter(Mandatory=$true)][string]$companyName,
[Parameter()][string]$copyright
)
Process {
$separatedVersion = $version -replace "\.", ","
$separatedFileVersion = $fileVersion -replace "\.", ","
$newProductNameStr = '#define EVENTSTORE_PRODUCTNAME_STR "' + $productName + '"'
$newProductVersionStr = '#define EVENTSTORE_PRODUCTVERSION_STR "' + $version + '"'
$newProductVersion = '#define EVENTSTORE_PRODUCTVERSION ' + $separatedVersion
$newFileVersionStr = '#define EVENTSTORE_FILEVERSION_STR "' + $fileVersion + '"'
$newFileVersion = '#define EVENTSTORE_FILEVERSION ' + $separatedFileVersion
$newCommitNumberStr = '#define EVENTSTORE_COMMITNUMBER_STR "' + $version + '.' + $branch + '@' + $commitHashAndTimestamp + '"'
$newCopyrightStr = '#define EVENTSTORE_COPYRIGHT_STR "' + $copyright + '"'
$newProductNameStrPattern = '#define EVENTSTORE_PRODUCTNAME_STR.*$'
$newProductVersionStrPattern = '#define EVENTSTORE_PRODUCTVERSION_STR.*$'
$newProductVersionPattern = '#define EVENTSTORE_PRODUCTVERSION .*$'
$newFileVersionStrPattern = '#define EVENTSTORE_FILEVERSION_STR.*$'
$newFileVersionPattern = '#define EVENTSTORE_FILEVERSION .*$'
$newCommitNumberStrPattern = '#define EVENTSTORE_COMMITNUMBER_STR.*$'
$newCopyrightStrPattern = '#define EVENTSTORE_COPYRIGHT_STR.*$'
$edited = (Get-Content $versionResourcePath) | ForEach-Object {
% {$_ -replace "\/\*+.*\*+\/", "" } |
% {$_ -replace "\/\/+.*$", "" } |
% {$_ -replace "\/\*+.*$", "" } |
% {$_ -replace "^.*\*+\/\b*$", "" } |
% {$_ -replace $newProductNameStrPattern, $newProductNameStr } |
% {$_ -replace $newProductVersionStrPattern, $newProductVersionStr } |
% {$_ -replace $newProductVersionPattern, $newProductVersion } |
% {$_ -replace $newFileVersionStrPattern, $newFileVersionStr } |
% {$_ -replace $newFileVersionPattern, $newFileVersion } |
% {$_ -replace $newCommitNumberStrPattern, $newCommitNumberStr } |
% {$_ -replace $newCopyrightStrPattern, $newCopyrightStr }
}
Set-Content -Path $versionResourcePath -Value $edited
}
}