forked from ScrewdAOSP/vendor_screwd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·165 lines (141 loc) · 5.35 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
#!/bin/bash
# red = errors, cyan = warnings, green = confirmations, blue = informational
# plain for generic text, bold for titles, reset flag at each end of line
# plain blue should not be used for readability reasons - use plain cyan instead
CLR_RST=$(tput sgr0) ## reset flag
CLR_RED=$CLR_RST$(tput setaf 1) # red, plain
CLR_GRN=$CLR_RST$(tput setaf 2) # green, plain
CLR_BLU=$CLR_RST$(tput setaf 4) # blue, plain
CLR_CYA=$CLR_RST$(tput setaf 6) # cyan, plain
CLR_BLD=$(tput bold) ## bold flag
CLR_BLD_RED=$CLR_RST$CLR_BLD$(tput setaf 1) # red, bold
CLR_BLD_GRN=$CLR_RST$CLR_BLD$(tput setaf 2) # green, bold
CLR_BLD_BLU=$CLR_RST$CLR_BLD$(tput setaf 4) # blue, bold
CLR_BLD_CYA=$CLR_RST$CLR_BLD$(tput setaf 6) # cyan, bold
# Nuke scrollback
echo -e '\0033\0143'
clear
# Output usage help
function showHelpAndExit {
echo -e "${CLR_BLD_BLU}usage: $0 <device> [options]${CLR_RST}"
echo -e ""
echo -e "${CLR_BLD_BLU}options:${CLR_RST}"
echo -e "${CLR_BLD_BLU} -h, --help display this help message${CLR_RST}"
echo -e "${CLR_BLD_BLU} -c, --clean wipe the tree before building${CLR_RST}"
echo -e "${CLR_BLD_BLU} -u, --user build a user build for distribution${CLR_RST}"
echo -e "${CLR_BLD_BLU} -s, --sync sync before building${CLR_RST}"
exit 1
}
# Make sure we are running on 64-bit before carrying on with anything
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
if [ "$ARCH" != "64" ]; then
echo -e "${CLR_BLD_RED}error: unsupported arch (expected: 64, found: $ARCH)${CLR_RST}"
exit 1
fi
# Set up paths
cd $(dirname $0)
DIR_ROOT=$(pwd)
DIR_OUT=$(readlink $DIR_ROOT/out)
[ -z "$DIR_OUT" ] && DIR_OUT="$DIR_ROOT/out"
# Set fallback branch
export ROOMSERVICE_BRANCHES=n7x-caf
# Make sure everything looks sane so far
if [ ! -d "$DIR_ROOT/vendor/screwd" ]; then
echo -e "${CLR_BLD_RED}error: insane root directory ($DIR_ROOT)${CLR_RST}"
exit 1
fi
# Pick the default thread count (allow overrides from the environment)
if [ -z "$THREADS" ]; then
if [ "$(uname -s)" = 'Darwin' ]; then
export THREADS=$(sysctl -n machdep.cpu.core_count)
else
export THREADS=$(cat /proc/cpuinfo | grep '^processor' | wc -l)
fi
fi
# Grab the build version
VERSION_MAJOR=$(cat $DIR_ROOT/vendor/screwd/configs/version.mk | grep 'PRODUCT_VERSION_MAJOR = *' | sed 's/PRODUCT_VERSION_MAJOR = //g')
VERSION_MINOR=$(cat $DIR_ROOT/vendor/screwd/configs/version.mk | grep 'PRODUCT_VERSION_MINOR = *' | sed 's/PRODUCT_VERSION_MINOR = //g')
VERSION_MAINTENANCE=$(cat $DIR_ROOT/vendor/screwd/configs/version.mk | grep 'PRODUCT_VERSION_MAINTENANCE = *' | sed 's/PRODUCT_VERSION_MAINTENANCE = //g')
VERSION_TAG=$(cat $DIR_ROOT/vendor/screwd/configs/version.mk | grep 'SCREWD_BUILD_TYPE = *' | sed 's/SCREWD_BUILD_TYPE = //g')
if [ -n "$TAG" ]; then
VERSION=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_MAINTENANCE-$VERSION_TAG
else
VERSION=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_MAINTENANCE
fi
# Grab all the command-line parameters
export DEVICE=$1
shift
if [ -z "$DEVICE" ]; then
echo -e "${CLR_BLD_RED}error: no device specified${CLR_RST}"
showHelpAndExit
fi
case $DEVICE in
-h|--help|h|help)
showHelpAndExit
;;
esac
while [[ "$#" > 0 ]]; do
PARAM=$(echo ${1,,})
case $PARAM in
-h|--help|h|help)
showHelpAndExit
;;
-c|--clean|c|clean)
FLAG_CLEAN_BUILD=y
;;
-u|--user|u|user)
FLAG_USER_BUILD=y
;;
-s|--sync|s|sync)
FLAG_SYNC=y
;;
*)
echo -e "${CLR_CYA}warning: skipping unknown parameter: $1${CLR_RST}"
;;
esac
shift
done
# Prep for a clean build, if requested so
if [ "$FLAG_CLEAN_BUILD" = 'y' ]; then
echo -e "${CLR_BLD_BLU}Cleaning output files left from old builds${CLR_RST}"
echo -e ""
rm -rf ${DIR_ROOT}/out/target/product/$DEVICE
fi
# And sync up, if asked to
if [ "$FLAG_SYNC" = 'y' ]; then
echo -e "${CLR_BLD_BLU}Downloading the latest source files${CLR_RST}"
echo -e ""
repo sync -j"$THREADS" -c --no-clone-bundle
fi
# Check the starting time (of the real build process)
TIME_START=$(date +%s.%N)
# Friendly logging to tell the user everything is working fine is always nice
echo -e "${CLR_BLD_GRN}Building SCREWD $VERSION for $DEVICE${CLR_RST}"
echo -e "${CLR_GRN}Start time: $(date)${CLR_RST}"
echo -e ""
# Initializationizing!
echo -e "${CLR_BLD_BLU}Setting up the environment${CLR_RST}"
echo -e ""
. build/envsetup.sh
echo -e ""
# Lunch-time!
echo -e "${CLR_BLD_BLU}Lunching $DEVICE${CLR_RST} ${CLR_CYA}(Including dependencies sync)${CLR_RST}"
echo -e ""
if [ "$FLAG_USER_BUILD" = 'y' ]; then
lunch "screwd_$DEVICE-user"
else
lunch "screwd_$DEVICE-userdebug"
fi
echo -e ""
# Build away!
echo -e "${CLR_BLD_BLU}Starting compilation${CLR_RST}"
echo -e ""
mka bacon
echo -e ""
# Check the finishing time
TIME_END=$(date +%s.%N)
# Log those times at the end as a fun fact of the day
echo -e "${CLR_BLD_GRN}Total time elapsed:${CLR_RST} ${CLR_GRN}$(echo "($TIME_END - $TIME_START) / 60" | bc) minutes ($(echo "$TIME_END - $TIME_START" | bc) seconds)${CLR_RST}"
echo -e ""
#kill java if it's hanging on
pkill java