blob: b5afe52304b3929b2dce8dac2f95bae690baaabb (
plain)
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
|
#!/bin/bash
###############################################################################
# Copyright (c) 2011 Linaro
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
###############################################################################
#
# $1 = mirror service host
# $2 = build CONFIG, base64-encoded
#
# Dump system release to build log
echo
cat /etc/issue
set -xe
# We need ramdisk size when executing under root, but still don't want
# to evaluate build config (== arbitrary code) as such.
function get_ramdisk_size () {
sudo -E -H -u jenkins-build bash -es "$1" <<\EOF
export CONFIGURATION="$(echo "$1" | base64 -id)"
set -a
eval "$CONFIGURATION"
set +a
echo $RAMDISK_SIZE
EOF
}
BUILD_SCRIPT_ROOT=$(readlink -f "$(dirname "${0}")/../build-scripts")
# Stopgap measure to cleanup environment on instances reused for different jobs
mount | grep -E "^tmpfs on .+workspace/" | awk ' {print $3}' | xargs --no-run-if-empty -n1 umount
umount build/out/target || true
umount build/out || true
umount build || true
rm -rf build
mkdir build
ramdisk_size=$(get_ramdisk_size $2)
# Put build/* on a ramdisk to speed up build
if [ -z "$ramdisk_size" -o "$ramdisk_size" != "0" ]; then
mem_total=`cat /proc/meminfo | grep MemTotal | sed -s 's/[^0-9]*\([0-9]*\) kB/\1/'`
if [ "$mem_total" -gt 15680064 ]; then
ramdisk_size=${ramdisk_size:-11750M}
echo "Using $ramdisk_size tmpfs for build"
mount -t tmpfs -o size=$ramdisk_size tmpfs build
elif [ "$mem_total" -gt 12485760 ]; then
# XXX mounting build/out/target on a tmpfs is probably a bit android specific...
ramdisk_size=${ramdisk_size:-11G}
echo "Using $ramdisk_size tmpfs for build/out/target"
mkdir -p build/out/target
mount -t tmpfs -o size=$ramdisk_size tmpfs build/out/target
else
mkdir build/out
fi
fi
chown jenkins-build:nogroup -R build
cd build
sudo -E -H -u jenkins-build bash -xes "${BUILD_SCRIPT_ROOT}" "$@" <<\EOF
export BUILD_SCRIPT_ROOT="${1}"
HOST="${2}"
export CONFIGURATION="$(echo "${3}" | base64 -id)"
set -a
eval "$CONFIGURATION"
set +a
if [ -n "$BUILD_CONFIG_REPO" ]; then
echo "Fetching build config indirectly from git"
save_dir=$PWD
rm -rf /tmp/buildconf.$$
mkdir -p /tmp/buildconf.$$
cd /tmp/buildconf.$$
git clone "$BUILD_CONFIG_REPO"
cd *
git checkout "$BUILD_CONFIG_BRANCH"
CONFIGURATION=$(cat "$BUILD_CONFIG_FILENAME")
cd $save_dir
set -a
eval $CONFIGURATION
set +a
fi
# Backward compatibility with SCRIPT_NAME
if [ -n "$SCRIPT_NAME" ]; then
BUILD_TYPE="$SCRIPT_NAME"
echo "WARNING: SCRIPT_NAME is deprecated, use BUILD_TYPE instead"
fi
if [ -z "$BUILD_TYPE" ]; then
BUILD_TYPE=build-android
fi
if [ "$(echo "$BUILD_TYPE" | sed -n -e 's/^[-a-zA-Z_]\+$/&/p')" != "$BUILD_TYPE" ]; then
echo "Invalid BUILD_TYPE: $BUILD_TYPE"
exit 1
fi
exec bash -xe "${BUILD_SCRIPT_ROOT}/${BUILD_TYPE}" "${HOST}"
EOF
|