Anthony King | efd1542 | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 1 | # slim functions that extend build/envsetup.sh |
| 2 | |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 3 | function slim_device_combos() |
| 4 | { |
| 5 | local T list_file variant device |
Anthony King | 92a74cc | 2015-05-04 16:23:37 +0100 | [diff] [blame] | 6 | |
Anthony King | efd1542 | 2015-05-01 00:00:37 +0100 | [diff] [blame] | 7 | T="$(gettop)" |
| 8 | list_file="${T}/vendor/slim/slim.devices" |
| 9 | variant="userdebug" |
| 10 | |
| 11 | if [[ $1 ]] |
| 12 | then |
| 13 | if [[ $2 ]] |
| 14 | then |
| 15 | list_file="$1" |
| 16 | variant="$2" |
| 17 | else |
| 18 | if [[ ${VARIANT_CHOICES[@]} =~ (^| )$1($| ) ]] |
| 19 | then |
| 20 | variant="$1" |
| 21 | else |
| 22 | list_file="$1" |
| 23 | fi |
| 24 | fi |
| 25 | fi |
| 26 | |
| 27 | if [[ ! -f "${list_file}" ]] |
| 28 | then |
| 29 | echo "unable to find device list: ${list_file}" |
| 30 | list_file="${T}/vendor/slim/slim.devices" |
| 31 | echo "defaulting device list file to: ${list_file}" |
| 32 | fi |
| 33 | |
| 34 | while IFS= read -r device |
| 35 | do |
| 36 | add_lunch_combo "slim_${device}-${variant}" |
| 37 | done < "${list_file}" |
| 38 | } |
| 39 | |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 40 | function slim_rename_function() |
| 41 | { |
Anthony King | 8765d66 | 2015-05-01 00:46:46 +0100 | [diff] [blame] | 42 | eval "original_slim_$(declare -f ${1})" |
| 43 | } |
| 44 | |
Anthony King | 9c060f2 | 2015-05-04 17:07:40 +0100 | [diff] [blame] | 45 | function _slim_build_hmm() #hidden |
| 46 | { |
| 47 | printf "%-8s %s" "${1}:" "${2}" |
| 48 | } |
| 49 | |
| 50 | function slim_append_hmm() |
| 51 | { |
| 52 | HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_slim_build_hmm "$1" "$2")") |
| 53 | } |
| 54 | |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 55 | function slim_add_hmm_entry() |
| 56 | { |
Anthony King | 58c3dfb | 2015-05-04 14:05:57 +0100 | [diff] [blame] | 57 | for c in ${!HMM_DESCRIPTIVE[*]} |
| 58 | do |
Anthony King | 9c060f2 | 2015-05-04 17:07:40 +0100 | [diff] [blame] | 59 | if [[ "${1}" == $(echo "${HMM_DESCRIPTIVE[$c]}" | cut -f1 -d":") ]] |
Anthony King | 58c3dfb | 2015-05-04 14:05:57 +0100 | [diff] [blame] | 60 | then |
Anthony King | 9c060f2 | 2015-05-04 17:07:40 +0100 | [diff] [blame] | 61 | HMM_DESCRIPTIVE[${c}]="$(_slim_build_hmm "$1" "$2")" |
Anthony King | 58c3dfb | 2015-05-04 14:05:57 +0100 | [diff] [blame] | 62 | return |
| 63 | fi |
| 64 | done |
Anthony King | 9c060f2 | 2015-05-04 17:07:40 +0100 | [diff] [blame] | 65 | slim_append_hmm "$1" "$2" |
Anthony King | 58c3dfb | 2015-05-04 14:05:57 +0100 | [diff] [blame] | 66 | } |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 67 | |
| 68 | function slimremote() |
| 69 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 70 | local proj pfx project |
| 71 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 72 | if ! git rev-parse &> /dev/null |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 73 | then |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 74 | echo "Not in a git directory. Please run this from an Android repository you wish to set up." |
| 75 | return |
| 76 | fi |
| 77 | git remote rm slim 2> /dev/null |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 78 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 79 | proj="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 80 | |
| 81 | if (echo "$proj" | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then |
| 82 | pfx="android_" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 83 | fi |
| 84 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 85 | project="${proj//\//_}" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 86 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 87 | git remote add slim "git@github.com:SlimRoms/$pfx$project" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 88 | echo "Remote 'slim' created" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | function cmremote() |
| 92 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 93 | local proj pfx project |
| 94 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 95 | if ! git rev-parse &> /dev/null |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 96 | then |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 97 | echo "Not in a git directory. Please run this from an Android repository you wish to set up." |
| 98 | return |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 99 | fi |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 100 | git remote rm cm 2> /dev/null |
| 101 | |
| 102 | proj="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 103 | pfx="android_" |
| 104 | project="${proj//\//_}" |
| 105 | git remote add cm "git@github.com:CyanogenMod/$pfx$project" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 106 | echo "Remote 'cm' created" |
| 107 | } |
| 108 | |
| 109 | function aospremote() |
| 110 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 111 | local pfx project |
| 112 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 113 | if ! git rev-parse &> /dev/null |
| 114 | then |
| 115 | echo "Not in a git directory. Please run this from an Android repository you wish to set up." |
| 116 | return |
| 117 | fi |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 118 | git remote rm aosp 2> /dev/null |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 119 | |
| 120 | project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 121 | if [[ "$project" != device* ]] |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 122 | then |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 123 | pfx="platform/" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 124 | fi |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 125 | git remote add aosp "https://android.googlesource.com/$pfx$project" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 126 | echo "Remote 'aosp' created" |
| 127 | } |
| 128 | |
| 129 | function cafremote() |
| 130 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 131 | local pfx project |
| 132 | |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 133 | if ! git rev-parse &> /dev/null |
| 134 | then |
| 135 | echo "Not in a git directory. Please run this from an Android repository you wish to set up." |
| 136 | fi |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 137 | git remote rm caf 2> /dev/null |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 138 | |
| 139 | project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 140 | if [[ "$project" != device* ]] |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 141 | then |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 142 | pfx="platform/" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 143 | fi |
Anthony King | 9854d3e | 2015-05-04 14:44:32 +0100 | [diff] [blame] | 144 | git remote add caf "git://codeaurora.org/$pfx$project" |
Anthony King | 1c9bca2 | 2015-05-04 14:18:18 +0100 | [diff] [blame] | 145 | echo "Remote 'caf' created" |
| 146 | } |
Anthony King | 35181fd | 2015-05-04 15:01:56 +0100 | [diff] [blame] | 147 | |
| 148 | function slim_push() |
| 149 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 150 | local branch ssh_name path_opt proj |
Anthony King | 35181fd | 2015-05-04 15:01:56 +0100 | [diff] [blame] | 151 | branch="lp5.1" |
| 152 | ssh_name="slim_review" |
| 153 | path_opt= |
| 154 | |
| 155 | if [[ "$1" ]] |
| 156 | then |
| 157 | proj="$ANDROID_BUILD_TOP/$(echo "$1" | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 158 | path_opt="--git-dir=$(printf "%q/.git" "${proj}")" |
| 159 | else |
| 160 | proj="$(pwd -P)" |
| 161 | fi |
| 162 | proj="$(echo "$proj" | sed "s#$ANDROID_BUILD_TOP/##g")" |
| 163 | proj="$(echo "$proj" | sed 's#/$##')" |
| 164 | proj="${proj//\//_}" |
| 165 | |
| 166 | if (echo "$proj" | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then |
| 167 | proj="android_$proj" |
| 168 | fi |
| 169 | |
| 170 | git $path_opt push "ssh://${ssh_name}/SlimRoms/$proj" "HEAD:refs/for/$branch" |
| 171 | } |
Anthony King | 40ca181 | 2015-05-04 16:47:22 +0100 | [diff] [blame] | 172 | |
| 173 | |
| 174 | slim_rename_function hmm |
| 175 | function hmm() #hidden |
| 176 | { |
Anthony King | 6a2768e | 2015-05-04 17:17:31 +0100 | [diff] [blame] | 177 | local i T |
Anthony King | 40ca181 | 2015-05-04 16:47:22 +0100 | [diff] [blame] | 178 | T="$(gettop)" |
| 179 | original_slim_hmm |
| 180 | echo |
| 181 | |
| 182 | echo "vendor/slim extended functions. The complete list is:" |
| 183 | for i in $(grep -P '^function .*$' "$T/vendor/slim/build/envsetup.sh" | grep -v "#hidden" | sed 's/function \([a-z_]*\).*/\1/' | sort | uniq); do |
| 184 | echo "$i" |
| 185 | done |column |
| 186 | } |
| 187 | |
Anthony King | 9c060f2 | 2015-05-04 17:07:40 +0100 | [diff] [blame] | 188 | slim_append_hmm "slimremote" "Add a git remote for matching SLIM repository" |
| 189 | slim_append_hmm "cmremote" "Add a git remote for matching CM repository" |
| 190 | slim_append_hmm "aospremote" "Add git remote for matching AOSP repository" |
| 191 | slim_append_hmm "cafremote" "Add git remote for matching CodeAurora repository." |