Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 1 | # bliss functions that extend build/envsetup.sh |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 2 | function __print_bliss_functions_help() { |
| 3 | cat <<EOF |
| 4 | Additional BlissRoms functions: |
| 5 | - breakfast: Setup the build environment, but only list |
| 6 | devices we support. |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 7 | - mka: Builds using SCHED_BATCH on all processors. |
Jackeagle | 35340ca | 2019-08-01 02:50:02 -0400 | [diff] [blame] | 8 | - 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. |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 13 | EOF |
| 14 | } |
Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 15 | |
| 16 | function 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 | |
| 53 | function bliss_rename_function() |
| 54 | { |
| 55 | eval "original_bliss_$(declare -f ${1})" |
| 56 | } |
| 57 | |
| 58 | function _bliss_build_hmm() #hidden |
| 59 | { |
| 60 | printf "%-8s %s" "${1}:" "${2}" |
| 61 | } |
| 62 | |
| 63 | function bliss_append_hmm() |
| 64 | { |
| 65 | HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_bliss_build_hmm "$1" "$2")") |
| 66 | } |
| 67 | |
| 68 | function 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 King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 81 | function 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 | |
| 99 | function 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 | |
| 119 | function 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 | |
| 138 | function bliss_push() |
| 139 | { |
| 140 | local branch ssh_name path_opt proj |
Jackeagle | 432a349 | 2018-05-22 01:15:28 -0400 | [diff] [blame] | 141 | branch="o8.1" |
Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 142 | 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 |
Jackeagle | 432a349 | 2018-05-22 01:15:28 -0400 | [diff] [blame] | 157 | proj="platform_$proj" |
Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 158 | fi |
| 159 | |
| 160 | git $path_opt push "ssh://${ssh_name}/BlissRoms/$proj" "HEAD:refs/for/$branch" |
| 161 | } |
| 162 | |
| 163 | |
| 164 | bliss_rename_function hmm |
| 165 | function 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 Stefani | e87b0c0 | 2017-08-17 20:30:00 +0200 | [diff] [blame] | 178 | function 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 | |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 207 | function breakfast() |
| 208 | { |
| 209 | target=$1 |
Archi | 4f440b0 | 2014-02-28 19:18:54 +0100 | [diff] [blame] | 210 | local variant=$2 |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 211 | |
| 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 |
Archi | 4f440b0 | 2014-02-28 19:18:54 +0100 | [diff] [blame] | 222 | if [ -z "$variant" ]; then |
| 223 | variant="userdebug" |
| 224 | fi |
| 225 | lunch bliss_$target-$variant |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 226 | fi |
| 227 | fi |
| 228 | return $? |
| 229 | } |
| 230 | |
| 231 | alias bib=breakfast |
| 232 | |
Jackeagle | 35340ca | 2019-08-01 02:50:02 -0400 | [diff] [blame] | 233 | function 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 | |
mikeNG | bdc1fde | 2018-05-17 23:17:12 -0400 | [diff] [blame] | 245 | function repopick() { |
| 246 | T=$(gettop) |
| 247 | $T/vendor/bliss/build/tools/repopick.py $@ |
| 248 | } |
| 249 | |
Chirayu Desai | 352b4d8 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 250 | function fixup_common_out_dir() { |
| 251 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 252 | target_device=$(get_build_var TARGET_DEVICE) |
Sam Mortimer | 6043be1 | 2019-09-10 11:40:34 -0700 | [diff] [blame] | 253 | common_target_out=common-${target_device} |
| 254 | if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then |
Chirayu Desai | 352b4d8 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 255 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 256 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
Sam Mortimer | 6043be1 | 2019-09-10 11:40:34 -0700 | [diff] [blame] | 257 | ln -s ${common_target_out} ${common_out_dir} |
Chirayu Desai | 352b4d8 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 258 | else |
| 259 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 260 | mkdir -p ${common_out_dir}-${target_device} |
Sam Mortimer | 6043be1 | 2019-09-10 11:40:34 -0700 | [diff] [blame] | 261 | ln -s ${common_target_out} ${common_out_dir} |
Chirayu Desai | 352b4d8 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 262 | fi |
| 263 | else |
| 264 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 265 | mkdir -p ${common_out_dir} |
| 266 | fi |
| 267 | } |
| 268 | |
Aren Clegg | 8c29db7 | 2018-10-08 04:09:30 +0000 | [diff] [blame] | 269 | if [[ $(uname -s) = "Darwin" ]];then |
| 270 | jobs=$(sysctl -n hw.ncpu) |
| 271 | elif [[ $(uname -s) = "Linux" ]];then |
| 272 | jobs=$(nproc) |
| 273 | fi |
| 274 | |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 275 | # Make using all available CPUs |
| 276 | function mka() { |
Aren Clegg | 8c29db7 | 2018-10-08 04:09:30 +0000 | [diff] [blame] | 277 | m -j$jobs "$@" |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 278 | } |
xplodwild | e1943f2 | 2013-08-29 20:18:18 +0200 | [diff] [blame] | 279 | |
Steve Kondik | b66cd02 | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 280 | # Enable SD-LLVM if available |
| 281 | if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then |
Alexander Martinz | c4fa54b | 2016-11-05 15:27:43 +0100 | [diff] [blame] | 282 | case `uname -s` in |
| 283 | Darwin) |
| 284 | # Darwin is not supported yet |
| 285 | ;; |
| 286 | *) |
| 287 | export SDCLANG=true |
nicknitewolf | d27211f | 2017-09-28 18:38:55 +0800 | [diff] [blame] | 288 | export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin |
| 289 | export SDCLANG_PATH_2=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_4.0/prebuilt/linux-x86_64/bin |
Jackeagle | 35340ca | 2019-08-01 02:50:02 -0400 | [diff] [blame] | 290 | export SDCLANG_LTO_DEFS=$(gettop)/vendor/bliss/build/core/sdllvm-lto-defs.mk |
Alexander Martinz | c4fa54b | 2016-11-05 15:27:43 +0100 | [diff] [blame] | 291 | ;; |
| 292 | esac |
Steve Kondik | b66cd02 | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 293 | fi |