aboutsummaryrefslogtreecommitdiff
path: root/node/build
blob: c628de1ac13dffa7b40e737f8630c876e30073df (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
#!/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

mkdir -p build
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