blob: 7813329641ce71f5964b2d65c654b31e19258fa0 [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.
7- brunch: Sets up build environment using breakfast(),
8 and then comiles using mka() against bacon target.
9- mka: Builds using SCHED_BATCH on all processors.
xplodwilde1943f22013-08-29 20:18:18 +020010- pushboot: Push a file from your OUT dir to your phone and
11 reboots it, using absolute path.
xplodwild29ffed22013-08-24 17:40:37 +010012EOF
13}
Anthony King0ac8e1a2015-05-01 00:00:37 +010014
15function bliss_device_combos()
16{
17 local T list_file variant device
18
19 T="$(gettop)"
20 list_file="${T}/vendor/bliss/bliss.devices"
21 variant="userdebug"
22
23 if [[ $1 ]]
24 then
25 if [[ $2 ]]
26 then
27 list_file="$1"
28 variant="$2"
29 else
30 if [[ ${VARIANT_CHOICES[@]} =~ (^| )$1($| ) ]]
31 then
32 variant="$1"
33 else
34 list_file="$1"
35 fi
36 fi
37 fi
38
39 if [[ ! -f "${list_file}" ]]
40 then
41 echo "unable to find device list: ${list_file}"
42 list_file="${T}/vendor/bliss/bliss.devices"
43 echo "defaulting device list file to: ${list_file}"
44 fi
45
46 while IFS= read -r device
47 do
48 add_lunch_combo "bliss_${device}-${variant}"
49 done < "${list_file}"
50}
51
52function bliss_rename_function()
53{
54 eval "original_bliss_$(declare -f ${1})"
55}
56
57function _bliss_build_hmm() #hidden
58{
59 printf "%-8s %s" "${1}:" "${2}"
60}
61
62function bliss_append_hmm()
63{
64 HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_bliss_build_hmm "$1" "$2")")
65}
66
67function bliss_add_hmm_entry()
68{
69 for c in ${!HMM_DESCRIPTIVE[*]}
70 do
71 if [[ "${1}" == $(echo "${HMM_DESCRIPTIVE[$c]}" | cut -f1 -d":") ]]
72 then
73 HMM_DESCRIPTIVE[${c}]="$(_bliss_build_hmm "$1" "$2")"
74 return
75 fi
76 done
77 bliss_append_hmm "$1" "$2"
78}
79
80function blissremote()
81{
82 local proj pfx project
83
84 if ! git rev-parse &> /dev/null
85 then
86 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
87 return
88 fi
89 git remote rm bliss 2> /dev/null
90
91 proj="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
92
93 if (echo "$proj" | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then
Jackeagle432a3492018-05-22 01:15:28 -040094 pfx="platform_"
Anthony King0ac8e1a2015-05-01 00:00:37 +010095 fi
96
97 project="${proj//\//_}"
98
99 git remote add bliss "git@github.com:BlissRoms/$pfx$project"
100 echo "Remote 'bliss' created"
101}
102
103function losremote()
104{
105 local proj pfx project
106
107 if ! git rev-parse &> /dev/null
108 then
109 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
110 return
111 fi
112 git remote rm cm 2> /dev/null
113
114 proj="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
115 pfx="android_"
116 project="${proj//\//_}"
117 git remote add los "git@github.com:LineageOS/$pfx$project"
118 echo "Remote 'los' created"
119}
120
121function aospremote()
122{
123 local pfx project
124
125 if ! git rev-parse &> /dev/null
126 then
127 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
128 return
129 fi
130 git remote rm aosp 2> /dev/null
131
132 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
133 if [[ "$project" != device* ]]
134 then
135 pfx="platform/"
136 fi
137 git remote add aosp "https://android.googlesource.com/$pfx$project"
138 echo "Remote 'aosp' created"
139}
140
141function cafremote()
142{
143 local pfx project
144
145 if ! git rev-parse &> /dev/null
146 then
147 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
148 fi
149 git remote rm caf 2> /dev/null
150
151 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
152 if [[ "$project" != device* ]]
153 then
154 pfx="platform/"
155 fi
156 git remote add caf "git://codeaurora.org/$pfx$project"
157 echo "Remote 'caf' created"
158}
159
160function bliss_push()
161{
162 local branch ssh_name path_opt proj
Jackeagle432a3492018-05-22 01:15:28 -0400163 branch="o8.1"
Anthony King0ac8e1a2015-05-01 00:00:37 +0100164 ssh_name="bliss_review"
165 path_opt=
166
167 if [[ "$1" ]]
168 then
169 proj="$ANDROID_BUILD_TOP/$(echo "$1" | sed "s#$ANDROID_BUILD_TOP/##g")"
170 path_opt="--git-dir=$(printf "%q/.git" "${proj}")"
171 else
172 proj="$(pwd -P)"
173 fi
174 proj="$(echo "$proj" | sed "s#$ANDROID_BUILD_TOP/##g")"
175 proj="$(echo "$proj" | sed 's#/$##')"
176 proj="${proj//\//_}"
177
178 if (echo "$proj" | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then
Jackeagle432a3492018-05-22 01:15:28 -0400179 proj="platform_$proj"
Anthony King0ac8e1a2015-05-01 00:00:37 +0100180 fi
181
182 git $path_opt push "ssh://${ssh_name}/BlissRoms/$proj" "HEAD:refs/for/$branch"
183}
184
185
186bliss_rename_function hmm
187function hmm() #hidden
188{
189 local i T
190 T="$(gettop)"
191 original_bliss_hmm
192 echo
193
194 echo "vendor/bliss extended functions. The complete list is:"
195 for i in $(grep -P '^function .*$' "$T/vendor/bliss/build/envsetup.sh" | grep -v "#hidden" | sed 's/function \([a-z_]*\).*/\1/' | sort | uniq); do
196 echo "$i"
197 done |column
198}
199
Luca Stefanie87b0c02017-08-17 20:30:00 +0200200function mk_timer()
201{
202 local start_time=$(date +"%s")
203 $@
204 local ret=$?
205 local end_time=$(date +"%s")
206 local tdiff=$(($end_time-$start_time))
207 local hours=$(($tdiff / 3600 ))
208 local mins=$((($tdiff % 3600) / 60))
209 local secs=$(($tdiff % 60))
210 local ncolors=$(tput colors 2>/dev/null)
211 echo
212 if [ $ret -eq 0 ] ; then
213 echo -n "#### make completed successfully "
214 else
215 echo -n "#### make failed to build some targets "
216 fi
217 if [ $hours -gt 0 ] ; then
218 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
219 elif [ $mins -gt 0 ] ; then
220 printf "(%02g:%02g (mm:ss))" $mins $secs
221 elif [ $secs -gt 0 ] ; then
222 printf "(%s seconds)" $secs
223 fi
224 echo " ####"
225 echo
226 return $ret
227}
228
xplodwild29ffed22013-08-24 17:40:37 +0100229function brunch()
230{
231 breakfast $*
232 if [ $? -eq 0 ]; then
233 time mka bacon
234 else
235 echo "No such item in brunch menu. Try 'breakfast'"
236 return 1
237 fi
238 return $?
239}
Anthony King0ac8e1a2015-05-01 00:00:37 +0100240
xplodwild29ffed22013-08-24 17:40:37 +0100241function breakfast()
242{
243 target=$1
Archi4f440b02014-02-28 19:18:54 +0100244 local variant=$2
xplodwild29ffed22013-08-24 17:40:37 +0100245 BLISS_DEVICES_ONLY="true"
246 unset LUNCH_MENU_CHOICES
247 add_lunch_combo full-eng
248 for f in `/bin/ls device/*/*/vendorsetup.sh 2> /dev/null`
249 do
250 echo "including $f"
251 . $f
252 done
253 unset f
254
255 if [ $# -eq 0 ]; then
256 # No arguments, so let's have the full menu
257 lunch
258 else
259 echo "z$target" | grep -q "-"
260 if [ $? -eq 0 ]; then
261 # A buildtype was specified, assume a full device name
262 lunch $target
263 else
264 # This is probably just the bliss model name
Archi4f440b02014-02-28 19:18:54 +0100265 if [ -z "$variant" ]; then
266 variant="userdebug"
267 fi
268 lunch bliss_$target-$variant
xplodwild29ffed22013-08-24 17:40:37 +0100269 fi
270 fi
271 return $?
272}
273
274alias bib=breakfast
275
mikeNGbdc1fde2018-05-17 23:17:12 -0400276function repopick() {
277 T=$(gettop)
278 $T/vendor/bliss/build/tools/repopick.py $@
279}
280
Chirayu Desai352b4d82013-06-30 10:04:25 +0530281function fixup_common_out_dir() {
282 common_out_dir=$(get_build_var OUT_DIR)/target/common
283 target_device=$(get_build_var TARGET_DEVICE)
284 if [ ! -z $ANDROID_FIXUP_COMMON_OUT ]; then
285 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
286 mv ${common_out_dir} ${common_out_dir}-${target_device}
287 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
288 else
289 [ -L ${common_out_dir} ] && rm ${common_out_dir}
290 mkdir -p ${common_out_dir}-${target_device}
291 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
292 fi
293 else
294 [ -L ${common_out_dir} ] && rm ${common_out_dir}
295 mkdir -p ${common_out_dir}
296 fi
297}
298
xplodwild29ffed22013-08-24 17:40:37 +0100299# Make using all available CPUs
300function mka() {
Luca Stefani6cd5da92017-08-17 20:34:44 +0200301 m -j "$@"
xplodwild29ffed22013-08-24 17:40:37 +0100302}
xplodwilde1943f22013-08-29 20:18:18 +0200303
304function pushboot() {
305 if [ ! -f $OUT/$* ]; then
306 echo "File not found: $OUT/$*"
307 return 1
308 fi
309
310 adb root
311 sleep 1
312 adb wait-for-device
313 adb remount
314
315 adb push $OUT/$* /$*
316 adb reboot
317}
Steve Kondikb66cd022016-11-04 12:05:19 -0700318
319# Enable SD-LLVM if available
320if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then
Alexander Martinzc4fa54b2016-11-05 15:27:43 +0100321 case `uname -s` in
322 Darwin)
323 # Darwin is not supported yet
324 ;;
325 *)
326 export SDCLANG=true
nicknitewolfd27211f2017-09-28 18:38:55 +0800327 export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin
328 export SDCLANG_PATH_2=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin
Mandeep Singh Grangdd7cb1d2016-05-05 13:09:41 -0700329 export SDCLANG_LTO_DEFS=$(gettop)/vendor/lineage/build/core/sdllvm-lto-defs.mk
Alexander Martinzc4fa54b2016-11-05 15:27:43 +0100330 ;;
331 esac
Steve Kondikb66cd022016-11-04 12:05:19 -0700332fi