blob: 058c68fd5c4a455e5ac6d3e2a486248642d16e78 [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 BLISS_DEVICES_ONLY="true"
212 unset LUNCH_MENU_CHOICES
213 add_lunch_combo full-eng
214 for f in `/bin/ls device/*/*/vendorsetup.sh 2> /dev/null`
215 do
216 echo "including $f"
217 . $f
218 done
219 unset f
220
221 if [ $# -eq 0 ]; then
222 # No arguments, so let's have the full menu
223 lunch
224 else
225 echo "z$target" | grep -q "-"
226 if [ $? -eq 0 ]; then
227 # A buildtype was specified, assume a full device name
228 lunch $target
229 else
230 # This is probably just the bliss model name
Archi4f440b02014-02-28 19:18:54 +0100231 if [ -z "$variant" ]; then
232 variant="userdebug"
233 fi
234 lunch bliss_$target-$variant
xplodwild29ffed22013-08-24 17:40:37 +0100235 fi
236 fi
237 return $?
238}
239
240alias bib=breakfast
241
Jackeagle35340ca2019-08-01 02:50:02 -0400242function blissify()
243{
244 breakfast $*
245 if [ $? -eq 0 ]; then
246 time mka blissify
247 else
248 echo "No such item in brunch menu. Try 'breakfast'"
249 return 1
250 fi
251 return $?
252}
253
mikeNGbdc1fde2018-05-17 23:17:12 -0400254function repopick() {
255 T=$(gettop)
256 $T/vendor/bliss/build/tools/repopick.py $@
257}
258
Chirayu Desai352b4d82013-06-30 10:04:25 +0530259function fixup_common_out_dir() {
260 common_out_dir=$(get_build_var OUT_DIR)/target/common
261 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer6043be12019-09-10 11:40:34 -0700262 common_target_out=common-${target_device}
263 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Chirayu Desai352b4d82013-06-30 10:04:25 +0530264 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
265 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer6043be12019-09-10 11:40:34 -0700266 ln -s ${common_target_out} ${common_out_dir}
Chirayu Desai352b4d82013-06-30 10:04:25 +0530267 else
268 [ -L ${common_out_dir} ] && rm ${common_out_dir}
269 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer6043be12019-09-10 11:40:34 -0700270 ln -s ${common_target_out} ${common_out_dir}
Chirayu Desai352b4d82013-06-30 10:04:25 +0530271 fi
272 else
273 [ -L ${common_out_dir} ] && rm ${common_out_dir}
274 mkdir -p ${common_out_dir}
275 fi
276}
277
Aren Clegg8c29db72018-10-08 04:09:30 +0000278if [[ $(uname -s) = "Darwin" ]];then
279 jobs=$(sysctl -n hw.ncpu)
280 elif [[ $(uname -s) = "Linux" ]];then
281 jobs=$(nproc)
282fi
283
xplodwild29ffed22013-08-24 17:40:37 +0100284# Make using all available CPUs
285function mka() {
Aren Clegg8c29db72018-10-08 04:09:30 +0000286 m -j$jobs "$@"
xplodwild29ffed22013-08-24 17:40:37 +0100287}
xplodwilde1943f22013-08-29 20:18:18 +0200288
Steve Kondikb66cd022016-11-04 12:05:19 -0700289# Enable SD-LLVM if available
290if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then
Alexander Martinzc4fa54b2016-11-05 15:27:43 +0100291 case `uname -s` in
292 Darwin)
293 # Darwin is not supported yet
294 ;;
295 *)
296 export SDCLANG=true
nicknitewolfd27211f2017-09-28 18:38:55 +0800297 export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin
298 export SDCLANG_PATH_2=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin
Jackeagle35340ca2019-08-01 02:50:02 -0400299 export SDCLANG_LTO_DEFS=$(gettop)/vendor/bliss/build/core/sdllvm-lto-defs.mk
Alexander Martinzc4fa54b2016-11-05 15:27:43 +0100300 ;;
301 esac
Steve Kondikb66cd022016-11-04 12:05:19 -0700302fi