forked from CarbonDev/hudson
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·221 lines (188 loc) · 4.79 KB
/
build.sh
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
function check_result {
if [ "0" -ne "$?" ]
then
(repo forall -c "git reset --hard") >/dev/null
echo $1
exit 1
fi
}
# Jenkins logs in with "bash -c ..." which does not read any profile or rc
# files (that is, it's not a login or interactive shell). Source the system
# profile here to pull in system settings such as ccache variables, etc.
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
if [ -z "$HOME" ]
then
echo HOME not in environment, guessing...
export HOME=$(awk -F: -v v="$USER" '{if ($1==v) print $6}' /etc/passwd)
fi
if [ -z "$WORKSPACE" ]
then
echo WORKSPACE not specified
exit 1
fi
if [ -z "$REPO_BRANCH" ]
then
echo REPO_BRANCH not specified
exit 1
fi
if [ -z "$LUNCH" ]
then
echo LUNCH not specified
exit 1
fi
export PATH=~/bin:$PATH
if [ -f ~/.profile ]
then
. ~/.profile
fi
export PYTHONDONTWRITEBYTECODE=1
cd $WORKSPACE
rm -rf archive
mkdir -p archive
export BUILD_NO=$BUILD_NUMBER
unset BUILD_NUMBER
export USE_CCACHE=1
export BUILD_WITH_COLORS=0
project_device=$(echo $LUNCH | cut -d'-' -f1)
device=$(echo $project_device | cut -b 4-)
# Setup ccache
CCACHE_BIN=$(which ccache)
if [ -z "$CCACHE_BIN" ]
then
CCACHE_BIN="prebuilts/misc/linux-x86/ccache/ccache"
fi
if [ -z "$CCACHE_DIR" ]
then
export CCACHE_DIR="$HOME/.ccache-$device"
if [ ! -d "$CCACHE_DIR" -a -x "$CCACHE_BIN" ]
then
mkdir -p "$CCACHE_DIR"
$CCACHE_BIN -M 20G
fi
fi
REPO=$(which repo)
if [ -z "$REPO" ]
then
mkdir -p ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
fi
git config --global user.name $(whoami)@$NODE_NAME
git config --global user.email jenkins@gummyrom.com
if [ ! -d $REPO_BRANCH ]
then
mkdir $REPO_BRANCH
if [ ! -z "$BOOTSTRAP" -a -d "$BOOTSTRAP" ]
then
echo Bootstrapping repo with: $BOOTSTRAP
cp -R $BOOTSTRAP/.repo $REPO_BRANCH
fi
cd $REPO_BRANCH
repo init -u https://github.com/TEAM-Gummy/platform_manifest.git -b $REPO_BRANCH
else
cd $REPO_BRANCH
# temp hack for turl
repo init -u https://github.com/TEAM-Gummy/platform_manifest.git -b $REPO_BRANCH
fi
## TEMPORARY: Some kernels are building _into_ the source tree and messing
## up posterior syncs due to changes
rm -rf kernel/*
echo Syncing...
repo sync -j16 -d -c -f > /dev/null
check_result "repo sync failed."
echo Sync complete.
if [ -f $WORKSPACE/hudson/$REPO_BRANCH-setup.sh ]
then
$WORKSPACE/hudson/$REPO_BRANCH-setup.sh
fi
. build/envsetup.sh
lunch $LUNCH
check_result "lunch failed."
rm -f $WORKSPACE/$REPO_BRANCH/out/target/product/$device/Gummy-*.zip*
UNAME=$(uname)
if [ "$BUILD_TYPE" = "NIGHTLY" ]
then
export TG_NIGHTLY=true
elif [ "$BUILD_TYPE" = "EXPERIMENTAL" ]
then
export TG_EXPERIMENTAL=true
elif [ "$BUILD_TYPE" = "RELEASE" ]
then
export TG_RELEASE=true
fi
# Generate git logs for all platform repos
rm -f $WORKSPACE/changecount
WORKSPACE=$WORKSPACE LUNCH=$LUNCH bash $WORKSPACE/hudson/changes/buildlog.sh 2>&1
# Abort build if it's exactly the same as the previous one
if [ -f $WORKSPACE/changecount ]
then
CHANGE_COUNT=$(cat $WORKSPACE/changecount)
rm -f $WORKSPACE/changecount
if [ $CHANGE_COUNT -eq "0" ]
then
echo "Zero changes since last build, aborting"
exit 1
fi
fi
LAST_CLEAN=0
if [ -f .clean ]
then
LAST_CLEAN=$(date -r .clean +%s)
fi
TIME_SINCE_LAST_CLEAN=$(expr $(date +%s) - $LAST_CLEAN)
# convert this to hours
TIME_SINCE_LAST_CLEAN=$(expr $TIME_SINCE_LAST_CLEAN / 60 / 60)
if [ $TIME_SINCE_LAST_CLEAN -gt "72" ]
then
echo "Cleaning!"
touch .clean
make clobber
else
echo "Skipping clean: $TIME_SINCE_LAST_CLEAN hours since last clean."
fi
if [ -z "$CLEAN_TYPE" ]
then
echo CLEAN_TYPE not specified, assuming already clean
else
mka $CLEAN_TYPE
fi
$CCACHE_BIN -s
time mka gummy 2>&1 TG_BUILDTYPE=$BUILD_TYPE
RECOVERY=$WORKSPACE/$REPO_BRANCH/out/target/product/$device/recovery.img
RECOVERY_VARIANT=$WORKSPACE/$REPO_BRANCH/out/target/product/$device/recovery/root/sbin/teamwin
if [ -f "$RECOVERY_VARIANT" ]
then
RECOVERYNAME=Gummy-TWRP-2.7.1.0-$device.img
else
RECOVERYNAME=Gummy-CWM-based-touch-recovery-$device.img
fi
MODVERSION=$(cat $WORKSPACE/$REPO_BRANCH/out/target/product/$device/system/build.prop | grep ro.tg.version | cut -d = -f 2)
if [ -f $WORKSPACE/$REPO_BRANCH/out/target/product/$device/Gummy-$MODVERSION.zip ]
then
for f in $(ls $WORKSPACE/$REPO_BRANCH/out/target/product/$device/Gummy-$MODVERSION.zip*)
do
cp $f $WORKSPACE2/archive/$(basename $f)
done
cp $WORKSPACE2/archive/CHANGES.txt $WORKSPACE2/archive/Gummy-$MODVERSION.txt
else
echo Build failed!!
exit 1
fi
if [ -f "$RECOVERY" ]
then
cp $RECOVERY $WORKSPACE2/archive/$RECOVERYNAME
else
echo Recovery build failed!!
exit 1
fi
check_result "Build failed."
rm -rf out/target/product/$device
$CCACHE_BIN -s