OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This script moves ebuilds between 'stable' and 'live' states. | 7 # This script moves ebuilds between 'stable' and 'live' states. |
8 # By default 'stable' ebuilds point at and build from source at the | 8 # By default 'stable' ebuilds point at and build from source at the |
9 # last known good commit. Moving an ebuild to 'live' (via cros_workon start) | 9 # last known good commit. Moving an ebuild to 'live' (via cros_workon start) |
10 # is intended to support development. The current source tip is fetched, | 10 # is intended to support development. The current source tip is fetched, |
11 # source modified and built using the unstable 'live' (9999) ebuild. | 11 # source modified and built using the unstable 'live' (9999) ebuild. |
12 | 12 |
13 # Load common constants. This should be the first executable line. | 13 # --- BEGIN COMMON.SH BOILERPLATE --- |
14 # The path to common.sh should be relative to your script's location. | 14 # Load common CrOS utilities. Inside the chroot this file is installed in |
15 . "$(dirname "$0")/common.sh" | 15 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 16 # location. |
| 17 find_common_sh() { |
| 18 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 19 local path |
| 20 |
| 21 SCRIPT_ROOT= |
| 22 for path in "${common_paths[@]}"; do |
| 23 if [ -r "${path}/common.sh" ]; then |
| 24 SCRIPT_ROOT=${path} |
| 25 break |
| 26 fi |
| 27 done |
| 28 } |
| 29 |
| 30 find_common_sh |
| 31 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 32 # --- END COMMON.SH BOILERPLATE --- |
16 | 33 |
17 # Script must be run inside the chroot | 34 # Script must be run inside the chroot |
18 restart_in_chroot_if_needed $* | 35 restart_in_chroot_if_needed "$@" |
19 get_default_board | 36 get_default_board |
20 | 37 |
21 DEFINE_string board "${DEFAULT_BOARD}" \ | 38 DEFINE_string board "${DEFAULT_BOARD}" \ |
22 "The board to set package keywords for." | 39 "The board to set package keywords for." |
23 DEFINE_boolean host "${FLAGS_FALSE}" \ | 40 DEFINE_boolean host "${FLAGS_FALSE}" \ |
24 "Uses the host instead of board" | 41 "Uses the host instead of board" |
25 DEFINE_string command "git status" \ | 42 DEFINE_string command "git status" \ |
26 "The command to be run by forall." | 43 "The command to be run by forall." |
27 DEFINE_boolean all "${FLAGS_FALSE}" \ | 44 DEFINE_boolean all "${FLAGS_FALSE}" \ |
28 "Apply to all possible packages for the given command" | 45 "Apply to all possible packages for the given command" |
29 | 46 |
30 FLAGS_HELP="usage: $0 <command> [flags] [<list of packages>|--all] | 47 FLAGS_HELP="usage: $0 <command> [flags] [<list of packages>|--all] |
31 commands: | 48 commands: |
32 start: Moves an ebuild to live (intended to support development) | 49 start: Moves an ebuild to live (intended to support development) |
33 stop: Moves an ebuild to stable (use last known good) | 50 stop: Moves an ebuild to stable (use last known good) |
34 list: List of live ebuilds (workon ebuilds if --all) | 51 list: List of live ebuilds (workon ebuilds if --all) |
35 list-all: List all of the live ebuilds for all setup boards | 52 list-all: List all of the live ebuilds for all setup boards |
36 iterate: For each ebuild, cd to the source dir and run a commond" | 53 iterate: For each ebuild, cd to the source dir and run a commond" |
37 FLAGS "$@" || exit 1 | 54 FLAGS "$@" || exit 1 |
38 eval set -- "${FLAGS_ARGV}" | 55 eval set -- "${FLAGS_ARGV}" |
39 | 56 |
40 | 57 |
41 # eat the workon command keywords: start, stop or list. | 58 # eat the workon command keywords: start, stop or list. |
42 WORKON_CMD=$1 | 59 WORKON_CMD=$1 |
43 shift | 60 shift |
44 | 61 |
45 | |
46 # Board dir config | 62 # Board dir config |
47 | 63 |
48 # If both are specified, just use host, because board does not | 64 # If both are specified, just use host, because board does not |
49 # have to be specified and may come from default, in which case | 65 # have to be specified and may come from default, in which case |
50 # there's no way to override. | 66 # there's no way to override. |
51 [ -n "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_TRUE} ] && \ | 67 [ -n "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_TRUE} ] && \ |
52 FLAGS_board="" # kill board | 68 FLAGS_board="" # kill board |
53 [ -z "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_FALSE} ] && \ | 69 [ -z "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_FALSE} ] && \ |
54 [ "${WORKON_CMD}" != "list-all" ] && \ | 70 [ "${WORKON_CMD}" != "list-all" ] && \ |
55 die "You must specify either --host or --board=" | 71 die "You must specify either --host or --board=" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 sudo ln -s "${WORKON_FILE}" "${KEYWORDS_FILE}" || \ | 107 sudo ln -s "${WORKON_FILE}" "${KEYWORDS_FILE}" || \ |
92 die "ln -s ${WORKON_FILE} ${KEYWORDS_FILE}" | 108 die "ln -s ${WORKON_FILE} ${KEYWORDS_FILE}" |
93 fi | 109 fi |
94 if [ ! -L "${UNMASK_FILE}" ]; then | 110 if [ ! -L "${UNMASK_FILE}" ]; then |
95 [ -f "${UNMASK_FILE}" ] && sudo mv "${UNMASK_FILE}" "${WORKON_FILE}" | 111 [ -f "${UNMASK_FILE}" ] && sudo mv "${UNMASK_FILE}" "${WORKON_FILE}" |
96 sudo ln -s "${WORKON_FILE}" "${UNMASK_FILE}" || \ | 112 sudo ln -s "${WORKON_FILE}" "${UNMASK_FILE}" || \ |
97 die "ln -s ${WORKON_FILE} ${UNMASK_FILE}" | 113 die "ln -s ${WORKON_FILE} ${UNMASK_FILE}" |
98 fi | 114 fi |
99 | 115 |
100 find_keyword_workon_ebuilds() { | 116 find_keyword_workon_ebuilds() { |
101 keyword="${1}" | 117 local keyword="${1}" |
| 118 local overlay |
102 | 119 |
103 local cros_overlays=$("${PORTAGEQCMD}" envvar PORTDIR_OVERLAY) | 120 local cros_overlays=$("${PORTAGEQCMD}" envvar PORTDIR_OVERLAY) |
104 | 121 |
105 # NOTE: overlay may be a symlink, and we have to use ${overlay}/ | 122 # NOTE: overlay may be a symlink, and we have to use ${overlay}/ |
106 for overlay in ${cros_overlays}; do | 123 for overlay in ${cros_overlays}; do |
107 # only look up ebuilds named 9999 to eliminate duplicates | 124 # only look up ebuilds named 9999 to eliminate duplicates |
108 find ${overlay}/ -name '*9999.ebuild' | \ | 125 find ${overlay}/ -name '*9999.ebuild' | \ |
109 xargs grep -l "inherit.*cros-workon" | \ | 126 xargs grep -l "inherit.*cros-workon" | \ |
110 xargs grep -l "KEYWORDS=.*${keyword}.*" | 127 xargs grep -l "KEYWORDS=.*${keyword}.*" |
111 done | 128 done |
112 } | 129 } |
113 | 130 |
114 show_workon_ebuilds() { | 131 show_workon_ebuilds() { |
115 keyword=$1 | 132 local keyword=$1 |
116 | 133 |
117 find_keyword_workon_ebuilds ${keyword} | \ | 134 find_keyword_workon_ebuilds ${keyword} | \ |
118 sed -e 's/.*\/\([^/]*\)\/\([^/]*\)\/.*\.ebuild/\1\/\2/' | \ | 135 sed -e 's/.*\/\([^/]*\)\/\([^/]*\)\/.*\.ebuild/\1\/\2/' | \ |
119 sort -u | 136 sort -u |
120 # This changes the absolute path to ebuilds into category/package. | 137 # This changes the absolute path to ebuilds into category/package. |
121 } | 138 } |
122 | 139 |
123 # Canonicalize package name to category/package. | 140 # Canonicalize package name to category/package. |
124 canonicalize_name () { | 141 canonicalize_name () { |
125 local pkgfile | 142 local pkgfile |
(...skipping 17 matching lines...) Expand all Loading... |
143 return 1 | 160 return 1 |
144 fi | 161 fi |
145 echo "${pkgname}" | 162 echo "${pkgname}" |
146 return 0 | 163 return 0 |
147 } | 164 } |
148 | 165 |
149 # Canonicalize a list of names. | 166 # Canonicalize a list of names. |
150 canonicalize_names () { | 167 canonicalize_names () { |
151 local atoms=$1 | 168 local atoms=$1 |
152 local names="" | 169 local names="" |
| 170 local atom |
153 | 171 |
154 for atom in ${atoms}; do | 172 for atom in ${atoms}; do |
155 local name=$(canonicalize_name "${atom}") | 173 local name=$(canonicalize_name "${atom}") |
156 [ -n "${name}" ] || return 1 | 174 [ -n "${name}" ] || return 1 |
157 names+=" ${name}" | 175 names+=" ${name}" |
158 done | 176 done |
159 | 177 |
160 echo "${names}" | 178 echo "${names}" |
161 } | 179 } |
162 | 180 |
163 # Display ebuilds currently part of the live branch and open for development. | 181 # Display ebuilds currently part of the live branch and open for development. |
164 show_live_ebuilds () { | 182 show_live_ebuilds () { |
165 sed -n 's/^=\(.*\)-9999$/\1/p' "${WORKON_FILE}" | 183 sed -n 's/^=\(.*\)-9999$/\1/p' "${WORKON_FILE}" |
166 } | 184 } |
167 | 185 |
168 # Display ebuilds currently part of the live branch and open for development | 186 # Display ebuilds currently part of the live branch and open for development |
169 # for any board that currently has live ebuilds. | 187 # for any board that currently has live ebuilds. |
170 show_all_live_ebuilds () { | 188 show_all_live_ebuilds () { |
| 189 local workon_file |
171 for workon_file in ${WORKON_DIR}/*; do | 190 for workon_file in ${WORKON_DIR}/*; do |
172 if [ -s "${workon_file}" ]; then | 191 if [ -s "${workon_file}" ]; then |
173 echo -e "${V_BOLD_GREEN}$(basename ${workon_file}):${V_VIDOFF}" | 192 echo -e "${V_BOLD_GREEN}$(basename ${workon_file}):${V_VIDOFF}" |
174 sed -n 's/^=\(.*\)-9999$/ \1/p' "${workon_file}" | 193 sed -n 's/^=\(.*\)-9999$/ \1/p' "${workon_file}" |
175 echo "" | 194 echo "" |
176 fi | 195 fi |
177 done | 196 done |
178 } | 197 } |
179 | 198 |
180 # This is called only for "cros-workon start". We dont handle the "stop" case si
nce the local changes are ignored anyway since the 9999.ebuild is masked and we
dont want to deal with what to do with the user's local changes. | 199 # This is called only for "cros-workon start". We dont handle the |
| 200 # "stop" case since the local changes are ignored anyway since the |
| 201 # 9999.ebuild is masked and we dont want to deal with what to do with |
| 202 # the user's local changes. |
181 regen_manifest_and_sync() { | 203 regen_manifest_and_sync() { |
182 # Nothing to do unless you are working on the minilayout | 204 # Nothing to do unless you are working on the minilayout |
183 local manifest=${CHROOT_TRUNK_DIR}/.repo/manifest.xml | 205 local manifest=${CHROOT_TRUNK_DIR}/.repo/manifest.xml |
184 if [ $(basename $(readlink -f ${manifest})) != "minilayout.xml" ]; then | 206 if [ $(basename $(readlink -f ${manifest})) != "minilayout.xml" ]; then |
185 return | 207 return |
186 fi | 208 fi |
187 | 209 |
| 210 local pkgname |
188 for pkgname in $(show_live_ebuilds); do | 211 for pkgname in $(show_live_ebuilds); do |
189 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${pkgname}) info) | 212 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${pkgname}) info) |
190 local srcdir=$(readlink -m ${CROS_WORKON_SRCDIR}) | 213 local srcdir=$(readlink -m ${CROS_WORKON_SRCDIR}) |
191 local trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR}) | 214 local trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR}) |
192 local project_path=${srcdir#${trunkdir}/} | 215 local project_path=${srcdir#${trunkdir}/} |
193 | 216 |
194 loman add --workon "${CROS_WORKON_PROJECT}" "${project_path}" | 217 loman add --workon "${CROS_WORKON_PROJECT}" "${project_path}" |
195 done | 218 done |
196 echo "Please run \"repo sync\" now." | 219 echo "Please run \"repo sync\" now." |
197 } | 220 } |
198 | 221 |
199 # Move a stable ebuild to the live development catgeory. The ebuild | 222 # Move a stable ebuild to the live development catgeory. The ebuild |
200 # src_unpack step fetches the package source for local development. | 223 # src_unpack step fetches the package source for local development. |
201 ebuild_to_live () { | 224 ebuild_to_live () { |
202 local atoms=$1 | 225 local atoms=$1 |
203 local atoms_success="" | 226 local atoms_success="" |
| 227 local atom |
204 | 228 |
205 for atom in ${atoms}; do | 229 for atom in ${atoms}; do |
206 if ! grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then | 230 if ! grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then |
207 if sudo bash -c "echo \"=${atom}-9999\" >> \"${WORKON_FILE}\""; then | 231 if sudo bash -c "echo \"=${atom}-9999\" >> \"${WORKON_FILE}\""; then |
208 atoms_success="${atoms_success} ${atom}" | 232 atoms_success="${atoms_success} ${atom}" |
209 fi | 233 fi |
210 else | 234 else |
211 warn "Already working on ${atom}" | 235 warn "Already working on ${atom}" |
212 fi | 236 fi |
213 done | 237 done |
214 [ -n "${atoms_success}" ] && regen_manifest_and_sync && \ | 238 [ -n "${atoms_success}" ] && regen_manifest_and_sync && \ |
215 info "Started working on '${atoms_success/ /}' for '${BOARD_STR}'" | 239 info "Started working on '${atoms_success/ /}' for '${BOARD_STR}'" |
216 } | 240 } |
217 | 241 |
218 # Move a live development ebuild back to stable. | 242 # Move a live development ebuild back to stable. |
219 ebuild_to_stable () { | 243 ebuild_to_stable () { |
220 local atoms=$1 | 244 local atoms=$1 |
221 local atoms_success="" | 245 local atoms_success="" |
| 246 local atom |
222 | 247 |
223 for atom in ${atoms}; do | 248 for atom in ${atoms}; do |
224 if grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then | 249 if grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then |
225 if sudo sed -e "/^=${atom/\//\\/}-9999\$/d" -i "${WORKON_FILE}"; then | 250 if sudo sed -e "/^=${atom/\//\\/}-9999\$/d" -i "${WORKON_FILE}"; then |
226 atoms_success="${atoms_success} ${atom}" | 251 atoms_success="${atoms_success} ${atom}" |
227 fi | 252 fi |
228 else | 253 else |
229 warn "Not working on ${atom}" | 254 warn "Not working on ${atom}" |
230 fi | 255 fi |
231 done | 256 done |
232 [ -n "${atoms_success}" ] && \ | 257 [ -n "${atoms_success}" ] && \ |
233 info "Stopped working on '${atoms_success/ /}' for '${BOARD_STR}'" | 258 info "Stopped working on '${atoms_success/ /}' for '${BOARD_STR}'" |
234 } | 259 } |
235 | 260 |
236 # Run a command on all or a set of repos. | 261 # Run a command on all or a set of repos. |
237 ebuild_iterate() { | 262 ebuild_iterate() { |
238 local atoms=$1 | 263 local atoms=$1 |
| 264 local atom |
239 | 265 |
240 for atom in ${atoms}; do | 266 for atom in ${atoms}; do |
241 info "Running \"${FLAGS_command}\" on ${atom}" | 267 info "Running \"${FLAGS_command}\" on ${atom}" |
242 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${atom}) info) | 268 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${atom}) info) |
243 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}") | 269 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}") |
244 done | 270 done |
245 } | 271 } |
246 | 272 |
247 # --all makes commands operate on different lists | 273 # --all makes commands operate on different lists |
248 if [ ${FLAGS_all} = "${FLAGS_TRUE}" ]; then | 274 if [ ${FLAGS_all} = "${FLAGS_TRUE}" ]; then |
249 case ${WORKON_CMD} in | 275 case ${WORKON_CMD} in |
250 start) ATOM_LIST=$(show_workon_ebuilds ${BOARD_KEYWORD});; | 276 start) ATOM_LIST=$(show_workon_ebuilds ${BOARD_KEYWORD});; |
251 stop|iterate) ATOM_LIST=$(show_live_ebuilds);; | 277 stop|iterate) ATOM_LIST=$(show_live_ebuilds);; |
252 list|list-all) ;; | 278 list) ;; |
253 *) die "--all is invalid for the given command";; | 279 *) die "--all is invalid for the given command";; |
254 esac | 280 esac |
255 else # not selected --all | 281 else # not selected --all |
256 case ${WORKON_CMD} in | 282 case ${WORKON_CMD} in |
257 start|stop|iterate) | 283 start|stop|iterate) |
258 ATOM_LIST=$@ | 284 ATOM_LIST=$@ |
259 if [ -z "${ATOM_LIST}" ]; then | 285 if [ -z "${ATOM_LIST}" ]; then |
260 die "${WORKON_CMD}: No packages specified" | 286 die "${WORKON_CMD}: No packages specified" |
261 elif ! ATOM_LIST=$(canonicalize_names "${ATOM_LIST}"); then | 287 elif ! ATOM_LIST=$(canonicalize_names "${ATOM_LIST}"); then |
262 die "Error parsing package list" | 288 die "Error parsing package list" |
263 fi;; | 289 fi;; |
264 *) ;; | 290 *) ;; |
265 esac | 291 esac |
266 fi | 292 fi |
267 | 293 |
268 case ${WORKON_CMD} in | 294 case ${WORKON_CMD} in |
269 start) ebuild_to_live "${ATOM_LIST}" ;; | 295 start) ebuild_to_live "${ATOM_LIST}" ;; |
270 stop) ebuild_to_stable "${ATOM_LIST}" ;; | 296 stop) ebuild_to_stable "${ATOM_LIST}" ;; |
271 list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || show_worko
n_ebuilds ${BOARD_KEYWORD} ;; | 297 list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || \ |
| 298 show_workon_ebuilds ${BOARD_KEYWORD} ;; |
272 list-all) show_all_live_ebuilds ;; | 299 list-all) show_all_live_ebuilds ;; |
273 iterate)ebuild_iterate "${ATOM_LIST}" ;; | 300 iterate) ebuild_iterate "${ATOM_LIST}" ;; |
274 *) die "$(basename $0): command '${WORKON_CMD}' not recognized" ;; | 301 *) die "$(basename $0): command '${WORKON_CMD}' not recognized" ;; |
275 esac | 302 esac |
OLD | NEW |