blob: 40264339e438e27337d636d6eadcd7ad19985e16 (
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
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
|
#!/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
#
BUILD_SCRIPT_ROOT=$(readlink -f "$(dirname "${0}")/../build-scripts")
source "${BUILD_SCRIPT_ROOT}"/helpers
REPO_TOOL_URL="https://android.git.linaro.org/gitweb?p=tools/repo.git;a=blob_plain;f=repo;hb=refs/heads/stable"
# 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 <<\EOF
source /var/run/build-tools/build-config
echo $RAMDISK_SIZE
EOF
}
function update-repo-tool () {
curl ${REPO_TOOL_URL} > /tmp/repo
chmod a+x /tmp/repo
mv /tmp/repo /usr/local/bin/repo
}
if is_on_ec2; then
update-repo-tool
fi
mkdir -p $(get_build_config)/build-tools
if ! $BUILD_SCRIPT_ROOT/../node/prepare_build_config.py --base64 "$2"; then
echo "Early exit due to build environment validation failure"
exit 1
fi
# At this point, safely sourceable build config is in /tmp/build-tools/build-config
cat $(get_build_config)/build-tools/build-config
source $(get_build_config)/build-tools/build-config
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"
$BUILD_SCRIPT_ROOT/../node/prepare_build_config.py "$(cat "$BUILD_CONFIG_FILENAME")"
cd $save_dir
source $(get_build_config)/build-tools/build-config
fi
# 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
if is_on_ec2; then
rm -rf build
fi
mkdir -p build
if is_on_ec2; then
ramdisk_size=$(get_ramdisk_size $2)
if [ -z "$ramdisk_size" ]; then
ramdisk_size=0
fi
fi
# Put build/* on a ramdisk to speed up build
if is_on_ec2; then
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
else
mkdir build/out
fi
if is_on_ec2; then
chown :nogroup -R /mnt/jenkins
chown jenkins-build:nogroup -R build
fi
cd build
if is_on_ec2; then
exec_cmd="sudo -E -H -u jenkins-build bash"
else
exec_cmd="bash"
fi
$exec_cmd -xes "${BUILD_SCRIPT_ROOT}" "$@" <<\EOF
export BUILD_SCRIPT_ROOT="${1}"
HOST="${2}"
source "${BUILD_SCRIPT_ROOT}"/helpers
set -a
source $(get_build_config)/build-tools/build-config
set +a
# 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
|