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

set -e

export LANG=C

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

mkdir -p ${HOME}/bin ${WORKSPACE}/build/out
curl https://storage.googleapis.com/git-repo-downloads/repo > ${HOME}/bin/repo
wget https://git.linaro.org/ci/publishing-api.git/blob_plain/HEAD:/linaro-cp.py -O ${HOME}/bin/linaro-cp.py
chmod a+x ${HOME}/bin/*
export PATH=${HOME}/bin:${PATH}

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

sudo add-apt-repository "deb http://cz.archive.ubuntu.com/ubuntu utopic main universe"
sudo apt-get update
sudo apt-get install -y -f gcc-4.6 bc

# 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}"

echo "SYNCING CODE"

REPO_START=$(date +%s.%N)
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

set +e

# Download the code
repo sync --force-sync -j${cpu_count} -c > $WORKSPACE/sync-logs.txt 2>&1

if [ $? -ne 0 ]; then
    echo "Error: *** Error repo sync failed"
    cat $WORKSPACE/sync-logs.txt
    exit -1
fi

repo manifest -r -o $WORKSPACE/pinned-manifest.xml

# 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
        git reset --hard
        echo "Error: *** Error patch merge failed"
        exit -1
    fi
    cd -
else
    echo "Build Triggered by timer or after merging the patch"
fi

REPO_END=$(date +%s.%N)
REPO_TIME=$(echo "$REPO_END - $REPO_START" | bc)

MAKE_JOBS=${cpu_count}

echo "BUILDING CODE"

#Clean previous build artifacts
rm -rf out/host/