annotate common/bin/hgforest.sh @ 890:13ddc5c3ebfc

Merge
author jlaskey
date Sat, 02 Mar 2013 10:28:16 -0400
parents e877cb3eb4d6 5b0b6ef58dbf
children 1378ccca1c79
rev   line source
ohrstrom@536 1 #!/bin/sh
ohrstrom@536 2
ohrstrom@536 3 #
ohrstrom@536 4 # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
ohrstrom@536 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohrstrom@536 6 #
ohrstrom@536 7 # This code is free software; you can redistribute it and/or modify it
ohrstrom@536 8 # under the terms of the GNU General Public License version 2 only, as
ohrstrom@536 9 # published by the Free Software Foundation.
ohrstrom@536 10 #
ohrstrom@536 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohrstrom@536 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohrstrom@536 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohrstrom@536 14 # version 2 for more details (a copy is included in the LICENSE file that
ohrstrom@536 15 # accompanied this code).
ohrstrom@536 16 #
ohrstrom@536 17 # You should have received a copy of the GNU General Public License version
ohrstrom@536 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohrstrom@536 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohrstrom@536 20 #
ohrstrom@536 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohrstrom@536 22 # or visit www.oracle.com if you need additional information or have any
ohrstrom@536 23 # questions.
ohrstrom@536 24 #
ohrstrom@536 25
ohrstrom@536 26 # Shell script for a fast parallel forest command
ohrstrom@536 27 command="$1"
ohrstrom@536 28 pull_extra_base="$2"
ohrstrom@536 29
ohrstrom@536 30 # Python always buffers stdout significantly, thus we will not see any output from hg clone jdk,
ohrstrom@536 31 # until a lot of time has passed! By passing -u to python, we get incremental updates
ohrstrom@536 32 # on stdout. Much nicer.
ohrstrom@536 33 whichhg="`which hg`"
ohrstrom@536 34
ohrstrom@536 35 if [ "${whichhg}" = "" ] ; then
ohrstrom@536 36 echo Cannot find hg!
ohrstrom@536 37 exit 1
ohrstrom@536 38 fi
ohrstrom@536 39
ohrstrom@536 40 if [ "" = "$command" ] ; then
ohrstrom@536 41 echo No command to hg supplied!
ohrstrom@536 42 exit 1
ohrstrom@536 43 fi
ohrstrom@536 44
ohrstrom@536 45 has_hash_bang="`head -n 1 "${whichhg}" | cut -b 1-2`"
ohrstrom@536 46 python=""
ohrstrom@536 47 bpython=""
ohrstrom@536 48
ohrstrom@536 49 if [ "#!" = "$has_hash_bang" ] ; then
ohrstrom@536 50 python="`head -n 1 ${whichhg} | cut -b 3-`"
ohrstrom@536 51 bpython="`basename "$python"`"
ohrstrom@536 52 fi
ohrstrom@536 53
ohrstrom@536 54 if [ "python" = "$bpython" -a -x "$python" ] ; then
ohrstrom@536 55 hg="${python} -u ${whichhg}"
ohrstrom@536 56 else
ohrstrom@536 57 echo Cannot find python from hg launcher. Running plain hg, which probably has buffered stdout.
ohrstrom@536 58 hg="hg"
ohrstrom@536 59 fi
ohrstrom@536 60
ohrstrom@536 61 # Clean out the temporary directory that stores the pid files.
ohrstrom@536 62 tmp=/tmp/forest.$$
ohrstrom@536 63 rm -f -r ${tmp}
ohrstrom@536 64 mkdir -p ${tmp}
ohrstrom@536 65
ohrstrom@536 66 safe_interrupt () {
chegar@613 67 if [ -d ${tmp} ]; then
chegar@613 68 if [ "`ls ${tmp}/*.pid`" != "" ]; then
chegar@613 69 echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!"
ohrstrom@536 70 sleep 1
ohrstrom@536 71 # Pipe stderr to dev/null to silence kill, that complains when trying to kill
ohrstrom@536 72 # a subprocess that has already exited.
chegar@613 73 kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null
chegar@613 74 wait
chegar@613 75 echo Interrupt complete!
chegar@613 76 fi
ohrstrom@536 77 fi
ohrstrom@536 78 rm -f -r ${tmp}
ohrstrom@536 79 exit 1
ohrstrom@536 80 }
ohrstrom@536 81
ohrstrom@536 82 nice_exit () {
chegar@613 83 if [ -d ${tmp} ]; then
chegar@613 84 if [ "`ls ${tmp}`" != "" ]; then
chegar@613 85 wait
chegar@613 86 fi
ohrstrom@536 87 fi
ohrstrom@536 88 rm -f -r ${tmp}
ohrstrom@536 89 }
ohrstrom@536 90
ohrstrom@536 91 trap 'safe_interrupt' INT QUIT
ohrstrom@536 92 trap 'nice_exit' EXIT
chegar@613 93
ohrstrom@536 94 # Only look in specific locations for possible forests (avoids long searches)
ohrstrom@536 95 pull_default=""
ohrstrom@536 96 repos=""
ohrstrom@536 97 repos_extra=""
ohrstrom@536 98 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
jjg@643 99 subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
ohrstrom@536 100 if [ -f .hg/hgrc ] ; then
ohrstrom@536 101 pull_default=`hg paths default`
ohrstrom@536 102 if [ "${pull_default}" = "" ] ; then
ohrstrom@536 103 echo "ERROR: Need initial clone with 'hg paths default' defined"
ohrstrom@536 104 exit 1
ohrstrom@536 105 fi
ohrstrom@536 106 fi
ohrstrom@536 107 if [ "${pull_default}" = "" ] ; then
ohrstrom@536 108 echo "ERROR: Need initial repository to use this script"
ohrstrom@536 109 exit 1
ohrstrom@536 110 fi
ohrstrom@536 111 for i in ${subrepos} ; do
ohrstrom@536 112 if [ ! -f ${i}/.hg/hgrc ] ; then
ohrstrom@536 113 repos="${repos} ${i}"
ohrstrom@536 114 fi
ohrstrom@536 115 done
ohrstrom@536 116 if [ "${pull_extra_base}" != "" ] ; then
ohrstrom@536 117 subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
ohrstrom@536 118 pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
ohrstrom@536 119 pull_extra="${pull_extra_base}/${pull_default_tail}"
ohrstrom@536 120 for i in ${subrepos_extra} ; do
ohrstrom@536 121 if [ ! -f ${i}/.hg/hgrc ] ; then
ohrstrom@536 122 repos_extra="${repos_extra} ${i}"
ohrstrom@536 123 fi
ohrstrom@536 124 done
ohrstrom@536 125 fi
ohrstrom@536 126 at_a_time=2
ohrstrom@536 127 # Any repos to deal with?
ohrstrom@536 128 if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
ohrstrom@536 129 exit
ohrstrom@536 130 fi
ohrstrom@536 131 else
ohrstrom@536 132 hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
ohrstrom@536 133 # Derive repository names from the .hg directory locations
ohrstrom@536 134 for i in ${hgdirs} ; do
ohrstrom@536 135 repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
ohrstrom@536 136 done
ohrstrom@536 137 for i in ${repos} ; do
ohrstrom@536 138 if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then
ohrstrom@536 139 locked="${i} ${locked}"
ohrstrom@536 140 fi
ohrstrom@536 141 done
ohrstrom@536 142 at_a_time=8
ohrstrom@536 143 # Any repos to deal with?
ohrstrom@536 144 if [ "${repos}" = "" ] ; then
ohrstrom@536 145 echo "No repositories to process."
ohrstrom@536 146 exit
ohrstrom@536 147 fi
ohrstrom@536 148 if [ "${locked}" != "" ] ; then
ohrstrom@536 149 echo "These repositories are locked: ${locked}"
ohrstrom@536 150 exit
ohrstrom@536 151 fi
ohrstrom@536 152 fi
ohrstrom@536 153
ohrstrom@536 154 # Echo out what repositories we do a command on.
ohrstrom@536 155 echo "# Repositories: ${repos} ${repos_extra}"
ohrstrom@536 156 echo
ohrstrom@536 157
ohrstrom@536 158 # Run the supplied command on all repos in parallel.
ohrstrom@536 159 n=0
ohrstrom@536 160 for i in ${repos} ${repos_extra} ; do
ohrstrom@536 161 n=`expr ${n} '+' 1`
ohrstrom@536 162 repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
ohrstrom@536 163 reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
ohrstrom@536 164 pull_base="${pull_default}"
ohrstrom@536 165 for j in $repos_extra ; do
ohrstrom@536 166 if [ "$i" = "$j" ] ; then
ohrstrom@536 167 pull_base="${pull_extra}"
ohrstrom@536 168 fi
ohrstrom@536 169 done
ohrstrom@536 170 (
ohrstrom@536 171 (
ohrstrom@536 172 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
ohrstrom@536 173 pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
ohrstrom@536 174 echo ${hg} clone ${pull_newrepo} ${i}
chegar@613 175 path="`dirname ${i}`"
chegar@613 176 if [ "${path}" != "." ] ; then
chegar@613 177 times=0
chegar@613 178 while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists
chegar@613 179 do
chegar@613 180 times=`expr ${times} '+' 1`
chegar@613 181 if [ `expr ${times} '%' 10` -eq 0 ] ; then
chegar@613 182 echo ${path} still not created, waiting...
chegar@613 183 fi
chegar@613 184 sleep 5
chegar@613 185 done
chegar@613 186 fi
chegar@613 187 (${hg} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
ohrstrom@536 188 else
ohrstrom@536 189 echo "cd ${i} && ${hg} $*"
chegar@613 190 cd ${i} && (${hg} "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc )&
chegar@613 191 fi
ohrstrom@536 192 echo $! > ${tmp}/${repopidfile}.pid
ohrstrom@536 193 ) 2>&1 | sed -e "s@^@${reponame}: @") &
chegar@613 194
ohrstrom@536 195 if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
ohrstrom@536 196 sleep 2
ohrstrom@536 197 echo Waiting 5 secs before spawning next background command.
ohrstrom@536 198 sleep 3
ohrstrom@536 199 fi
ohrstrom@536 200 done
ohrstrom@536 201 # Wait for all hg commands to complete
ohrstrom@536 202 wait
ohrstrom@536 203
chegar@613 204 # Terminate with exit 0 only if all subprocesses were successful
chegar@613 205 ec=0
chegar@613 206 if [ -d ${tmp} ]; then
chegar@613 207 for rc in ${tmp}/*.pid.rc ; do
chegar@613 208 exit_code=`cat ${rc} | tr -d ' \n\r'`
chegar@613 209 if [ "${exit_code}" != "0" ] ; then
chegar@613 210 echo "WARNING: ${rc} exited abnormally."
chegar@613 211 ec=1
chegar@613 212 fi
chegar@613 213 done
chegar@613 214 fi
chegar@613 215 exit ${ec}