forked from EventStore/EventStore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·218 lines (179 loc) · 6.94 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
#!/usr/bin/env bash
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PRODUCTNAME="Event Store Open Source"
COMPANYNAME="Event Store LLP"
COPYRIGHT="Copyright 2012 Event Store LLP. All rights reserved."
# ------------ End of configuration -------------
function usage() {
echo <<EOF
Usage:
$0 [<version=0.0.0.0>] [<configuration=release>] [<distro-platform-override>]
Versions must be complete four part idenfitiers valid for use on a .NET assembly.
Valid configurations are:
debug
release
The OS distribution and version will be detected automatically unless it is
overriden as the last argument. This script expects to find libjs1.[so|dylib]
in the src/libs/x64/distroname-distroversion/ directory, built using the scripts
in the scripts/build-js1/ directory. Note that overriding this may result in
crashes using Event Store.
*The only supported Linux for production use at the moment is Ubuntu 14.04 LTS.*
However, since several people have asked for builds compatible with Amazon Linux
in particular, we have included a pre-built version of libjs1.so which will
link to the correct version of libc on Amazon Linux 2015.03.
Currently the supported versions without needing to build libjs1 from source are:
ubuntu-14.04 (Ubuntu Trusty)
amazon-2015.03 (Amazon Linux 2015.03)
EOF
exit 1
}
CONFIGURATION="Release"
function checkParams() {
version=$1
configuration=$2
platform_override=$3
[[ $# -gt 3 ]] && usage
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
if [[ "$platform_override" == "" ]] ; then
# shellcheck source=../detect-system/detect-system.sh disable=SC1091
source "$BASE_DIR/scripts/detect-system/detect-system.sh"
getSystemInformation
CURRENT_DISTRO="$ES_DISTRO-$ES_DISTRO_VERSION"
else
CURRENT_DISTRO=$platform_override
fi
LIBJS1EXT="so"
if [ "$ES_DISTRO" == "osx" ]; then
LIBJS1EXT="dylib"
fi
LIBJS1PATH="$BASE_DIR/src/libs/x64/$CURRENT_DISTRO/libjs1.$LIBJS1EXT"
if [ ! -f "$LIBJS1PATH" ]; then
echo "$LIBJS1PATH does not exist. Did you build libjs1 for this distribution/version?"
exit 1
fi
}
function revertVersionFiles() {
files=$( find . -name "AssemblyInfo.cs" )
for file in $files
do
git checkout "$file"
echo "Reverted $file"
done
}
function revertVersionInfo() {
files=$( find . -name "VersionInfo.cs" )
for file in $files
do
git checkout "$file"
echo "Reverted $file"
done
}
function err() {
revertVersionFiles
revertVersionInfo
echo "FAILED. See earlier messages"
exit 1
}
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 "s/$assemblyVersionPattern/$newAssemblyVersion/g" \
-e "s/$assemblyFileVersionPattern/$newAssemblyFileVersion/g" \
-e "s/$assemblyVersionInformationalPattern/$newAssemblyVersionInformational/g" \
-e "s/$assemblyProductNamePattern/$newAssemblyProductName/g" \
-e "s/$assemblyCopyrightPattern/$newAssemblyCopyright/g" \
-e "s/$assemblyCompanyPattern/$newAssemblyCompany/g" \
"$file" > "$tempfile" || err
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 patchVersionInfo {
branchName=$(git rev-parse --abbrev-ref HEAD)
commitHash=$(git log -n1 --pretty=format:"%H" HEAD)
commitTimestamp=$(git log -n1 --pretty=format:"%aD" HEAD)
newVersion="public static readonly string Version = \"$VERSIONSTRING\";"
newBranch="public static readonly string Branch = \"$branchName\";"
newCommitHash="public static readonly string Hashtag = \"$commitHash\";"
newTimestamp="public static readonly string Timestamp = \"$commitTimestamp\";"
versionPattern="public static readonly string Version .*$"
branchPattern="public static readonly string Branch .*$"
commitHashPattern="public static readonly string Hashtag .*$"
timestampPattern="public static readonly string Timestamp .*$"
files=$( find . -name "VersionInfo.cs" )
for file in $files
do
tempfile="$file.tmp"
sed -e "s/$versionPattern/$newVersion/" \
-e "s/$branchPattern/$newBranch/" \
-e "s/$commitHashPattern/$newCommitHash/" \
-e "s/$timestampPattern/$newTimestamp/" \
"$file" > "$tempfile"
mv "$tempfile" "$file"
echo "Patched $file with version information"
done
}
function linkCurrentJS1 {
mkdir -p "$BASE_DIR/src/libs/x64/current"
for f in $BASE_DIR/src/libs/x64/$CURRENT_DISTRO/*; do
ln -s "$f" "$BASE_DIR/src/libs/x64/current/$(basename "$f")"
done
}
function buildEventStore {
patchVersionFiles
patchVersionInfo
rm -rf bin/
xbuild src/EventStore.sln /p:Platform="Any CPU" /p:Configuration="$CONFIGURATION" || err
revertVersionFiles
revertVersionInfo
}
function exitWithError {
echo "$1"
exit 1
}
checkParams "$1" "$2" "$3"
echo "Running from base directory: $BASE_DIR"
echo "Running on distribution: $CURRENT_DISTRO"
linkCurrentJS1
buildEventStore
rm -rf "$BASE_NAME/src/libs/x64/$CURRENT_DISTRO"