blob: bc1aed9dca47d6a623ef8244bd6e08a69593fdb0 [file] [log] [blame]
Anthony Kingefd15422015-05-01 00:00:37 +01001# slim functions that extend build/envsetup.sh
2
Anthony King6a2768e2015-05-04 17:17:31 +01003function slim_device_combos()
4{
5 local T list_file variant device
Anthony King92a74cc2015-05-04 16:23:37 +01006
Anthony Kingefd15422015-05-01 00:00:37 +01007 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 King6a2768e2015-05-04 17:17:31 +010040function slim_rename_function()
41{
Anthony King8765d662015-05-01 00:46:46 +010042 eval "original_slim_$(declare -f ${1})"
43}
44
Anthony King9c060f22015-05-04 17:07:40 +010045function _slim_build_hmm() #hidden
46{
47 printf "%-8s %s" "${1}:" "${2}"
48}
49
50function slim_append_hmm()
51{
52 HMM_DESCRIPTIVE=("${HMM_DESCRIPTIVE[@]}" "$(_slim_build_hmm "$1" "$2")")
53}
54
Anthony King6a2768e2015-05-04 17:17:31 +010055function slim_add_hmm_entry()
56{
Anthony King58c3dfb2015-05-04 14:05:57 +010057 for c in ${!HMM_DESCRIPTIVE[*]}
58 do
Anthony King9c060f22015-05-04 17:07:40 +010059 if [[ "${1}" == $(echo "${HMM_DESCRIPTIVE[$c]}" | cut -f1 -d":") ]]
Anthony King58c3dfb2015-05-04 14:05:57 +010060 then
Anthony King9c060f22015-05-04 17:07:40 +010061 HMM_DESCRIPTIVE[${c}]="$(_slim_build_hmm "$1" "$2")"
Anthony King58c3dfb2015-05-04 14:05:57 +010062 return
63 fi
64 done
Anthony King9c060f22015-05-04 17:07:40 +010065 slim_append_hmm "$1" "$2"
Anthony King58c3dfb2015-05-04 14:05:57 +010066}
Anthony King1c9bca22015-05-04 14:18:18 +010067
68function slimremote()
69{
Anthony King6a2768e2015-05-04 17:17:31 +010070 local proj pfx project
71
Anthony King9854d3e2015-05-04 14:44:32 +010072 if ! git rev-parse &> /dev/null
Anthony King1c9bca22015-05-04 14:18:18 +010073 then
Anthony King9854d3e2015-05-04 14:44:32 +010074 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 King1c9bca22015-05-04 14:18:18 +010078
Anthony King9854d3e2015-05-04 14:44:32 +010079 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 King1c9bca22015-05-04 14:18:18 +010083 fi
84
Anthony King9854d3e2015-05-04 14:44:32 +010085 project="${proj//\//_}"
Anthony King1c9bca22015-05-04 14:18:18 +010086
Anthony King9854d3e2015-05-04 14:44:32 +010087 git remote add slim "git@github.com:SlimRoms/$pfx$project"
Anthony King1c9bca22015-05-04 14:18:18 +010088 echo "Remote 'slim' created"
Anthony King1c9bca22015-05-04 14:18:18 +010089}
90
91function cmremote()
92{
Anthony King6a2768e2015-05-04 17:17:31 +010093 local proj pfx project
94
Anthony King9854d3e2015-05-04 14:44:32 +010095 if ! git rev-parse &> /dev/null
Anthony King1c9bca22015-05-04 14:18:18 +010096 then
Anthony King9854d3e2015-05-04 14:44:32 +010097 echo "Not in a git directory. Please run this from an Android repository you wish to set up."
98 return
Anthony King1c9bca22015-05-04 14:18:18 +010099 fi
Anthony King9854d3e2015-05-04 14:44:32 +0100100 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 King1c9bca22015-05-04 14:18:18 +0100106 echo "Remote 'cm' created"
107}
108
109function aospremote()
110{
Anthony King6a2768e2015-05-04 17:17:31 +0100111 local pfx project
112
Anthony King9854d3e2015-05-04 14:44:32 +0100113 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 King1c9bca22015-05-04 14:18:18 +0100118 git remote rm aosp 2> /dev/null
Anthony King9854d3e2015-05-04 14:44:32 +0100119
120 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
121 if [[ "$project" != device* ]]
Anthony King1c9bca22015-05-04 14:18:18 +0100122 then
Anthony King9854d3e2015-05-04 14:44:32 +0100123 pfx="platform/"
Anthony King1c9bca22015-05-04 14:18:18 +0100124 fi
Anthony King9854d3e2015-05-04 14:44:32 +0100125 git remote add aosp "https://android.googlesource.com/$pfx$project"
Anthony King1c9bca22015-05-04 14:18:18 +0100126 echo "Remote 'aosp' created"
127}
128
129function cafremote()
130{
Anthony King6a2768e2015-05-04 17:17:31 +0100131 local pfx project
132
Anthony King9854d3e2015-05-04 14:44:32 +0100133 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 King1c9bca22015-05-04 14:18:18 +0100137 git remote rm caf 2> /dev/null
Anthony King9854d3e2015-05-04 14:44:32 +0100138
139 project="$(pwd -P | sed "s#$ANDROID_BUILD_TOP/##g")"
140 if [[ "$project" != device* ]]
Anthony King1c9bca22015-05-04 14:18:18 +0100141 then
Anthony King9854d3e2015-05-04 14:44:32 +0100142 pfx="platform/"
Anthony King1c9bca22015-05-04 14:18:18 +0100143 fi
Anthony King9854d3e2015-05-04 14:44:32 +0100144 git remote add caf "git://codeaurora.org/$pfx$project"
Anthony King1c9bca22015-05-04 14:18:18 +0100145 echo "Remote 'caf' created"
146}
Anthony King35181fd2015-05-04 15:01:56 +0100147
148function slim_push()
149{
Anthony King6a2768e2015-05-04 17:17:31 +0100150 local branch ssh_name path_opt proj
Anthony King35181fd2015-05-04 15:01:56 +0100151 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 King40ca1812015-05-04 16:47:22 +0100172
173
174slim_rename_function hmm
175function hmm() #hidden
176{
Anthony King6a2768e2015-05-04 17:17:31 +0100177 local i T
Anthony King40ca1812015-05-04 16:47:22 +0100178 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 King9c060f22015-05-04 17:07:40 +0100188slim_append_hmm "slimremote" "Add a git remote for matching SLIM repository"
189slim_append_hmm "cmremote" "Add a git remote for matching CM repository"
190slim_append_hmm "aospremote" "Add git remote for matching AOSP repository"
191slim_append_hmm "cafremote" "Add git remote for matching CodeAurora repository."