-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild
executable file
·250 lines (219 loc) · 7.59 KB
/
build
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
#!/bin/sh
#
# Copyright (c) 2014, Simon J Mudd <[email protected]>. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston
# MA 02110-1301 USA.
#
# Build script for WebScaleSQL RPMs.
#
# Usage: build [<webscalesql git directory>]
#
# Will store this as a variable if defined in .webscalerc so it
# can be used on subsequent calls.
#
[ -n "$DEBUG" ] && set -x
myname=$(basename $0)
myhostname=$(hostname -s)
mydir=$(dirname $0)
[ "$mydir" = . ] && mydir=$PWD
set -e
# standard logging routines
msg_info () {
echo "$(date +'%b %d %H:%M:%S') $myhostname $myname[$$]: $*"
}
msg_fatal () {
msg_info "FATAL: $*"
exit 1
}
# build the rpm
build () {
local rc
local logfile=$mydir/build.log.$(date +%Y%m%d.%H%M%S)
# now do the real build.
msg_info "Logging to $logfile"
# move to build directory
cd $specdir
(
set -o pipefail
msg_info "Building webscalesql rpms..."
MYSQL_BUILD_PATH=$DEVTOOLSET_DIR:$PATH \
MYSQL_BUILD_CC=$DEVTOOLSET_DIR/gcc \
MYSQL_BUILD_CXX=$DEVTOOLSET_DIR/c++ \
rpmbuild -ba --define "distro_specific 1" $specfile 2>&1 | tee -a $logfile
)
# check return status
rc=$?
test -f $logfile && gzip -9 $logfile
if [ $rc = 0 ]; then
msg_info "OK: Build completed successfully"
else
msg_fatal "Build failed"
fi
}
# Copy the local spec file from the webscalesql-rpm directory to rpm's specdir
copy_spec_file () {
if test -e $specdir/$specfile && cmp -s $specfile $specdir/$specfile; then
msg_info "OK: spec file $specfile is up to date"
else
msg_info "Copying spec file $specfile to $specdir"
cp -p $specfile $specdir/
fi
}
# build a tar ball, from the head of the branch we are on
create_tarball () {
local wss=$1
local mysql_version=$2
local wss_commits=$3
local tarball=$4
msg_info "Creating tar ball $tarball in $sourcedir from ${WSS_HOME}"
(
set -o pipefail
cd ${WSS_HOME} && git archive --format=tar --prefix=${wss}-${mysql_version}.${wss_commits}/ HEAD | gzip -9 > $sourcedir/$tarball
)
# check return status
rc=$?
if [ $rc = 0 ]; then
msg_info "OK: tarball created successfully"
else
msg_fatal "Tarball creation failed"
fi
}
# Check if the version/release needs changing and adjust if needed.
# If changed add a new changelog entry indicating this.
#
# As per message by Steaphan Greene on 11 April at 20:22
# we name the packages as <mysql_version>-<commits>.
#
# However, rpm gets rather upset with - in a version number
# so I've replaced this with a . instead.
#
# Version taken from:
#[sjmudd@builder webscalesql-5.6]$ git branch
#* webscalesql-5.6.17
#
# so 5.6.17
#
# commits taken from:
#[sjmudd@builder webscalesql-5.6]$ git log | grep -c ^commit
#68
# so 68
#
# and patch the spec file here.
#%global mysql_version 5.6.17.68
#
patch_spec_file () {
local mysql_version=$1
local commits=$2
local wss_version=$mysql_version.$commits
local spec_version=$(grep ^%global.webscalesql_version $mydir/$specfile | sed -e 's/%global webscalesql_version[[:space:]]*//')
if [ "$wss_version" = "$spec_version" ]; then
msg_info "OK: $mydir/$specfile has the right %global mysql_version value: $spec_version"
rc=1
else
msg_info "Patching $mydir/$specfile with new %global webscale_version value: $wss_version"
sed -i -e "/^%global webscalesql_version/ s/$spec_version/$wss_version/" $mydir/$specfile
patch_changelog $wss_version
fi
}
# Patch the spec file's %changelog with the change that has been made.
# fix me and figure out what to put here.
# * Sun Mar 30 2014 Simon J Mudd <[email protected]> <version>-<release>
# - build webscalesql from latest webscalesql commit at $ts
patch_changelog () {
local current_date=$(date +'%a %b %d %Y')
local username=$(id -un)
local hostname=$(hostname)
local wss_version=$1
msg_info "Adding a new %changelog entry to $mydir/$specfile"
sed -i -e "
# Add a new changelog entry
/^%changelog/ {
a\\
* $current_date <$username@$hostname>
a\\
- build $wss from latest $wss commit $wss_version
a\\
}
" $mydir/$specfile
}
msg_info "WebScaleSQL RPM Builder (C) 2014 Simon J Mudd <[email protected]>"
# Location of devtools bin path
if rpm -q devtoolset-2-gcc >/dev/null 2>&1; then
DEVTOOLSET_DIR=/opt/rh/devtoolset-2/root/usr/bin
msg_info "DEVTOOLSET_DIR=$DEVTOOLSET_DIR (Using devtoolset-2 for building)"
elif rpm -q devtoolset-1.1 >/dev/null 2>&1; then
DEVTOOLSET_DIR=/opt/centos/devtoolset-1.1/root/usr/bin
msg_info "DEVTOOLSET_DIR=$DEVTOOLSET_DIR (Using devtoolset-1.1 for building)"
else
msg_info "WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
msg_info "WARNING: devtoolset rpm does not seem to be installed."
msg_info "WARNING: The build of WebScaleSQL may fail."
msg_info "WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
sleep 5
fi
# setup some default values
rcfile=$mydir/.webscalesqlrc
# source rc file if found
test -f $rcfile && . $rcfile
if [ $# = 1 ]; then
WSS_HOME=$1
test -d $WSS_HOME ||\
msg_fatal "Directory $1 not found"
echo "WSS_HOME=$WSS_HOME" > $rcfile
msg_info "Writing WSS_HOME to $rcfile"
fi
# Check for location of the WebScaleSQL directory
[ -n "$WSS_HOME" ] ||\
msg_fatal "WSS_HOME (directory of webscalesql git tree) unknown"
# Allow us to build with performance_schema
# - the environment variable being set is picked up by the spec file
if [ -n "$WITH_PERFORMANCE_SCHEMA" ]; then
msg_info "Building with performance_schema enabled (as requested)"
else
msg_info "Building with performance_schema disabled (default WebScaleSQL behaviour)"
msg_info "( to enable performance_schema set WITH_PERFORMANCE_SCHEMA=1 when calling build )"
fi
wss=webscalesql # long name, too much typing
wss_version=5.6
mysql_version=$(cd $WSS_HOME && git branch | grep ^\* | grep webscalesql- | sed -e 's/.*webscalesql-//')
wss_commits=$(cd $WSS_HOME && git log | grep -c ^commit)
msg_info "WebScaleSQL base MySQL version: $mysql_version"
msg_info "WebScaleSQL commits since: $wss_commits"
tarball=${wss}-${mysql_version}.${wss_commits}.tar.gz
specfile=$wss.spec
# We need to ask rpm for the location of various directories, which
# may depend on how we have setup ~/.rpmmacros. the %{name} substitution
# may be needed depending on usage, otherwise it's a noop.
# If I check one directory is there as needed I need to check them all...
topdir=$( rpm --eval '%{_topdir}' )
specdir=$( rpm --eval '%{_specdir}' | sed -e "s|/%{name}|/$wss|")
sourcedir=$( rpm --eval '%{_sourcedir}' | sed -e "s|/%{name}|/$wss|")
rpmdir=$( rpm --eval '%{_rpmdir}' | sed -e "s|/%{name}|/$wss|")
srcrpmdir=$( rpm --eval '%{_srcrpmdir}' | sed -e "s|/%{name}|/$wss|")
buildrootdir=$(rpm --eval '%{_buildrootdir}')
# create needed directories
msg_info "Checking required rpm build directory tree..."
for d in $topdir $specdir $sourcedir $rpmdir $srcrpmdir $buildrootdir; do
if test -n "$d" -a "$d" != "/" -a ! -d $d; then
msg_info "Creating missing directory: $d"
mkdir -p $d
fi
done
msg_info "specdir=$specdir (rpm location of spec files)"
msg_info "sourcedir=$sourcedir (rpm location of source files)"
patch_spec_file $mysql_version $wss_commits
copy_spec_file
create_tarball $wss $mysql_version $wss_commits $tarball
build