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. |
| 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. |
xplodwild | e1943f2 | 2013-08-29 20:18:18 +0200 | [diff] [blame] | 10 | - pushboot: Push a file from your OUT dir to your phone and |
| 11 | reboots it, using absolute path. |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 12 | EOF |
| 13 | } |
Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 14 | |
| 15 | function 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 | |
| 52 | function bliss_rename_function() |
| 53 | { |
| 54 | eval "original_bliss_$(declare -f ${1})" |
| 55 | } |
| 56 | |
| 57 | function _bliss_build_hmm() #hidden |
| 58 | { |
| 59 | printf "%-8s %s" "${1}:" "${2}" |
| 60 | } |
| 61 | |
| 62 | function bliss_append_hmm() |
| 63 | { |
| 64 | HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_bliss_build_hmm "$1" "$2")") |
| 65 | } |
| 66 | |
| 67 | function 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 | |
| 80 | function 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 |
| 94 | pfx="android_" |
| 95 | fi |
| 96 | |
| 97 | project="${proj//\//_}" |
| 98 | |
| 99 | git remote add bliss "git@github.com:BlissRoms/$pfx$project" |
| 100 | echo "Remote 'bliss' created" |
| 101 | } |
| 102 | |
| 103 | function 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 | |
| 121 | function 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 | |
| 141 | function 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 | |
| 160 | function bliss_push() |
| 161 | { |
| 162 | local branch ssh_name path_opt proj |
| 163 | branch="lp5.1" |
| 164 | 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 |
| 179 | proj="android_$proj" |
| 180 | fi |
| 181 | |
| 182 | git $path_opt push "ssh://${ssh_name}/BlissRoms/$proj" "HEAD:refs/for/$branch" |
| 183 | } |
| 184 | |
| 185 | |
| 186 | bliss_rename_function hmm |
| 187 | function 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 | |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 200 | function brunch() |
| 201 | { |
| 202 | breakfast $* |
| 203 | if [ $? -eq 0 ]; then |
| 204 | time mka bacon |
| 205 | else |
| 206 | echo "No such item in brunch menu. Try 'breakfast'" |
| 207 | return 1 |
| 208 | fi |
| 209 | return $? |
| 210 | } |
Anthony King | 0ac8e1a | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 211 | |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 212 | function breakfast() |
| 213 | { |
| 214 | target=$1 |
Archi | 4f440b0 | 2014-02-28 19:18:54 +0100 | [diff] [blame] | 215 | local variant=$2 |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 216 | BLISS_DEVICES_ONLY="true" |
| 217 | unset LUNCH_MENU_CHOICES |
| 218 | add_lunch_combo full-eng |
| 219 | for f in `/bin/ls device/*/*/vendorsetup.sh 2> /dev/null` |
| 220 | do |
| 221 | echo "including $f" |
| 222 | . $f |
| 223 | done |
| 224 | unset f |
| 225 | |
| 226 | if [ $# -eq 0 ]; then |
| 227 | # No arguments, so let's have the full menu |
| 228 | lunch |
| 229 | else |
| 230 | echo "z$target" | grep -q "-" |
| 231 | if [ $? -eq 0 ]; then |
| 232 | # A buildtype was specified, assume a full device name |
| 233 | lunch $target |
| 234 | else |
| 235 | # This is probably just the bliss model name |
Archi | 4f440b0 | 2014-02-28 19:18:54 +0100 | [diff] [blame] | 236 | if [ -z "$variant" ]; then |
| 237 | variant="userdebug" |
| 238 | fi |
| 239 | lunch bliss_$target-$variant |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 240 | fi |
| 241 | fi |
| 242 | return $? |
| 243 | } |
| 244 | |
| 245 | alias bib=breakfast |
| 246 | |
Chirayu Desai | 352b4d8 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 247 | function fixup_common_out_dir() { |
| 248 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 249 | target_device=$(get_build_var TARGET_DEVICE) |
| 250 | if [ ! -z $ANDROID_FIXUP_COMMON_OUT ]; then |
| 251 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 252 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
| 253 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 254 | else |
| 255 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 256 | mkdir -p ${common_out_dir}-${target_device} |
| 257 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 258 | fi |
| 259 | else |
| 260 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 261 | mkdir -p ${common_out_dir} |
| 262 | fi |
| 263 | } |
| 264 | |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 265 | # Make using all available CPUs |
| 266 | function mka() { |
Luca Stefani | 6cd5da9 | 2017-08-17 20:34:44 +0200 | [diff] [blame] | 267 | m -j "$@" |
xplodwild | 29ffed2 | 2013-08-24 17:40:37 +0100 | [diff] [blame] | 268 | } |
xplodwild | e1943f2 | 2013-08-29 20:18:18 +0200 | [diff] [blame] | 269 | |
| 270 | function pushboot() { |
| 271 | if [ ! -f $OUT/$* ]; then |
| 272 | echo "File not found: $OUT/$*" |
| 273 | return 1 |
| 274 | fi |
| 275 | |
| 276 | adb root |
| 277 | sleep 1 |
| 278 | adb wait-for-device |
| 279 | adb remount |
| 280 | |
| 281 | adb push $OUT/$* /$* |
| 282 | adb reboot |
| 283 | } |