This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
/
build_release_platform.sh
executable file
·318 lines (272 loc) · 9.85 KB
/
build_release_platform.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/bash
#
# Builds a mod_pagespeed distribution on a buildbot.
#
# Usage:
# 1. Log into buildbot
# 3. ./build_release_platform.sh $RELEASE $CHANNEL [patch_file] [tag]
#
# Where $RELEASE is either the 4 segment version number, e.g 0.10.21.2, or the
# word "trunk" and $CHANNEL is either "beta" or "stable".
#
# The optional "patch_file" will be applied after runing 'gclient sync'.
# Also note that if you re-run the same build command multiple times,
# pre-applied patches will remain.
#
# If tag is specified it will be used to pick what gets checked out, instead of
# $RELEASE; this is useful if applying an unreleased patch that changes the
# version number for a security release.
#
# Updating:
# If you make any changes to this script, please scp it up to the builbotd:
# scp build_release_platform.sh [IP-OF-CENTOS-BUILDBOT]:
# scp build_release_platform.sh [IP-OF-UBUNTU-BUILDBOT]:
#
# The builbots have hardlinks between /home/builbot/build_release_platform.sh
# and /var/chroot/[chroot-name]/home/buildbot/build_release_platform.sh, which
# means that when you update the copy in ~/build_release_platform.sh you're
# automatically updating the one in the chroot as well.
set -e # exit script if any command returns an error
set -u # exit the script if any variable is uninitialized
set -x # print commands as we run them
export VIRTUALBOX_TEST="VIRTUALBOX_TEST" # to skip some tests that fail in VM
RELEASE=$1
CHANNEL=$2
TAG=$RELEASE
do_patch="0"
# Apply optional patch-file to apply before building. To create a patch from a
# commit, do:
# git show [commit id] > patchfile
if [ $# -ge 3 ]; then
patch_file=$(readlink -f $3)
do_patch="1"
fi
if [ $# -eq 4 ]; then
TAG=$4
fi
if [ -d ~/bin/depot_tools ]; then
cd ~/bin/depot_tools
svn update
else
mkdir -p ~/bin
cd ~/bin
svn co https://src.chromium.org/svn/trunk/tools/depot_tools
fi
PATH=~/bin/depot_tools:$PATH
# Are we on RedHat or Ubuntu?
#
# Note that the 'force' directives on the install commands are only
# used for this RPM/DEB build/install/test script, and are not
# exported as a recommended flow for users.
#
# If the force directives are not included, then the installation will
# fail if run a second time.
if [ "$(grep CentOS /etc/issue)" ]; then
EXT=rpm
INSTALL="rpm --install"
RESTART="./centos.sh apache_debug_restart"
TEST="./centos.sh enable_ports_and_file_access apache_vm_system_tests"
echo We appear to be running on CentOS. Building rpm...
else
EXT=deb
INSTALL="dpkg --install"
RESTART="./ubuntu.sh apache_debug_restart"
TEST="./ubuntu.sh apache_vm_system_tests"
echo We appear to NOT be running on CentOS. Building deb...
fi
NBITS=$(getconf LONG_BIT)
if [ "$EXT" = "rpm" ]; then
if [ $NBITS = "32" ]; then
HOMEDIR="/var/chroot/centos_i386/home/buildbot"
else
HOMEDIR="/home/buildbot"
fi
else
if [ $NBITS = "32" ]; then
HOMEDIR="/var/chroot/lucid_i386/home/buildbot"
else
HOMEDIR="/home/buildbot"
fi
fi
if [ $(uname -m) = x86_64 ]; then
BIT_SIZE_NAME=x64
else
BIT_SIZE_NAME=ia32
fi
if [[ "$RELEASE" == 1.9.32.* || "$RELEASE" == 1.10.33.* ]]; then
# Without https://github.com/pagespeed/mod_pagespeed/commit/0e79a08 the font
# inlining tests will fail, and we never backported that fix to 1.9 or 1.10.
export DISABLE_FONT_API_TESTS=1
fi
build_dir="$HOME/build/$RELEASE"
log_dir="$build_dir/log"
rm -rf $log_dir
mkdir -p $log_dir
rm -rf "$HOME/release/$RELEASE"
mkdir -p "$HOME/release/$RELEASE"
# Usage:
# check log_filename.log command args...
#
# The log file will placed in $log_dir, and will be 'tail'ed if the
# command fails.
function check() {
# We are explicitly checking error status here and tailing the log
# file so turn off auto-exit-on-error tempoararily.
set +e
log_filename="$log_dir/$1"
shift
echo "[$(date '+%k:%M:%S')] $@ >> $log_filename"
echo $@ >> "$log_filename"
$@ >> "$log_filename" 2>&1
if [ $? != 0 ]; then
echo '***' status is $?
tail "$log_filename"
echo Failed at $(date)
exit 1
fi
set -e
}
# We do the building in build/ which generates all kinds of crap which
# we don't ship in our binaries, such as .o and .a files.
#
# We put what we want to ship into release/ so that it can be scp'd onto
# the signing server with only one password.
mkdir -p $build_dir
if [ ! -d "$build_dir/src" ]; then
cd $build_dir && git clone https://github.com/pagespeed/mod_pagespeed.git src
fi
cd $build_dir/src && git reset --hard HEAD && git pull --ff-only
if [ "$TAG" != "trunk" ]; then # Just treat "trunk" as master.
git checkout "$TAG"
fi
if [ "$EXT" = "rpm" ] ; then
# On the centos buildbot we need to patch the Makefile to make
# apache_debug_restart to a killall -9 httpd.
cd $build_dir/src
killall_patch=$(cat <<EOF
diff --git a/install/Makefile b/install/Makefile
index 376def9..29fa72e 100644
--- a/install/Makefile
+++ b/install/Makefile
@@ -573,6 +573,7 @@ setup_test_machine :
>sudo \$(APACHE_CONTROL_PROGRAM) restart
apache_debug_restart :
+>killall -9 httpd || echo "not killed"
>\$(APACHE_CONTROL_PROGRAM) restart
apache_debug_stop : stop
EOF)
echo "$killall_patch" | tr '>' '\t' | git apply
fi
cd $build_dir
check gclient.log \
gclient config https://github.com/pagespeed/mod_pagespeed.git --unmanaged --name=src
check gclient.log gclient sync --force
cd src
# Neither buildbot is using a compiler recent enough to provide stdalign.h,
# which boringssl needs. Even on Centos 5's gcc 4.1 we do have a way to set
# alignment, though, so following
# https://sourceware.org/bugzilla/show_bug.cgi?id=19390 define alignas ourself
# and put it where boringssl can find it.
echo '#define alignas(x) __attribute__ ((aligned (x)))' > \
third_party/boringssl/src/crypto/stdalign.h
if [ $do_patch -eq "1" ]; then
echo Applying patch-file $patch_file
git apply $patch_file
echo "Re-running gclient in case the patch touched DEPS"
check gclient.log gclient sync
fi
# This is needed on the vms, but not on our workstations for some reason.
find $build_dir/src -name "*.sh" | xargs chmod +x
cd $build_dir
echo src/build/gyp_chromium -Dchannel=$CHANNEL
export AR_host=$build_dir/src/build/wrappers/ar.sh
check gyp_chromium.log python src/build/gyp_chromium -Dchannel=$CHANNEL
cd src
# It would be better to have AR.target overridden at gyp time, but
# that functionality seems broken.
MODPAGESPEED_ENABLE_UPDATES=1 check build.log \
make BUILDTYPE=Release AR.host=${AR_host} AR.target=${AR_host} V=1 \
linux_package_$EXT mod_pagespeed_test pagespeed_automatic_test
ls -l $PWD/out/Release/mod-pagespeed-${CHANNEL}*
mkdir -p ~/release/$RELEASE
mv $PWD/out/Release/mod-pagespeed-${CHANNEL}* ~/release/$RELEASE
if [ "$EXT" = "rpm" ] ; then
export SSL_CERT_DIR=/etc/pki/tls/certs
export SSL_CERT_FILE=/etc/pki/tls/cert.pem
fi
check unit_test.log out/Release/mod_pagespeed_test
check unit_test.log out/Release/pagespeed_automatic_test
# Buildbots should have NOPASSWD set, so won't need to be prompted for sudo
# password.
echo Purging old releases ...
if [ "$EXT" = "rpm" ] ; then
# rpm --erase only succeeds if all packages listed are installed, so we need
# to find which one is installed and only erase that.
rpm --query mod-pagespeed-stable mod-pagespeed-beta | \
grep -v "is not installed" | \
xargs --no-run-if-empty sudo rpm --erase
else
# dpkg --purge succeeds even if one or both of the packages is not installed.
sudo dpkg --purge mod-pagespeed-beta mod-pagespeed-stable
fi
echo Installing release ...
check install.log sudo $INSTALL $HOME/release/$RELEASE/*.$EXT
echo Test restart to make sure config file is valid ...
cd $build_dir/src/install
check install.log sudo -E $RESTART
echo Testing release ...
check system_test.log sudo -E $TEST
echo Copy the unstripped .so files to a safe place for easier debugging later.
cp $build_dir/src/out/Release/libmod_pagespeed.so \
${HOME}/release/${RELEASE}/unstripped_libmodpagespeed_${NBITS}_${EXT}.so
cp $build_dir/src/out/Release/libmod_pagespeed_ap24.so \
${HOME}/release/${RELEASE}/unstripped_libmodpagespeed_ap24_${NBITS}_${EXT}.so
# Because we now build on the build-bots which are not on the internal network,
# we can't just scp to the signing server. The copying step must be pulled from
# there.
echo Build succeeded at $(date)
cd
echo Pull the release directory from the signing server.
echo $ scp -r buildbot@centos-buildbot:${HOMEDIR}/release/${RELEASE} ~/release
# This doesn't necessarily need to be limited to CentOS, but we only need to
# build PSOL libraries on one system, and CentOS has the oldest GCC, so we
# build it there.
if [ "$EXT" = "rpm" -a "$CHANNEL" = "beta" ]; then
echo Building PSOL binaries ...
for buildtype in Release Debug; do
cd $build_dir/src
check psol_build.log make BUILDTYPE=$buildtype \
AR.host=${AR_host} AR.target=${AR_host} V=1 \
mod_pagespeed_test pagespeed_automatic_test
if [[ "$RELEASE" == 1.9.32.* ]]; then
# On 1.9 (and earlier, but we don't build them anymore) automatic/ was in
# a different place.
automatic_dir=net/instaweb/automatic/
else
automatic_dir=pagespeed/automatic/
fi
cd $automatic_dir
# TODO(sligocki): Fix and use
# check psol_automatic_build.log
set +e
make MOD_PAGESPEED_ROOT=$build_dir/src BUILDTYPE=$buildtype \
AR.host=${AR_host} AR.target=${AR_host} V=1 \
CXXFLAGS="-DSERF_HTTPS_FETCHING=1" \
all \
>> psol_automatic_build.log 2>&1
set -e
cd $build_dir/src
BINDIR=$HOME/psol_release/$RELEASE/psol/lib/$buildtype/linux/$BIT_SIZE_NAME
mkdir -p $BINDIR/
mv $automatic_dir/pagespeed_automatic.a $BINDIR/
if [ "$buildtype" = "Release" ]; then
mv out/$buildtype/js_minify $BINDIR/pagespeed_js_minify
fi
# Sync release binaries incrementally as they're built so we don't
# lose progress.
echo PSOL $buildtype build succeeded at $(date)
# VMs are running low on disk space, so clean up between builds.
rm -rf out/$buildtype
done
fi
exit 0