-
Notifications
You must be signed in to change notification settings - Fork 49
/
build_rom.sh
executable file
·164 lines (141 loc) · 4.49 KB
/
build_rom.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
#!/bin/bash
# Colorize and add text parameters
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
blu=$(tput setaf 4) # blue
txtbld=$(tput bold) # bold
bldgrn=${txtbld}$(tput setaf 1) # bold red
bldgrn=${txtbld}$(tput setaf 2) # bold green
bldblu=${txtbld}$(tput setaf 4) # bold blue
txtrst=$(tput sgr0) # reset
DEVICE="$1"
USERDEBUG="$2"
#GSI="$3"
SYNC="$3"
CLEAN="$4"
SHUTDOWN="$5"
ROOT_PATH=$PWD
BUILD_PATH="$ROOT_PATH/out/target/product/$DEVICE"
# Start tracking time
echo -e ${bldblu}
echo -e "---------------------------------------"
echo -e "SCRIPT STARTING AT $(date +%D\ %r)"
echo -e "---------------------------------------"
echo -e ${txtrst}
START=$(date +%s)
# Sync with latest sources
if [ "$SYNC" == "sync" ]
then
echo -e "${bldblu}Syncing latest sources ${txtrst}"
repo sync
fi
# Setup environment
echo -e "${bldblu}Setting up build environment ${txtrst}"
. build/envsetup.sh
# Setup ccache
export USE_CCACHE=1
export CCACHE_DIR="/home/ezio/ANDROID/ccache"
/usr/bin/ccache -M 25G
# Set the device
#echo -e "Setting the device... ${txtrst}"
#if [ "$USERDEBUG" == "debug" ]
#then
#breakfast "$DEVICE-userdebug"
#else
#breakfast "$DEVICE-user"
#fi
# Clean out folder
if [ "$CLEAN" == "clean" ]
then
echo -e "${bldblu}Cleaning up the OUT folder with make clobber ${txtrst}"
make clean;
# we'll always call installclean from our vendor/extras/envsetup.sh now
#else
#echo -e "${bldblu}No make clobber so just make installclean ${txtrst}"
#make installclean;
fi
# Start compilation and save a log
#if [ "$GSI" == "gsi" ]
#then
#echo -e "${bldblu}Compiling a fastboot flashable system image for $DEVICE and saving a build log file ${txtrst}"
#mka systemimage 2>&1 | tee build.log;
#else
echo -e "${bldblu}Compiling the rom for $DEVICE and saving a build log file ${txtrst}"
#mka bacon 2>&1 | tee build.log;
#fi
if [ "$USERDEBUG" == "debug" ]
then
brunch "abc_$DEVICE-userdebug" 2>&1 | tee build.log;
else
brunch "abc_$DEVICE-user" 2>&1 | tee build.log;
fi
#if [ "$GSI" == "gsi" ]
#then
# If the above was successful
#if [ `ls $BUILD_PATH/system.img 2>/dev/null | wc -l` != "0" ]
#then
#BUILD_RESULT="Build successful"
#echo -e "${bldblu}Making a smaller img zip for faster uploads ${txtrst}"
# if [ `ls $ROOT_PATH/OLD_ABC_ROM_$DEVICE-*.zip 2>/dev/null | wc -l` != "0" ]
#then
# rm OLD_ABC_ROM_$DEVICE-*.zip
#fi
#if [ `ls $ROOT_PATH/ABC_ROM_$DEVICE-*.zip 2>/dev/null | wc -l` != "0" ]
#then
#for file in ABC_ROM_$DEVICE-*.zip
# do
# mv -f "${file}" "${file/ABC_ROM/OLD_ABC_ROM}"
#done
#fi
# zip ABC_ROM_$DEVICE-gsi_image-$(date +%Y%m%d) $BUILD_PATH/system.img
# rm $ROOT_PATH/system.img
#mv $BUILD_PATH/system.img $ROOT_PATH
#else
#BUILD_RESULT="Build failed"
# fi
#else
# If the above was successful
if [ `ls $BUILD_PATH/abc_*.zip 2>/dev/null | wc -l` != "0" ]
then
BUILD_RESULT="Build successful"
# Copy the device ROM.zip (EDIT 2019: for now we use the ota zip) to root (and before doing this, remove old device builds but not the last one of them, adding an OLD_tag to it)
echo -e "${bldblu}Copying ROM.zip to $ROOT_PATH ${txtrst}"
if [ `ls $ROOT_PATH/OLD_abc_$DEVICE-*.zip 2>/dev/null | wc -l` != "0" ]
then
rm OLD_abc_$DEVICE-*.zip
fi
if [ `ls $ROOT_PATH/abc_$DEVICE-*.zip 2>/dev/null | wc -l` != "0" ]
then
for file in abc_$DEVICE-*.zip
do
mv -f "${file}" "${file/abc/OLD_abc}"
done
fi
mv $BUILD_PATH/abc_$DEVICE-ota*.zip $ROOT_PATH
#rm $BUILD_PATH/$DEVICE-ota-eng.*.zip
rm $BUILD_PATH/abc_$DEVICE*.zip
# If the build failed
else
BUILD_RESULT="Build failed"
fi
#fi
# back to root dir
cd $ROOT_PATH
# Stop tracking time
END=$(date +%s)
echo -e ${bldblu}
echo -e "-------------------------------------"
echo -e "SCRIPT ENDING AT $(date +%D\ %r)"
echo -e ""
echo -e "${BUILD_RESULT}!"
echo -e "TIME: $(echo $((${END}-${START})) | awk '{print int($1/60)" MINUTES AND "int($1%60)" SECONDS"}')"
echo -e "-------------------------------------"
echo -e ${txtrst}
BUILDTIME="Build time: $(echo $((${END}-${START})) | awk '{print int($1/60)" minutes and "int($1%60)" seconds"}')"
#kill java if it's hanging on
#pkill java
# Shutdown the system if required by the user
if [ "$SHUTDOWN" == "off" ]
then
qdbus org.kde.ksmserver /KSMServer logout 0 2 2
fi