aboutsummaryrefslogtreecommitdiff
path: root/build-scripts/create-user-build-script
blob: d1e3c2c4fb76be607fd65e85106f92ea2a99fc62 (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
#!/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 " -u <mirror-manifest-url>    The manifest url to your AOSP mirror"
	echo "                   Default: ${MANIFEST_REPO}"
	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:u:hty" optn; do
	case    \${optn}   in
		${USAGE_OPTHANDLER}
		d   ) DIR=\${OPTARG};;
		u   ) MIRROR=\${OPTARG};;
		l   ) LINARO_ANDROID_ACCESS_ID=\${OPTARG};;
		t   ) EXACT=0;;
		y   ) INTERACTIVE=0;;
		h   ) usage; exit 1;;
		\?  ) usage; exit 1;;
	esac
done

UBUNTU=\$(lsb_release -sc)
HOST_ARCH=\$(uname -m)
if [ \${HOST_ARCH} != "x86_64" ]; then
	echo "ERROR: Only 64bit Host(Build) machines are supported at the moment."
	exit 1
fi

# Install basic dev package missing in chrooted environments
echo
echo "Setting up Ubuntu software repositories..."
sudo apt-get update
sudo apt-get install software-properties-common
PKGS='git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip vim-common python-parted python-yaml wget uuid-dev python-mako u-boot-tools bc acpica-tools python-wand python-crypto mtools'

if [[ \${UBUNTU} =~ "trusty"  || \${UBUNTU} =~ "utopic" || \${UBUNTU} =~ "vivid" || \${UBUNTU} =~ "wily" || \${UBUNTU} =~ "xenial" ]]; then
	echo
	echo "Installing missing dependencies if any..."

	if [[  \${UBUNTU} =~ "trusty" ]]; then
		PKGS+=' openjdk-7-jdk openjdk-7-jre'
	else
		if [[ \${UBUNTU} =~ "utopic" || \${UBUNTU} =~ "vivid" ]]; then
			sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
		fi
		sudo add-apt-repository ppa:openjdk-r/ppa
		sudo apt-get update
		PKGS+=' openjdk-7-jdk openjdk-7-jre'
	fi

	if [ \${INTERACTIVE} -eq 1 ]; then
		sudo apt-get install \${PKGS}
	else
		sudo apt-get -y install \${PKGS}
	fi
else
	echo "WARNING: Only Ubuntu 14.04 and above are supported. Press "y" to continue building AOSP without installing dependencies? "
	echo "Press any other key to continue with the existing JDK installation."
	read BUILD
	if [ "\${BUILD}" != y ]; then
		exit 1
	fi
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
}

export_config_env_var(){
	local CONFIG_VAR_NAME="${1}"
	if [ -z "${CONFIG_VAR_NAME}" ]; then
		return
	fi

	local CONFIG_VAR_VALUE=$(eval echo \${${CONFIG_VAR_NAME}})
	if [ -n "${CONFIG_VAR_VALUE}" ]; then
		cat <<EOF
export ${CONFIG_VAR_NAME}="${CONFIG_VAR_VALUE}"
EOF
	fi

}

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

    cat <<EOF
export TARGET_SIMULATOR=false
export BUILD_TINY_ANDROID=${BUILD_TINY_ANDROID}
export CPUS=\$(getconf _NPROCESSORS_ONLN)
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}
EOF

	export_config_env_var "TARGET_GCC_VERSION_EXP"
	export_config_env_var "MALLOC_IMPL"
	export_config_env_var "TARGET_KERNEL_SOURCE"
	export_config_env_var "TARGET_BUILD_KERNEL"
	export_config_env_var "TARGET_BOOTIMAGE_USE_FAT"

}

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 -a \${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
if [ -n "\${MIRROR}" ]; then
	MANIFEST_REPO="\${MIRROR}"
fi
./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
	if [[ -n \${LOCAL_MANIFEST} && ! -n \${MANIFEST} ]]; then
		sed -i 's/\/\/.*-bot@/\/\/'"\${LINARO_ANDROID_ACCESS_ID}"'@/' .repo/local_manifests/*.xml
	fi
fi
./repo sync -f -j1

EOF

	if [ -n "${TOOLCHAIN_URL}" ]; then
		cat <<EOF
# Download the toolchain
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} showcommands) 2>&1 |tee build-${TARGET_PRODUCT}.log
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