aboutsummaryrefslogtreecommitdiff
path: root/build-scripts/create-user-build-script
blob: 1b0a6d728dda5112ded7900171e8b6124056f22b (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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/bin/bash

set -e

source "${BUILD_SCRIPT_ROOT}"/helpers
setup-repo-vars

#Translate
#  https://android-build.linaro.org/jenkins/job/doanac_build-script-generation/6/
# into
#  http://snapshots.linaro.org/android/~doanac/build-script-generation/6/
PINNED_MANIFEST_URL=${BUILD_URL/http*jenkins\/job\//http://snapshots.linaro.org/android/~}
# change the dash in doanac_build... to doanac/build...
PINNED_MANIFEST_URL=${PINNED_MANIFEST_URL/_/\/}

if [ -n "$SOURCE_OVERLAY" ]; then
	USAGE_SUM="'Usage: \$0 -m <manifest.xml> -o <overlay.tar> [ -t -d directory -l login ]'"
	USAGE_OVERLAY="'\\n -m <manifest>    If -t is not used, then using a browser with cookies you\\n                  must download the pinned manifest from:\\n             $PINNED_MANIFEST_URL\\n -o               The path to the vendor required overlay.\\n                  Can be downloaded from http://snapshots.linaro.org/android/binaries/$SOURCE_OVERLAY\\n'"
	USAGE_OPTOVERLAY="m:o:"
	USAGE_OPTHANDLER="o   ) SOURCE_OVERLAY=\$OPTARG; SOURCE_OVERLAY_OPTIONAL=0;;  m   ) MANIFEST=\`readlink -f \$OPTARG\`; EXACT=1;;"
else
	USAGE_SUM="'Usage: \$0 [ -t -d directory -l login ]'"
fi

header()
{
	cat <<EOF
#!/bin/bash
# Author+=amit.pundir@linaro.org

set -e

EXACT=0
INTERACTIVE=1
DIR=android
if [ -z "\${LINARO_ANDROID_ACCESS_ID}" ] ; then
	LINARO_ANDROID_ACCESS_ID=\${USER}
fi
SOURCE_OVERLAY_OPTIONAL=1

usage()
{
	echo $USAGE_SUM
	echo -e $USAGE_OVERLAY
	echo " -t                Reproduce the build from the tip of the branch rather than doing"
	echo "                   an exact replica build"
	echo " -d <directory>    The directory to download code and build from"
	echo "                   Default: \${DIR}"
	echo " -l <login-id>     login-id to clone from linaro-private git repositories"
	echo "                   If in doubt, please contact Linaro Android mailing list for details"
	echo "                   Default: \${LINARO_ANDROID_ACCESS_ID}"
	echo " -y                Assume answer 'YES' for all questions. Non-interactive mode. Requires -l"
	echo " -h                Will show this message."
	exit 1
}

while getopts   "${USAGE_OPTOVERLAY}d:l:hty" optn; do
	case    \$optn   in
		$USAGE_OPTHANDLER
		d   ) DIR=\$OPTARG;;
		l   ) LINARO_ANDROID_ACCESS_ID=\$OPTARG;;
		t   ) EXACT=0;;
		y   ) INTERACTIVE=0;;
		h   ) usage; exit 1;;
		\?  ) usage; exit 1;;
        esac
done

UBUNTU=\`cat /etc/issue.net | cut -d' ' -f2\`
HOST_ARCH=\`uname -m\`
if [ \${HOST_ARCH} == "x86_64" ] ; then
	PKGS='gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc vim-common python-parted python-yaml wget uuid-dev python-mako'
else
	echo "ERROR: Only 64bit Host(Build) machines are supported at the moment."
	exit 1
fi
if [[ \${UBUNTU} =~ "14.04" || \${UBUNTU} =~ "13." || \${UBUNTU} =~ "12.10" ]]; then
	#Install basic dev package missing in chrooted environments
	sudo apt-get install software-properties-common
	sudo dpkg --add-architecture i386
	PKGS+=' libstdc++6:i386 git-core'
	if [[ \${UBUNTU} =~ "14.04" ]]; then
		PKGS+=' u-boot-tools bc acpica-tools'
	elif [[ \${UBUNTU} =~ "13.10" ]]; then
		PKGS+=' u-boot-tools bc iasl'
	else
		PKGS+=' uboot-mkimage acpica-tools'
	fi
elif [[ \${UBUNTU} =~ "12.04" || \${UBUNTU} =~ "10.04" ]] ; then
	#Install basic dev package missing in chrooted environments
	sudo apt-get install python-software-properties
	if [[ \${UBUNTU} =~ "12.04" ]]; then
		PKGS+=' libstdc++6:i386 git-core'
	else
		PKGS+=' ia32-libs libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext'
	fi
else
	echo "ERROR: Only Ubuntu 10.04, 12.*, 13.* and 14.04 versions are supported."
	exit 1
fi

echo
echo "Setting up Ubuntu software repositories..."
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu \$(lsb_release -sc) main universe restricted multiverse"
sudo add-apt-repository ppa:linaro-maintainers/tools
sudo apt-get update
echo
echo "Install OpenJDK v1.7?"
echo "*** If you are building AOSP master based builds then you should install OpenJDK v1.7. ***"
echo "*** But if you are building Android 4.4.4 or earlier Android releases then OpenJDK v1.6 is OK to use. ***"
echo "Press "y" to install OpenJDK v1.7, OR"
echo "Press "n" to install OpenJDK v1.6, OR"
echo "Press any other key to continue with the existing JDK installation."
read JDK
if [ \${JDK} == y ] ; then
	PKGS+=' openjdk-7-jdk openjdk-7-jre'
elif [ \${JDK} == n ] ; then
	PKGS+=' openjdk-6-jdk openjdk-6-jre'
else
	echo "Continue with the existing JDK installation .."
fi
echo
echo "Installing missing dependencies if any..."
if [ \$INTERACTIVE -eq 1 ] ; then
	sudo apt-get install \${PKGS}
else
	sudo apt-get -y install \${PKGS}
fi
# Obsolete git version 1.7.04 in lucid official repositories
# repo need at least git v1.7.2
if [[ \${UBUNTU} =~ "10.04" ]]; then
	echo
	echo "repo tool complains of obsolete git version 1.7.04 in lucid official repositories"
	echo "Building git for lucid from precise sources .."
	wget http://archive.ubuntu.com/ubuntu/pool/main/g/git/git_1.7.9.5.orig.tar.gz
	tar xzf git_1.7.9.5.orig.tar.gz
	cd git-1.7.9.5/
	make prefix=/usr
	sudo make prefix=/usr install
fi

EOF
	if [ -n "$SOURCE_OVERLAY" ]; then
		cat <<EOF
if [ \$EXACT -eq 1 ]; then
	if [ "a\$MANIFEST" == "a" -o ! -f \$MANIFEST ]; then
		echo "ERROR: no pinned manifest provided. Please download from $PINNED_MANIFEST_URL. This must be done from a browser that accepts cookies."
		exit 1
	fi
fi
if [ \$SOURCE_OVERLAY_OPTIONAL -ne 1 ]; then
	if [ "a\$SOURCE_OVERLAY" == "a" -o ! -f \$SOURCE_OVERLAY ]; then
		echo "ERROR: no source overlay provided. Please download from http://snapshots.linaro.org/android/binaries/$SOURCE_OVERLAY. This must be done from a browser that accepts cookies."
		exit 1
	fi
fi
EOF
	fi
	cat <<EOF
if [ -d \${DIR} ] ; then
	if [ \$INTERACTIVE -eq 1 ] ; then
		echo "Directory \${DIR} exists. Are you sure you want to use this? (y/n) "
		read CONTINUE
		[ \${CONTINUE} == y ] || exit 1
	else
		echo "Using existing directory: \${DIR} . "
	fi
else
	mkdir \${DIR}
fi
cd \${DIR}

EOF
}

jenkins_configs_method()
{
	cat <<EOF
# check for linaro private manifests
PM=\`echo ${MANIFEST_REPO} | grep -i "linaro-private" | wc -l\`
if [ \${PM} -gt 0 -a \${INTERACTIVE} -eq 1 ] ; then
	if [ "\${LINARO_ANDROID_ACCESS_ID}" == "\${USER}" ] ; then
		echo "You must specify valid login/access-id to clone from linaro-private manifest repositories."
		echo "Press "y" to continue with login: \${USER}, OR"
		echo "Press "n" to enter new login details, OR"
		echo "Press "h" for help."
		read NEXT
		if [ \${NEXT} == n ] ; then
			echo "Enter login/access-id:"
			read LINARO_ANDROID_ACCESS_ID
		elif [ \${NEXT} == h ] ; then
			usage
		fi
	fi
fi
export MANIFEST_REPO=\`echo ${MANIFEST_REPO} | sed 's/\/\/.*-bot@/\/\/'"\${LINARO_ANDROID_ACCESS_ID}"'@/'\`
export LOCAL_MANIFEST=\`echo ${LOCAL_MANIFEST} | sed 's/\/\/.*-bot@/\/\/'"\${LINARO_ANDROID_ACCESS_ID}"'@/'\`
export MANIFEST_BRANCH=${MANIFEST_BRANCH}
export LOCAL_MANIFEST_BRANCH=${LOCAL_MANIFEST_BRANCH}
export MANIFEST_FILENAME=${MANIFEST_FILENAME}
export TARGET_PRODUCT=${TARGET_PRODUCT}
export PATCHSETS="${PATCHSETS}"
export LUNCH=${LUNCH}
EOF
	if [ -n "$TARGET_KERNEL_SOURCE" ] ; then
		cat <<EOF
export TARGET_KERNEL_SOURCE=${TARGET_KERNEL_SOURCE}
EOF
	fi
    cat <<EOF
export TARGET_SIMULATOR=false
export BUILD_TINY_ANDROID=${BUILD_TINY_ANDROID}
export CPUS=\`grep -c processor /proc/cpuinfo\`
export INCLUDE_PERF=${INCLUDE_PERF}
export TARGET_BUILD_VARIANT=${TARGET_BUILD_VARIANT}
export BUILD_FS_IMAGE=${BUILD_FS_IMAGE}
export DEBUG_NO_STRICT_ALIASING=${DEBUG_NO_STRICT_ALIASING}
export DEBUG_NO_STDCXX11=${DEBUG_NO_STDCXX11}
export TOOLCHAIN_TRIPLET=${TOOLCHAIN_TRIPLET}
export ANDROID_64=${ANDROID_64}
export WITH_HOST_DALVIK=${WITH_HOST_DALVIK}
export USE_LINARO_TOOLCHAIN=${USE_LINARO_TOOLCHAIN}
EOF
	if [ -n "$TOOLCHAIN_URL" ] ; then
		cat <<EOF
export TOOLCHAIN_URL=${TOOLCHAIN_URL}
export TARGET_TOOLS_PREFIX=android-toolchain-eabi/bin/arm-linux-androideabi-
EOF
	else
		cat <<EOF
export TARGET_TOOLS_PREFIX=${TARGET_TOOLS_PREFIX}

EOF
	fi
}

git_configs_method()
{
	cat <<EOF
export BUILD_CONFIG_REPO=${BUILD_CONFIG_REPO}
export BUILD_CONFIG_BRANCH=${BUILD_CONFIG_BRANCH}
export BUILD_CONFIG_FILENAME=${BUILD_CONFIG_FILENAME}

git clone "\$BUILD_CONFIG_REPO" configs_repo
git --git-dir=configs_repo/.git checkout "\$BUILD_CONFIG_BRANCH"
CONFIGURATION=\$(cat configs_repo/"\$BUILD_CONFIG_FILENAME")
set -a
eval \$CONFIGURATION

EOF
}

sync_commands()
{
	if [ -n "$SOURCE_OVERLAY" ]; then
		CP_CMD="cp \$MANIFEST .repo/manifest.xml"
	else
		CP_CMD="curl -k ${PINNED_MANIFEST_URL}/pinned-manifest.xml > .repo/manifest.xml"
	fi
	if [ "$REPO_GROUPS" != "all,-notdefault,-eclipse" ]; then
		REPO_GROUPS_OPTION="-g $REPO_GROUPS"
	else
		REPO_GROUPS_OPTION=""
	fi
	cat <<EOF
# download the repo tool for android
curl "https://android-git.linaro.org/gitweb?p=tools/repo.git;a=blob_plain;f=repo;hb=refs/heads/stable" > repo
chmod +x repo

# download the android code
./repo init -u \${MANIFEST_REPO} -b \${MANIFEST_BRANCH} -m \${MANIFEST_FILENAME} ${REPO_MIRROR} $REPO_GROUPS_OPTION
if [ \${EXACT} -eq 1 ] ; then
	rm .repo/manifest.xml
	$CP_CMD
fi
rm -rf .repo/local_manifests
if [[ -n \${LOCAL_MANIFEST} && ! -n \${MANIFEST} ]]; then
	cd .repo/
        git clone \${LOCAL_MANIFEST} -b \${LOCAL_MANIFEST_BRANCH} local_manifests
        cd -
fi

# check for linaro private git repositories
PRI=\`grep -i "linaro-private" .repo/manifest.xml | wc -l\`
if [ \${PRI} -gt 0 -a \${INTERACTIVE} -eq 1 ] ; then
	if [ "\${LINARO_ANDROID_ACCESS_ID}" == "\${USER}" ] ; then
		echo "You must specify valid login/access-id to clone from linaro-private git repositories."
		echo "Press "y" to continue with login: \${USER}, OR"
		echo "Press "n" to enter new login details, OR"
		echo "Press "h" for help."
		read NEXT
		if [ \${NEXT} == n ] ; then
			echo "Enter login/access-id:"
			read LINARO_ANDROID_ACCESS_ID
		elif [ \${NEXT} == h ] ; then
			usage
		fi
	fi
	sed -i 's/\/\/.*-bot@/\/\/'"\${LINARO_ANDROID_ACCESS_ID}"'@/' .repo/manifest.xml
	sed -i 's/\/\/.*-bot@/\/\/'"\${LINARO_ANDROID_ACCESS_ID}"'@/' .repo/local_manifests/*.xml
fi
./repo sync -f -j1

EOF

	if [ -n "$TOOLCHAIN_URL" ] ; then
		cat <<EOF
# download the toolchain to build with
curl -k \${TOOLCHAIN_URL} > toolchain.tar.bz2
tar -jxf toolchain.tar.bz2
rm toolchain.tar.bz2
EOF
	fi
	if [ -n "$PATCHSETS" ] ; then
		cat <<EOF
# download and apply the patches
for i in \$PATCHSETS; do
	sh ./android-patchsets/\$i
done
EOF
	fi

	if [ -n "$SOURCE_OVERLAY" ]; then
		cat <<EOF

if [ -n "\${SOURCE_OVERLAY}" ]; then
	# extract the vendor's source overlay
	tar -x -a -f "\${SOURCE_OVERLAY}" -C .
	source_overlay_name=\$(basename \${SOURCE_OVERLAY})
	[ -f ./\${source_overlay_name} ] || cp -uv "\${SOURCE_OVERLAY}" .
fi
EOF
	fi
	echo
}

build_commands()
{
	cat <<EOF
# build the code
source build/envsetup.sh
lunch \${LUNCH}
make -j\${CPUS} ${MAKE_TARGETS}
EOF
}

{
	header
	if [ -n "$BUILD_CONFIG_REPO" ]; then
		git_configs_method
	else
		jenkins_configs_method
	fi
	sync_commands
	build_commands
} > linaro_android_build_cmds.sh
chmod +x linaro_android_build_cmds.sh