#!/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 to map which build config to trigger based on the change. function map_build_config() { case $GERRIT_PROJECT in "platform/manifest") echo "premerge-ci/armv8-android-juno-lsk";; "android/device/linaro/juno") echo "premerge-ci/armv8-android-juno-lsk";; "device/linaro/common") echo "premerge-ci/armv8-android-juno-lsk";; "device/linaro/juno32") echo "premerge-ci/armv8-android-juno32-lsk";; "device/linaro/vexpress") echo "premerge-ci/vexpress-lcr";; "device/linaro/fvp-armv8") echo "premerge-ci/armv8-android-fvp-lsk";; "android-patchsets") echo "premerge-ci/armv8-android-juno-lsk";; esac } # 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 --location ${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 if [ -n "$GERRIT_PROJECT" ] && [ $GERRIT_EVENT_TYPE == "patchset-created" ] ; then echo "Fetching build config indirectly from git for gerrit trigger" save_dir=$PWD rm -rf /tmp/buildconf.$$ mkdir -p /tmp/buildconf.$$ cd /tmp/buildconf.$$ git clone https://android.git.linaro.org/git/android-build-configs.git cd * git checkout master build_config=$(map_build_config) $BUILD_SCRIPT_ROOT/../node/prepare_build_config.py "$(cat $build_config)" 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