blob: 026140d76342072306cbd809bc3c2021cd48ecf5 [file] [log] [blame]
Anthony King0ac8e1a2015-05-01 00:00:37 +01001# bliss functions that extend build/envsetup.sh
xplodwild29ffed22013-08-24 17:40:37 +01002function __print_bliss_functions_help() {
3cat <<EOF
4Additional BlissRoms functions:
5- breakfast: Setup the build environment, but only list
6 devices we support.
xplodwild29ffed22013-08-24 17:40:37 +01007- mka: Builds using SCHED_BATCH on all processors.
Jackeagle35340ca2019-08-01 02:50:02 -04008- blissify: Sets up build environment using breakfast(),
9 and then compiles using mka() against blissify target.
10- aospremote: Add git remote for matching AOSP repository.
11- cafremote: Add git remote for matching CodeAurora repository.
12- losremote: Add git remote for matching LineageOS repository.
xplodwild29ffed22013-08-24 17:40:37 +010013EOF
14}
Anthony King0ac8e1a2015-05-01 00:00:37 +010015
16function bliss_device_combos()
17{
18 local T list_file variant device
19
20 T="$(gettop)"
21 list_file="${T}/vendor/bliss/bliss.devices"
22 variant="userdebug"
23
24 if [[ $1 ]]
25 then
26 if [[ $2 ]]
27 then
28 list_file="$1"
29 variant="$2"
30 else
31 if [[ ${VARIANT_CHOICES[@]} =~ (^| )$1($| ) ]]
32 then
33 variant="$1"
34 else
35 list_file="$1"
36 fi
37 fi
38 fi
39
40 if [[ ! -f "${list_file}" ]]
41 then
42 echo "unable to find device list: ${list_file}"
43 list_file="${T}/vendor/bliss/bliss.devices"
44 echo "defaulting device list file to: ${list_file}"
45 fi
46
47 while IFS= read -r device
48 do
49 add_lunch_combo "bliss_${device}-${variant}"
50 done < "${list_file}"
51}
52
53function bliss_rename_function()
54{
55 eval "original_bliss_$(declare -f ${1})"
56}
57
58function _bliss_build_hmm() #hidden
59{
60 printf "%-8s %s" "${1}:" "${2}"
61}
62
63function bliss_append_hmm()
64{
65 HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_bliss_build_hmm "$1" "$2")")
66}
67
68function bliss_add_hmm_entry()
69{
70 for c in ${!HMM_DESCRIPTIVE[*]}
71 do
72 if [[ "${1}" == $(echo "${HMM_DESCRIPTIVE[$c]}" | cut -f1 -d":") ]]
73 then
74 HMM_DESCRIPTIVE[${c}]="$(_bliss_build_hmm "$1" "$2")"
75 return
76 fi
77 done
78 bliss_append_hmm "$1" "$2"
79}
80
Anthony King0ac8e1a2015-05-01 00:00:37 +010081function losremote()
82{
83 local proj pfx project
84
85 if ! git rev-parse &> /dev/null
86 then
87 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
88 return
89 fi
90 git remote rm cm 2> /dev/null
91
92 proj="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
93 pfx="android_"
94 project="${proj//\//_}"
95 git remote add los "git@github.com:LineageOS/$pfx$project"
96 echo "Remote 'los' created"
97}
98
99function aospremote()
100{
101 local pfx project
102
103 if ! git rev-parse &> /dev/null
104 then
105 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
106 return
107 fi
108 git remote rm aosp 2> /dev/null
109
110 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
111 if [[ "$project" != device* ]]
112 then
113 pfx="platform/"
114 fi
115 git remote add aosp "https://android.googlesource.com/$pfx$project"
116 echo "Remote 'aosp' created"
117}
118
119function cafremote()
120{
121 local pfx project
122
123 if ! git rev-parse &> /dev/null
124 then
125 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
126 fi
127 git remote rm caf 2> /dev/null
128
129 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
130 if [[ "$project" != device* ]]
131 then
132 pfx="platform/"
133 fi
134 git remote add caf "git://codeaurora.org/$pfx$project"
135 echo "Remote 'caf' created"
136}
137
138function bliss_push()
139{
140 local branch ssh_name path_opt proj
Jackeagle432a3492018-05-22 01:15:28 -0400141 branch="o8.1"
Anthony King0ac8e1a2015-05-01 00:00:37 +0100142 ssh_name="bliss_review"
143 path_opt=
144
145 if [[ "$1" ]]
146 then
147 proj="$ANDROID_BUILD_TOP/$(echo "$1" | sed "s#$ANDROID_BUILD_TOP/##g")"
148 path_opt="--git-dir=$(printf "%q/.git" "${proj}")"
149 else
150 proj="$(pwd -P)"
151 fi
152 proj="$(echo "$proj" | sed "s#$ANDROID_BUILD_TOP/##g")"
153 proj="$(echo "$proj" | sed 's#/$##')"
154 proj="${proj//\//_}"
155
156 if (echo "$proj" | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then
Jackeagle432a3492018-05-22 01:15:28 -0400157 proj="platform_$proj"
Anthony King0ac8e1a2015-05-01 00:00:37 +0100158 fi
159
160 git $path_opt push "ssh://${ssh_name}/BlissRoms/$proj" "HEAD:refs/for/$branch"
161}
162
163
164bliss_rename_function hmm
165function hmm() #hidden
166{
167 local i T
168 T="$(gettop)"
169 original_bliss_hmm
170 echo
171
172 echo "vendor/bliss extended functions. The complete list is:"
173 for i in $(grep -P '^function .*$' "$T/vendor/bliss/build/envsetup.sh" | grep -v "#hidden" | sed 's/function \([a-z_]*\).*/\1/' | sort | uniq); do
174 echo "$i"
175 done |column
176}
177
Luca Stefanie87b0c02017-08-17 20:30:00 +0200178function mk_timer()
179{
180 local start_time=$(date +"%s")
181 $@
182 local ret=$?
183 local end_time=$(date +"%s")
184 local tdiff=$(($end_time-$start_time))
185 local hours=$(($tdiff / 3600 ))
186 local mins=$((($tdiff % 3600) / 60))
187 local secs=$(($tdiff % 60))
188 local ncolors=$(tput colors 2>/dev/null)
189 echo
190 if [ $ret -eq 0 ] ; then
191 echo -n "#### make completed successfully "
192 else
193 echo -n "#### make failed to build some targets "
194 fi
195 if [ $hours -gt 0 ] ; then
196 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
197 elif [ $mins -gt 0 ] ; then
198 printf "(%02g:%02g (mm:ss))" $mins $secs
199 elif [ $secs -gt 0 ] ; then
200 printf "(%s seconds)" $secs
201 fi
202 echo " ####"
203 echo
204 return $ret
205}
206
xplodwild29ffed22013-08-24 17:40:37 +0100207function breakfast()
208{
209 target=$1
Archi4f440b02014-02-28 19:18:54 +0100210 local variant=$2
xplodwild29ffed22013-08-24 17:40:37 +0100211
212 if [ $# -eq 0 ]; then
213 # No arguments, so let's have the full menu
214 lunch
215 else
216 echo "z$target" | grep -q "-"
217 if [ $? -eq 0 ]; then
218 # A buildtype was specified, assume a full device name
219 lunch $target
220 else
221 # This is probably just the bliss model name
Archi4f440b02014-02-28 19:18:54 +0100222 if [ -z "$variant" ]; then
223 variant="userdebug"
224 fi
225 lunch bliss_$target-$variant
xplodwild29ffed22013-08-24 17:40:37 +0100226 fi
227 fi
228 return $?
229}
230
231alias bib=breakfast
232
Jackeagle35340ca2019-08-01 02:50:02 -0400233function blissify()
234{
235 breakfast $*
236 if [ $? -eq 0 ]; then
237 time mka blissify
238 else
239 echo "No such item in brunch menu. Try 'breakfast'"
240 return 1
241 fi
242 return $?
243}
244
mikeNGbdc1fde2018-05-17 23:17:12 -0400245function repopick() {
246 T=$(gettop)
247 $T/vendor/bliss/build/tools/repopick.py $@
248}
249
Chirayu Desai352b4d82013-06-30 10:04:25 +0530250function fixup_common_out_dir() {
251 common_out_dir=$(get_build_var OUT_DIR)/target/common
252 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer6043be12019-09-10 11:40:34 -0700253 common_target_out=common-${target_device}
254 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Chirayu Desai352b4d82013-06-30 10:04:25 +0530255 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
256 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer6043be12019-09-10 11:40:34 -0700257 ln -s ${common_target_out} ${common_out_dir}
Chirayu Desai352b4d82013-06-30 10:04:25 +0530258 else
259 [ -L ${common_out_dir} ] && rm ${common_out_dir}
260 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer6043be12019-09-10 11:40:34 -0700261 ln -s ${common_target_out} ${common_out_dir}
Chirayu Desai352b4d82013-06-30 10:04:25 +0530262 fi
263 else
264 [ -L ${common_out_dir} ] && rm ${common_out_dir}
265 mkdir -p ${common_out_dir}
266 fi
267}
268
Aren Clegg8c29db72018-10-08 04:09:30 +0000269if [[ $(uname -s) = "Darwin" ]];then
270 jobs=$(sysctl -n hw.ncpu)
271 elif [[ $(uname -s) = "Linux" ]];then
272 jobs=$(nproc)
273fi
274
xplodwild29ffed22013-08-24 17:40:37 +0100275# Make using all available CPUs
276function mka() {
Aren Clegg8c29db72018-10-08 04:09:30 +0000277 m -j$jobs "$@"
xplodwild29ffed22013-08-24 17:40:37 +0100278}
xplodwilde1943f22013-08-29 20:18:18 +0200279