forked from EventStore/EventStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·290 lines (247 loc) · 8.33 KB
/
build.sh
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
#------------ Start of configuration -------------
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
V8_TAG="3.19.7"
PRODUCTNAME="Event Store Open Source"
COMPANYNAME="Event Store LLP"
COPYRIGHT="Copyright 2012 Event Store LLP. All rights reserved."
#------------ End of configuration -------------
function usage() {
echo ""
echo "Usage: $0 action <version=0.0.0.0> <platform=x64> <configuration=release>"
echo ""
echo "Valid actions are:"
echo " quick - assumes libjs1.so and libv8.so are available and"
echo " fails if this is not the case."
echo ""
echo " incremental - always rebuilds libjs1.so, but will only"
echo " build V8 if libv8.so is not available."
echo ""
echo " full - will clean the repository prior to building. This"
echo " always builds libv8.so and libjs1.so."
echo ""
echo "Valid platforms are:"
echo " x86"
echo " x64"
echo ""
echo "Valid configurations are:"
echo " debug"
echo " release"
echo ""
exit 1
}
ACTION="quick"
PLATFORM="x64"
CONFIGURATION="Release"
function checkParams() {
action=$1
version=$2
platform=$3
configuration=$4
[[ $# -gt 4 ]] && usage
if [[ "$action" = "" ]]; then
ACTION="quick"
echo "Action defaulted to: $ACTION"
else
if [[ "$action" == "quick" || "$action" == "incremental" || "$action" == "full" ]]; then
ACTION=$action
echo "Action set to: $ACTION"
else
echo "Invalid action: $action"
usage
fi
fi
if [[ "$platform" == "" ]]; then
PLATFORM="x64"
echo "Platform defaulted to: $PLATFORM"
else
if [[ "$platform" == "x64" || "$platform" == "x86" ]]; then
PLATFORM=$platform
echo "Platform set to: $PLATFORM"
else
echo "Invalid platform: $platform"
usage
fi
fi
if [[ "$configuration" == "" ]]; then
CONFIGURATION="release"
echo "Configuration defaulted to: $CONFIGURATION"
else
if [[ "$configuration" == "release" || "$configuration" == "debug" ]]; then
CONFIGURATION=$configuration
echo "Configuration set to: $CONFIGURATION"
else
echo "Invalid configuration: $configuration"
usage
fi
fi
if [[ "$version" == "" ]] ; then
VERSIONSTRING="0.0.0.0"
echo "Version defaulted to: 0.0.0.0"
else
VERSIONSTRING=$version
echo "Version set to: $VERSIONSTRING"
fi
}
function revertVersionFiles() {
files=$( find . -name "AssemblyInfo.cs" )
for file in $files
do
git checkout $file
echo "Reverted $file"
done
}
function err() {
revertVersionFiles
echo "FAILED. See earlier messages"
exit 1
}
function getV8() {
tag=$1
if [[ -d v8 ]] ; then
pushd v8 > /dev/null || err
gittag=`git describe --contains HEAD`
if [[ "$gittag" != "$tag" ]] ; then
echo "Pulling V8 repository..."
git pull || err
echo "Checking out $tag..."
git checkout $tag || err
else
echo "V8 repository already at $gittag"
fi
popd > /dev/null || err
else
echo "Cloning V8 repository..."
git clone git://github.com/v8/v8.git v8 || err
pushd v8 > /dev/null || err
echo "Checking out $tag..."
git checkout $tag
popd > /dev/null || err
fi
}
function getDependencies() {
if [[ -d v8/build/gyp ]] ; then
pushd v8/build/gyp > /dev/null || err
svnrevision=`svn info | sed -ne 's/^Revision: //p'`
popd > /dev/null || err
fi
pushd v8 > /dev/null || err
if [[ "$svnrevision" -ne "1501" ]] ; then
make dependencies || err
else
echo "GYP already up to date (r $svnrevision)"
fi
popd > /dev/null || err
}
function buildV8() {
pushd v8 > /dev/null || err
if [[ "$PLATFORM" -eq "x64" ]] ; then
makecall="x64.$CONFIGURATION"
elif [[ "$PLATFORM" -eq "x86" ]] ; then
makecall="ia32.$CONFIGURATION"
else
echo "Unsupported platform $PLATFORM."
exit 1
fi
make $makecall library=shared || err
pushd out/$makecall/lib.target > /dev/null
cp libv8.so ../../../../src/EventStore/libs || err
popd > /dev/null
[[ -d ../src/EventStore/libs/include ]] || mkdir ../src/EventStore/libs/include
pushd include > /dev/null || err
cp *.h ../../src/EventStore/libs/include || err
popd > /dev/null || err
popd > /dev/null || err
}
function buildJS1() {
currentDir=$(pwd -P)
includeString="-I $currentDir/src/EventStore/libs/include"
libsString="-L $currentDir/src/EventStore/libs"
outputDir="$currentDir/src/EventStore/libs"
pushd $currentDir/src/EventStore/EventStore.Projections.v8Integration/ > /dev/null || err
if [[ "$ARCHITECTURE" == "x86" ]] ; then
gccArch="-arch i386"
elif [[ "$ARCHITECTURE" == "x64" ]] ; then
gccArch="-arch amd64"
fi
g++ $includeString $libsString *.cpp -o $outputDir/libjs1.so $gccArch -lv8 -O2 -fPIC --shared --save-temps || err
popd > /dev/null || err
}
function patchVersionFiles {
branchName=`git rev-parse --abbrev-ref HEAD`
commitHashAndTime=`git log -n1 --pretty=format:"%H@%aD" HEAD`
newAssemblyVersion="[assembly: AssemblyVersion(\"$VERSIONSTRING\")]"
newAssemblyFileVersion="[assembly: AssemblyFileVersion(\"$VERSIONSTRING\")]"
newAssemblyVersionInformational="[assembly: AssemblyInformationalVersion(\"$VERSIONSTRING.$branchName@$commitHashAndTime\")]"
newAssemblyProductName="[assembly: AssemblyProduct(\"$PRODUCTNAME\")]"
newAssemblyCopyright="[assembly: AssemblyCopyright(\"$COPYRIGHT\")]"
newAssemblyCompany="[assembly: AssemblyCompany(\"$COMPANYNAME\")]"
assemblyVersionPattern='AssemblyVersion(.*'
assemblyFileVersionPattern='AssemblyFileVersion(.*'
assemblyVersionInformationalPattern='AssemblyInformationalVersion(.*'
assemblyProductNamePattern='AssemblyProduct(.*'
assemblyCopyrightPattern='AssemblyCopyright(.*'
assemblyCompanyPattern='AssemblyCompany(.*'
files=$( find . -name "AssemblyInfo.cs" )
for file in $files
do
tempfile="$file.tmp"
sed -e "/$assemblyVersionPattern/c\
$newAssemblyVersion" -e "/$assemblyFileVersionPattern/c\
$newAssemblyFileVersion" -e "/$assemblyVersionInformationalPattern/c\
$newAssemblyVersionInformational" -e "/$assemblyProductNamePattern/c\
$newAssemblyProductName" -e "/$assemblyCopyrightPattern/c\
$newAssemblyCopyright" -e "/$assemblyCompanyPattern/c\
$newAssemblyCompany" $file > $tempfile
mv $tempfile $file
if grep "AssemblyInformationalVersion" $file > /dev/null ; then
echo "Patched $file with version information"
else
echo " " >> $file
echo $newAssemblyVersionInformational >> $file
echo "Patched $file with version information"
fi
done
}
function buildEventStore {
patchVersionFiles
rm -rf bin/
xbuild src/EventStore/EventStore.sln /p:Platform="Any CPU" /p:Configuration="$CONFIGURATION" || err
revertVersionFiles
}
function cleanAll {
rm -rf bin/
rm -f src/EventStore/libs/libv8.so
rm -f src/EventStore/libs/libjs1.so
pushd v8 > /dev/null
git clean --quiet -e gyp -fdx -- build
git clean --quiet -dfx -- src
git clean --quiet -dfx -- test
git clean --quiet -dfx -- tools
git clean --quiet -dfx -- preparser
git clean --quiet -dfx -- samples
git reset --quiet --hard
popd > /dev/null
pushd src/EventStore/EventStore.Projections.v8Integration > /dev/null
git clean --quiet -dfx -- .
popd > /dev/null
}
function exitWithError {
echo $1
exit 1
}
checkParams $1 $2 $3 $4
echo "Running from base directory: $BASE_DIR"
if [[ "$ACTION" == "full" ]] ; then
cleanAll
fi
if [[ "$ACTION" == "incremental" || "$ACTION" == "full" ]] ; then
getV8 $V8_TAG
getDependencies
buildV8
buildJS1
buildEventStore
else
[[ -f src/EventStore/libs/libv8.so ]] || exitWithError "Cannot find libv8.so - cannot do a quick build!"
[[ -f src/EventStore/libs/libjs1.so ]] || exitWithError "Cannot find libjs1.so - cannot do a quick build!"
buildEventStore
fi