summaryrefslogtreecommitdiff
path: root/build.sh
blob: ab18e373ec9c18f657fdb3e8d4a30f6bec2b3b9a (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
#!/bin/bash

#set -ex

export LANG=C

git config --global user.email "android-build-bot@fake-email.com"
git config --global user.name "android-build-bot"

export base_dir="${HOME}/srv/${JOB_NAME}"
export cpu_count=$(getconf _NPROCESSORS_ONLN)
export jcpu_count=$(expr ${cpu_count} '*' 2)

# Move to persistent drive
if [ ! -d "${base_dir}" ]; then
    mkdir -p ${base_dir}
    chmod 777 ${base_dir}
fi
cd ${base_dir}

if [ -z $BUILD_CONFIG_REPO ] && [ -z $BUILD_CONFIG_BRANCH ] && [ -z $BUILDCONFIG_FILENAME ]; then
    echo "ERROR: Please provide the config repository, branch and filename"
    exit 1
else
    rm -rf android-build-configs
    git clone $BUILD_CONFIG_REPO -b $BUILD_CONFIG_BRANCH
fi

source android-build-configs/$BUILD_CONFIG_FILENAME

export PATH=$PATH:$PWD/tests/

if [ -z $MANIFEST_URL ]; then
    MANIFEST_URL=https://android.googlesource.com/platform/manifest/
fi

if [ -z $MANIFEST_BRANCH ]; then
    MANIFEST_BRANCH=master
fi

if [ -z $LOCAL_MANIFEST_URL ]; then
    echo "WARNING: local manifest not specified"
    echo "build is using main manifest only"
else
    if [ -z $LOCAL_MANIFEST_BRANCH ]; then
        echo "WARNING: local manifest branch not specified, using master branch"
        LOCAL_MANIFEST_BRANCH=master
    fi
fi

if [ -n $REPO_SEED_DIR ]; then
   REFERENCE="--reference=$REPO_SEED_DIR"
fi

if [ -z $BOOT_TO_GUI_TEST ]; then
   BOOT_TO_GUI_TEST=0
fi

mkdir -p android
cd android/

# setup tmpfs since we have enough free memory
# The default is half of the memory (size=50%)
mkdir -p out/target/product
sudo mount -t tmpfs tmpfs out/target/product

MAKE_TARGETS="${MAKE_TARGETS-droidcore}"

repo init -u $MANIFEST_URL -b $MANIFEST_BRANCH  $REFERENCE

if [ -n $LOCAL_MANIFEST_URL ]; then
    cd .repo
    rm -rf local_manifests
    git clone $LOCAL_MANIFEST_URL -b $LOCAL_MANIFEST_BRANCH local_manifests
    cd -
fi

rm -rf art/ build/ external/vixl

# Download the code
repo sync -j${cpu_count} -c

# Configure ccache
USE_CCACHE=1
CCACHE_DIR="${base_dir}/.ccache"
CCACHE_SLOPPINESS=file_macro,include_file_mtime,time_macros
export USE_CCACHE CCACHE_DIR CCACHE_SLOPPINESS
ccache -M 50G

if [ -n "$PATCHSETS" ]; then
    for i in $PATCHSETS; do
        sh ./android-patchsets/$i
    done
fi

if [ -n "$GERRIT_PROJECT" ]  && [ $GERRIT_EVENT_TYPE == "patchset-created" ]; then
    cd `grep -rni $GERRIT_PROJECT\" .repo/local_manifests | grep -Po 'path="\K[^"]*'`
    if git pull ssh://git@$GERRIT_HOST/$GERRIT_PROJECT $GERRIT_REFSPEC | grep -q "Automatic merge failed" ; then
        # TODO Fix this
        # ssh -p $GERRIT_PORT ssh://linaro-big-little-switcher-bot@$GERRIT_HOST review -p $GERRIT_PROJECT -m '"Automatic Merge Failed"' --code-review -1 $GERRIT_CHANGE_ID,$GERRIT_PATCHSET_NUMBER
        git reset --hard
        echo "Error: *** Merge Failed"
        exit -1
    fi
    cd -
fi

##HACK: This patch helps improve ccache hit rate
wget https://github.com/CyanogenMod/android_build/commit/332c89697947a97af6fa69f4e99bdab205ea3b55.patch -O fix-ccache.patch
cd build/
git am ../fix-ccache.patch
cd -

MAKE_JOBS=${cpu_count}

#Clean previous build artifacts
rm -rf out/*

source build/envsetup.sh
lunch $LUNCH_TARGET
make -j${jcpu_count} $MAKE_TARGETS showcommands
ccache -s