#!/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 # REPO_TOOL_URL="http://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 } update-repo-tool BUILD_SCRIPT_ROOT=$(readlink -f "$(dirname "${0}")/../build-scripts") mkdir -p /var/run/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 /var/run/build-tools/build-config cat /var/run/build-tools/build-config source /var/run/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 /var/run/build-tools/build-config fi ramdisk_size=$(get_ramdisk_size $2) if [ -z "$ramdisk_size" ]; then ramdisk_size=0 fi # 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}" set -a source /var/run/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