1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/make/scripts/hgforest.sh Wed Apr 27 01:39:08 2016 +0800 1.3 @@ -0,0 +1,144 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +# 1.7 +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 1.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.9 +# 1.10 +# This code is free software; you can redistribute it and/or modify it 1.11 +# under the terms of the GNU General Public License version 2 only, as 1.12 +# published by the Free Software Foundation. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 +# or visit www.oracle.com if you need additional information or have any 1.26 +# questions. 1.27 +# 1.28 + 1.29 +# Shell script for a fast parallel forest command 1.30 +command="$1" 1.31 +pull_extra_base="$2" 1.32 + 1.33 +tmp=/tmp/forest.$$ 1.34 +rm -f -r ${tmp} 1.35 +mkdir -p ${tmp} 1.36 + 1.37 +# Remove tmp area on A. B. Normal termination 1.38 +trap 'rm -f -r ${tmp}' KILL 1.39 +trap 'rm -f -r ${tmp}' EXIT 1.40 + 1.41 +# Only look in specific locations for possible forests (avoids long searches) 1.42 +pull_default="" 1.43 +repos="" 1.44 +repos_extra="" 1.45 +if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.46 + subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" 1.47 + if [ -f .hg/hgrc ] ; then 1.48 + pull_default=`hg paths default` 1.49 + if [ "${pull_default}" = "" ] ; then 1.50 + echo "ERROR: Need initial clone with 'hg paths default' defined" 1.51 + exit 1 1.52 + fi 1.53 + fi 1.54 + if [ "${pull_default}" = "" ] ; then 1.55 + echo "ERROR: Need initial repository to use this script" 1.56 + exit 1 1.57 + fi 1.58 + for i in ${subrepos} ; do 1.59 + if [ ! -f ${i}/.hg/hgrc ] ; then 1.60 + repos="${repos} ${i}" 1.61 + fi 1.62 + done 1.63 + if [ "${pull_extra_base}" != "" ] ; then 1.64 + subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" 1.65 + pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` 1.66 + pull_extra="${pull_extra_base}/${pull_default_tail}" 1.67 + for i in ${subrepos_extra} ; do 1.68 + if [ ! -f ${i}/.hg/hgrc ] ; then 1.69 + repos_extra="${repos_extra} ${i}" 1.70 + fi 1.71 + done 1.72 + fi 1.73 + at_a_time=2 1.74 + # Any repos to deal with? 1.75 + if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then 1.76 + echo "No repositories to clone." 1.77 + exit 1.78 + fi 1.79 +else 1.80 + hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` 1.81 + # Derive repository names from the .hg directory locations 1.82 + for i in ${hgdirs} ; do 1.83 + repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" 1.84 + done 1.85 + at_a_time=8 1.86 + # Any repos to deal with? 1.87 + if [ "${repos}" = "" ] ; then 1.88 + echo "No repositories to process." 1.89 + exit 1.90 + fi 1.91 +fi 1.92 + 1.93 +# Echo out what repositories we will clone 1.94 +echo "# Repos: ${repos} ${repos_extra}" 1.95 + 1.96 +# Run the supplied command on all repos in parallel, save output until end 1.97 +n=0 1.98 +for i in ${repos} ; do 1.99 + echo "Starting on ${i}" 1.100 + n=`expr ${n} '+' 1` 1.101 + ( 1.102 + ( 1.103 + if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then 1.104 + pull_newrepo="`echo ${pull_default}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.105 + cline="hg clone ${pull_newrepo} ${i}" 1.106 + echo "# ${cline}" 1.107 + ( eval "${cline}" ) 1.108 + else 1.109 + cline="hg $*" 1.110 + echo "# cd ${i} && ${cline}" 1.111 + ( cd ${i} && eval "${cline}" ) 1.112 + fi 1.113 + echo "# exit code $?" 1.114 + ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & 1.115 + if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.116 + sleep 5 1.117 + fi 1.118 +done 1.119 +# Wait for all hg commands to complete 1.120 +wait 1.121 + 1.122 +if [ "${repos_extra}" != "" ] ; then 1.123 + for i in ${repos_extra} ; do 1.124 + echo "Starting on ${i}" 1.125 + n=`expr ${n} '+' 1` 1.126 + ( 1.127 + ( 1.128 + pull_newextrarepo="`echo ${pull_extra}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" 1.129 + cline="hg clone ${pull_newextrarepo} ${i}" 1.130 + echo "# ${cline}" 1.131 + ( eval "${cline}" ) 1.132 + echo "# exit code $?" 1.133 + ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & 1.134 + if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then 1.135 + sleep 5 1.136 + fi 1.137 + done 1.138 + # Wait for all hg commands to complete 1.139 + wait 1.140 +fi 1.141 + 1.142 +# Cleanup 1.143 +rm -f -r ${tmp} 1.144 + 1.145 +# Terminate with exit 0 all the time (hard to know when to say "failed") 1.146 +exit 0 1.147 +