Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: host/cros_workon

Issue 6368032: cros_workon: apply gspencer's cleanup from issue 6240018 (Closed) Base URL: http://git.chromium.org/git/dev-util.git@master
Patch Set: more fixup Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 . /usr/lib/crosutils/common.sh || (echo "Unable to load common.sh" && exit 1)
14 # The path to common.sh should be relative to your script's location.
15 . "$(dirname "$0")/common.sh"
16 14
17 # Script must be run inside the chroot 15 # Script must be run inside the chroot
18 restart_in_chroot_if_needed $*
19 get_default_board 16 get_default_board
20 17
21 DEFINE_string board "${DEFAULT_BOARD}" \ 18 DEFINE_string board "${DEFAULT_BOARD}" \
22 "The board to set package keywords for." 19 "The board to set package keywords for."
23 DEFINE_boolean host "${FLAGS_FALSE}" \ 20 DEFINE_boolean host "${FLAGS_FALSE}" \
24 "Uses the host instead of board" 21 "Uses the host instead of board"
25 DEFINE_string command "git status" \ 22 DEFINE_string command "git status" \
26 "The command to be run by forall." 23 "The command to be run by forall."
27 DEFINE_boolean all "${FLAGS_FALSE}" \ 24 DEFINE_boolean all "${FLAGS_FALSE}" \
28 "Apply to all possible packages for the given command" 25 "Apply to all possible packages for the given command"
29 26
30 FLAGS_HELP="usage: $0 <command> [flags] [<list of packages>|--all] 27 FLAGS_HELP="usage: $0 <command> [flags] [<list of packages>|--all]
31 commands: 28 commands:
32 start: Moves an ebuild to live (intended to support development) 29 start: Moves an ebuild to live (intended to support development)
33 stop: Moves an ebuild to stable (use last known good) 30 stop: Moves an ebuild to stable (use last known good)
34 list: List of live ebuilds (workon ebuilds if --all) 31 list: List of live ebuilds (workon ebuilds if --all)
35 list-all: List all of the live ebuilds for all setup boards 32 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" 33 iterate: For each ebuild, cd to the source dir and run a commond"
37 FLAGS "$@" || exit 1 34 FLAGS "$@" || exit 1
38 eval set -- "${FLAGS_ARGV}" 35 eval set -- "${FLAGS_ARGV}"
39 36
40 37
41 # eat the workon command keywords: start, stop or list. 38 # eat the workon command keywords: start, stop or list.
42 WORKON_CMD=$1 39 WORKON_CMD=$1
43 shift 40 shift
44 41
45
46 # Board dir config 42 # Board dir config
47 43
48 # If both are specified, just use host, because board does not 44 # If both are specified, just use host, because board does not
49 # have to be specified and may come from default, in which case 45 # have to be specified and may come from default, in which case
50 # there's no way to override. 46 # there's no way to override.
51 [ -n "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_TRUE} ] && \ 47 [ -n "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_TRUE} ] && \
52 FLAGS_board="" # kill board 48 FLAGS_board="" # kill board
53 [ -z "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_FALSE} ] && \ 49 [ -z "${FLAGS_board}" ] && [ "${FLAGS_host}" = ${FLAGS_FALSE} ] && \
54 [ "${WORKON_CMD}" != "list-all" ] && \ 50 [ "${WORKON_CMD}" != "list-all" ] && \
55 die "You must specify either --host or --board=" 51 die "You must specify either --host or --board="
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 sudo ln -s "${WORKON_FILE}" "${KEYWORDS_FILE}" || \ 87 sudo ln -s "${WORKON_FILE}" "${KEYWORDS_FILE}" || \
92 die "ln -s ${WORKON_FILE} ${KEYWORDS_FILE}" 88 die "ln -s ${WORKON_FILE} ${KEYWORDS_FILE}"
93 fi 89 fi
94 if [ ! -L "${UNMASK_FILE}" ]; then 90 if [ ! -L "${UNMASK_FILE}" ]; then
95 [ -f "${UNMASK_FILE}" ] && sudo mv "${UNMASK_FILE}" "${WORKON_FILE}" 91 [ -f "${UNMASK_FILE}" ] && sudo mv "${UNMASK_FILE}" "${WORKON_FILE}"
96 sudo ln -s "${WORKON_FILE}" "${UNMASK_FILE}" || \ 92 sudo ln -s "${WORKON_FILE}" "${UNMASK_FILE}" || \
97 die "ln -s ${WORKON_FILE} ${UNMASK_FILE}" 93 die "ln -s ${WORKON_FILE} ${UNMASK_FILE}"
98 fi 94 fi
99 95
100 find_keyword_workon_ebuilds() { 96 find_keyword_workon_ebuilds() {
101 keyword="${1}" 97 local keyword="${1}"
98 local overlay
102 99
103 local cros_overlays=$("${PORTAGEQCMD}" envvar PORTDIR_OVERLAY) 100 local cros_overlays=$("${PORTAGEQCMD}" envvar PORTDIR_OVERLAY)
104 101
105 # NOTE: overlay may be a symlink, and we have to use ${overlay}/ 102 # NOTE: overlay may be a symlink, and we have to use ${overlay}/
106 for overlay in ${cros_overlays}; do 103 for overlay in ${cros_overlays}; do
107 # only look up ebuilds named 9999 to eliminate duplicates 104 # only look up ebuilds named 9999 to eliminate duplicates
108 find ${overlay}/ -name '*9999.ebuild' | \ 105 find ${overlay}/ -name '*9999.ebuild' | \
109 xargs grep -l "inherit.*cros-workon" | \ 106 xargs grep -l "inherit.*cros-workon" | \
110 xargs grep -l "KEYWORDS=.*${keyword}.*" 107 xargs grep -l "KEYWORDS=.*${keyword}.*"
111 done 108 done
112 } 109 }
113 110
114 show_workon_ebuilds() { 111 show_workon_ebuilds() {
115 keyword=$1 112 local keyword=$1
116 113
117 find_keyword_workon_ebuilds ${keyword} | \ 114 find_keyword_workon_ebuilds ${keyword} | \
118 sed -e 's/.*\/\([^/]*\)\/\([^/]*\)\/.*\.ebuild/\1\/\2/' | \ 115 sed -e 's/.*\/\([^/]*\)\/\([^/]*\)\/.*\.ebuild/\1\/\2/' | \
119 sort -u 116 sort -u
120 # This changes the absolute path to ebuilds into category/package. 117 # This changes the absolute path to ebuilds into category/package.
121 } 118 }
122 119
123 # Canonicalize package name to category/package. 120 # Canonicalize package name to category/package.
124 canonicalize_name () { 121 canonicalize_name () {
125 local pkgfile 122 local pkgfile
(...skipping 17 matching lines...) Expand all
143 return 1 140 return 1
144 fi 141 fi
145 echo "${pkgname}" 142 echo "${pkgname}"
146 return 0 143 return 0
147 } 144 }
148 145
149 # Canonicalize a list of names. 146 # Canonicalize a list of names.
150 canonicalize_names () { 147 canonicalize_names () {
151 local atoms=$1 148 local atoms=$1
152 local names="" 149 local names=""
150 local atom
153 151
154 for atom in ${atoms}; do 152 for atom in ${atoms}; do
155 local name=$(canonicalize_name "${atom}") 153 local name=$(canonicalize_name "${atom}")
156 [ -n "${name}" ] || return 1 154 [ -n "${name}" ] || return 1
157 names+=" ${name}" 155 names+=" ${name}"
158 done 156 done
159 157
160 echo "${names}" 158 echo "${names}"
161 } 159 }
162 160
163 # Display ebuilds currently part of the live branch and open for development. 161 # Display ebuilds currently part of the live branch and open for development.
164 show_live_ebuilds () { 162 show_live_ebuilds () {
165 sed -n 's/^=\(.*\)-9999$/\1/p' "${WORKON_FILE}" 163 sed -n 's/^=\(.*\)-9999$/\1/p' "${WORKON_FILE}"
166 } 164 }
167 165
168 # Display ebuilds currently part of the live branch and open for development 166 # Display ebuilds currently part of the live branch and open for development
169 # for any board that currently has live ebuilds. 167 # for any board that currently has live ebuilds.
170 show_all_live_ebuilds () { 168 show_all_live_ebuilds () {
169 local workon_file
171 for workon_file in ${WORKON_DIR}/*; do 170 for workon_file in ${WORKON_DIR}/*; do
172 if [ -s "${workon_file}" ]; then 171 if [ -s "${workon_file}" ]; then
173 echo -e "${V_BOLD_GREEN}$(basename ${workon_file}):${V_VIDOFF}" 172 echo -e "${V_BOLD_GREEN}$(basename ${workon_file}):${V_VIDOFF}"
174 sed -n 's/^=\(.*\)-9999$/ \1/p' "${workon_file}" 173 sed -n 's/^=\(.*\)-9999$/ \1/p' "${workon_file}"
175 echo "" 174 echo ""
176 fi 175 fi
177 done 176 done
178 } 177 }
179 178
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. 179 # This is called only for "cros-workon start". We dont handle the
180 # "stop" case since the local changes are ignored anyway since the
181 # 9999.ebuild is masked and we dont want to deal with what to do with
182 # the user's local changes.
181 regen_manifest_and_sync() { 183 regen_manifest_and_sync() {
182 # Nothing to do unless you are working on the minilayout 184 # Nothing to do unless you are working on the minilayout
183 local manifest=${CHROOT_TRUNK_DIR}/.repo/manifest.xml 185 local manifest=${CHROOT_TRUNK_DIR}/.repo/manifest.xml
184 if [ $(basename $(readlink -f ${manifest})) != "minilayout.xml" ]; then 186 if [ $(basename $(readlink -f ${manifest})) != "minilayout.xml" ]; then
185 return 187 return
186 fi 188 fi
187 189
190 local pkgname
188 for pkgname in $(show_live_ebuilds); do 191 for pkgname in $(show_live_ebuilds); do
189 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${pkgname}) info) 192 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${pkgname}) info)
190 local srcdir=$(readlink -m ${CROS_WORKON_SRCDIR}) 193 local srcdir=$(readlink -m ${CROS_WORKON_SRCDIR})
191 local trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR}) 194 local trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR})
192 local project_path=${srcdir#${trunkdir}/} 195 local project_path=${srcdir#${trunkdir}/}
193 196
194 loman add --workon "${CROS_WORKON_PROJECT}" "${project_path}" 197 loman add --workon "${CROS_WORKON_PROJECT}" "${project_path}"
195 done 198 done
196 echo "Please run \"repo sync\" now." 199 echo "Please run \"repo sync\" now."
197 } 200 }
198 201
199 # Move a stable ebuild to the live development catgeory. The ebuild 202 # Move a stable ebuild to the live development catgeory. The ebuild
200 # src_unpack step fetches the package source for local development. 203 # src_unpack step fetches the package source for local development.
201 ebuild_to_live () { 204 ebuild_to_live () {
202 local atoms=$1 205 local atoms=$1
203 local atoms_success="" 206 local atoms_success=""
207 local atom
204 208
205 for atom in ${atoms}; do 209 for atom in ${atoms}; do
206 if ! grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then 210 if ! grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then
207 if sudo bash -c "echo \"=${atom}-9999\" >> \"${WORKON_FILE}\""; then 211 if sudo bash -c "echo \"=${atom}-9999\" >> \"${WORKON_FILE}\""; then
208 atoms_success="${atoms_success} ${atom}" 212 atoms_success="${atoms_success} ${atom}"
209 fi 213 fi
210 else 214 else
211 warn "Already working on ${atom}" 215 warn "Already working on ${atom}"
212 fi 216 fi
213 done 217 done
214 [ -n "${atoms_success}" ] && regen_manifest_and_sync && \ 218 [ -n "${atoms_success}" ] && regen_manifest_and_sync && \
215 info "Started working on '${atoms_success/ /}' for '${BOARD_STR}'" 219 info "Started working on '${atoms_success/ /}' for '${BOARD_STR}'"
216 } 220 }
217 221
218 # Move a live development ebuild back to stable. 222 # Move a live development ebuild back to stable.
219 ebuild_to_stable () { 223 ebuild_to_stable () {
220 local atoms=$1 224 local atoms=$1
221 local atoms_success="" 225 local atoms_success=""
226 local atom
222 227
223 for atom in ${atoms}; do 228 for atom in ${atoms}; do
224 if grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then 229 if grep -qx "=${atom}-9999" "${WORKON_FILE}" ; then
225 if sudo sed -e "/^=${atom/\//\\/}-9999\$/d" -i "${WORKON_FILE}"; then 230 if sudo sed -e "/^=${atom/\//\\/}-9999\$/d" -i "${WORKON_FILE}"; then
226 atoms_success="${atoms_success} ${atom}" 231 atoms_success="${atoms_success} ${atom}"
227 fi 232 fi
228 else 233 else
229 warn "Not working on ${atom}" 234 warn "Not working on ${atom}"
230 fi 235 fi
231 done 236 done
232 [ -n "${atoms_success}" ] && \ 237 [ -n "${atoms_success}" ] && \
233 info "Stopped working on '${atoms_success/ /}' for '${BOARD_STR}'" 238 info "Stopped working on '${atoms_success/ /}' for '${BOARD_STR}'"
234 } 239 }
235 240
236 # Run a command on all or a set of repos. 241 # Run a command on all or a set of repos.
237 ebuild_iterate() { 242 ebuild_iterate() {
238 local atoms=$1 243 local atoms=$1
244 local atom
239 245
240 for atom in ${atoms}; do 246 for atom in ${atoms}; do
241 info "Running \"${FLAGS_command}\" on ${atom}" 247 info "Running \"${FLAGS_command}\" on ${atom}"
242 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${atom}) info) 248 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${atom}) info)
243 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}") 249 (cd "${CROS_WORKON_SRCDIR}" && bash -c "${FLAGS_command}")
244 done 250 done
245 } 251 }
246 252
247 # --all makes commands operate on different lists 253 # --all makes commands operate on different lists
248 if [ ${FLAGS_all} = "${FLAGS_TRUE}" ]; then 254 if [ ${FLAGS_all} = "${FLAGS_TRUE}" ]; then
249 case ${WORKON_CMD} in 255 case ${WORKON_CMD} in
250 start) ATOM_LIST=$(show_workon_ebuilds ${BOARD_KEYWORD});; 256 start) ATOM_LIST=$(show_workon_ebuilds ${BOARD_KEYWORD});;
251 stop|iterate) ATOM_LIST=$(show_live_ebuilds);; 257 stop|iterate) ATOM_LIST=$(show_live_ebuilds);;
252 list|list-all) ;; 258 list) ;;
253 *) die "--all is invalid for the given command";; 259 *) die "--all is invalid for the given command";;
254 esac 260 esac
255 else # not selected --all 261 else # not selected --all
256 case ${WORKON_CMD} in 262 case ${WORKON_CMD} in
257 start|stop|iterate) 263 start|stop|iterate)
258 ATOM_LIST=$@ 264 ATOM_LIST=$@
259 if [ -z "${ATOM_LIST}" ]; then 265 if [ -z "${ATOM_LIST}" ]; then
260 die "${WORKON_CMD}: No packages specified" 266 die "${WORKON_CMD}: No packages specified"
261 elif ! ATOM_LIST=$(canonicalize_names "${ATOM_LIST}"); then 267 elif ! ATOM_LIST=$(canonicalize_names "${ATOM_LIST}"); then
262 die "Error parsing package list" 268 die "Error parsing package list"
263 fi;; 269 fi;;
264 *) ;; 270 *) ;;
265 esac 271 esac
266 fi 272 fi
267 273
268 case ${WORKON_CMD} in 274 case ${WORKON_CMD} in
269 start) ebuild_to_live "${ATOM_LIST}" ;; 275 start) ebuild_to_live "${ATOM_LIST}" ;;
270 stop) ebuild_to_stable "${ATOM_LIST}" ;; 276 stop) ebuild_to_stable "${ATOM_LIST}" ;;
271 list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || show_worko n_ebuilds ${BOARD_KEYWORD} ;; 277 list) [ ${FLAGS_all} = "${FLAGS_FALSE}" ] && show_live_ebuilds || \
278 show_workon_ebuilds ${BOARD_KEYWORD} ;;
272 list-all) show_all_live_ebuilds ;; 279 list-all) show_all_live_ebuilds ;;
273 iterate)ebuild_iterate "${ATOM_LIST}" ;; 280 iterate) ebuild_iterate "${ATOM_LIST}" ;;
274 *) die "$(basename $0): command '${WORKON_CMD}' not recognized" ;; 281 *) die "$(basename $0): command '${WORKON_CMD}' not recognized" ;;
275 esac 282 esac
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698