-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·205 lines (171 loc) · 5.86 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
#!/bin/bash
# Version 2.0.7, Adapted for XPerience.
# Some darwin additions
# Remove some java verification
# Make Changelog and Copy to rom system and some cleans
# We don't allow scrollback buffer
echo -e '\0033\0143'
clear
# Get current path
DIR="$(cd `dirname $0`; pwd)"
OUT="$(readlink $DIR/out)"
[ -z "${OUT}" ] && OUT="${DIR}/out"
# Prepare output customization commands
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
blu=$(tput setaf 4) # blue
cya=$(tput setaf 6) # cyan
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldblu=${txtbld}$(tput setaf 4) # blue
bldcya=${txtbld}$(tput setaf 6) # cyan
txtrst=$(tput sgr0) # Reset
#check for architecture
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
# Local defaults, can be overriden by environment
: ${PREFS_FROM_SOURCE:="false"}
if [ `uname -s` == "Darwin" ]; then
: ${THREADS:="$(sysctl -n machdep.cpu.core_count)"}
else
: ${THREADS:="$(cat /proc/cpuinfo | grep "^processor" | wc -l)"}
fi
# Import command line parameters
DEVICE="$1"
EXTRAS="$2"
if [ $ARCH = "64" ]; then
# Get build version
BUILDTYPE=$(cat $DIR/vendor/XPe/vendor.mk | grep 'XPE_BUILDTYPE := *' | sed 's/XPE_BUILDTYPE := //g')
MAJOR=$(cat $DIR/vendor/XPe/vendor.mk | grep 'PRODUCT_VERSION_MAJOR := *' | sed 's/PRODUCT_VERSION_MAJOR := //g')
MINOR=$(cat $DIR/vendor/XPe/vendor.mk | grep 'PRODUCT_VERSION_MINOR := *' | sed 's/PRODUCT_VERSION_MINOR := //g')
MAINTENANCE=$(cat $DIR/vendor/XPe/vendor.mk | grep 'PRODUCT_VERSION_MAINTENANCE := *' | sed 's/PRODUCT_VERSION_MAINTENANCE := //g')
TAG=$(cat $DIR/vendor/XPe/vendor.mk | grep 'ROM_VERSION_TAG := *' | sed 's/ROM_VERSION_TAG := //g')
WITH_XPERIASUPPORT=$(cat $DIR/vendor/XPe/vendor.mk | grep 'WITH_XPERIASUPPORT := *' | sed 's/WITH_XPERIASUPPORT := //g')
if [ -n "$TAG" ]; then
VERSION=$MAJOR.$MINOR-R$TAG.$BUILDTYPE
else
VERSION=$MAJOR.$MINOR.$BUILDTYPE
fi
# If there is no extra parameter, reduce parameters index by 1
if [ "$EXTRAS" == "true" ] || [ "$EXTRAS" == "false" ]; then
SYNC="$2"
UPLOAD="$3"
else
SYNC="$3"
UPLOAD="$4"
fi
# Get start time
res1=$(date +%s.%N)
echo -e "${cya}Building ${bldcya}XPerience $VERSION for $DEVICE ${txtrst}";
echo -e "${bldgrn}Start time: $(date) ${txtrst}"
# Decide what command to execute
case "$EXTRAS" in
threads)
echo -e "${bldblu}Please enter desired building/syncing threads number followed by [ENTER]${txtrst}"
read threads
THREADS=$threads
;;
clean|cclean)
echo -e "${bldblu}Cleaning intermediates and output files${txtrst}"
export CLEAN_BUILD="true"
[ -d "${DIR}/out" ] && rm -Rf ${DIR}/out/*
;;
esac
echo -e ""
export DEVICE=$DEVICE
#Generate Changelog
export CHANGELOG=true
# setup environment
echo -e "${bldblu}Setting up environment ${txtrst}"
export USE_CCACHE=1
export CCACHE_DIR=~/.ccache
# set ccache due to your disk space,set it at your own risk
if [ `uname -s` == "Darwin" ]; then
prebuilts/misc/darwin-x86/ccache/ccache -M 50G
else
prebuilts/misc/linux-x86/ccache/ccache -M 50G
fi
#If you want include XPERIA Support
if [ "${WITH_XPERIASUPPORT}" == "true" ]; then
echo -e " copying xperia support"
echo ${bldppl}"Making dir..."${txtrst}
mkdir -v -p $OUT/target/product/"$DEVICE"/system/etc/permissions/
mkdir -v -p $OUT/target/product/"$DEVICE"/system/framework/
./vendor/XPe/config/xperiasupport.sh
fi
#making changelog on niglty roms
if [ "${BUILDTYPE}" == "NIGHTLY" ]; then
echo -e " Making changelog and System directory"
mkdir -v -p $OUT/target/product/"$DEVICE"/system/etc/
./vendor/XPe/tools/changelog
mv Changelog.txt out/target/product/"$DEVICE"/system/etc/CHANGELOG-XPE.txt
fi
#making changelog on niglty roms
if [ "${BUILDTYPE}" == "WEEKLY" ]; then
echo -e " Making changelog and System directory"
mkdir -v -p $OUT/target/product/"$DEVICE"/system/etc/
./vendor/XPe/tools/changelog
mv Changelog.txt out/target/product/"$DEVICE"/system/etc/CHANGELOG-XPE.txt
fi
#making changelog on UNOFFICIAL roms
if [ "${BUILDTYPE}" == "UNOFFICIAL" ]; then
echo -e " Making changelog and System directory"
mkdir -v -p $OUT/target/product/"$DEVICE"/system/etc/
cp vendor/XPe/CHANGELOG.mkdn out/target/product/"$DEVICE"/system/etc/CHANGELOG-XPE.txt
fi
#making changelog on RELEASE roms
if [ "${BUILDTYPE}" == "RELEASE" ]; then
echo -e " Making changelog and System directory"
mkdir -v -p $OUT/target/product/"$DEVICE"/system/etc/
cp vendor/XPe/CHANGELOG.mkdn out/target/product/"$DEVICE"/system/etc/CHANGELOG-XPE.txt
fi
#Enable to remove build.prop
echo -e ""
fix_count=0
elif [ "$var" == "clean" ]
then
echo -e "${bldblu}Clearing previous build info ${txtrst}"
mka installclean
elif [ "$var" == "fix" ]
then
echo -e "skip for remove build.prop"
fix_count=1
fi
if [ "$fix_count" == "0" ]
then
echo -e "removing build.prop"
rm -f out/target/product/"$DEVICE"/system/build.prop
rm -Rf out/target/product/"$DEVICE"/obj/PACKAGING/
fi
# Fetch latest sources
if [ "$SYNC" == "true" ]; then
echo -e ""
echo -e "${bldblu}Fetching latest sources${txtrst}"
repo sync -j"$THREADS"
echo -e ""
fi
if [ -n "${INTERACTIVE}" ]; then
echo -e "${bldblu}Dropping to interactive shell${txtrst}"
echo -en "${bldblu}Remeber to lunch you device:"
if [ "${VENDOR}" == "XPe" ]; then
echo -e "[${bldgrn}lunch xpe_$DEVICE-userdebug${bldblu}]${txtrst}"
else
echo -e "[${bldgrn}lunch full_$DEVICE-userdebug${bldblu}]${txtrst}"
fi
bash --init-file build/envsetup.sh -i
else
# Setup environment
echo -e ""
echo -e "${bldblu}Setting up environment${txtrst}"
. build/envsetup.sh
echo -e ""
# lunch/brunch device
echo -e "${bldblu}Lunching device [$DEVICE] ${cya}(Includes dependencies sync)${txtrst}"
lunch "$DEVICE-userdebug";
breakfast "$DEVICE"
echo -e "${bldblu}Starting compilation${txtrst}"
mka bacon -j"$THREADS"
echo -e ""
# Get elapsed time
res2=$(date +%s.%N)
echo -e "${bldgrn}Total time elapsed: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds)${txtrst}"