common/bin/hgforest.sh

Tue, 15 Jul 2014 18:46:37 -0700

author
mikael
date
Tue, 15 Jul 2014 18:46:37 -0700
changeset 1140
6d0ebf545f49
parent 902
d832f6171acd
child 1133
50aaf272884f
child 1141
183f87e4b8a7
permissions
-rw-r--r--

8029797: Let jprt run configure when building
Reviewed-by: dholmes

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

mercurial