Path: blob/aarch64-shenandoah-jdk8u272-b10/make/scripts/hgforest.sh
32284 views
#!/bin/sh12#3# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#2425# Shell script for a fast parallel forest command26command="$1"27pull_extra_base="$2"2829tmp=/tmp/forest.$$30rm -f -r ${tmp}31mkdir -p ${tmp}3233# Remove tmp area on A. B. Normal termination34trap 'rm -f -r ${tmp}' KILL35trap 'rm -f -r ${tmp}' EXIT3637# Only look in specific locations for possible forests (avoids long searches)38pull_default=""39repos=""40repos_extra=""41if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then42subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"43if [ -f .hg/hgrc ] ; then44pull_default=`hg paths default`45if [ "${pull_default}" = "" ] ; then46echo "ERROR: Need initial clone with 'hg paths default' defined"47exit 148fi49fi50if [ "${pull_default}" = "" ] ; then51echo "ERROR: Need initial repository to use this script"52exit 153fi54for i in ${subrepos} ; do55if [ ! -f ${i}/.hg/hgrc ] ; then56repos="${repos} ${i}"57fi58done59if [ "${pull_extra_base}" != "" ] ; then60subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"61pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`62pull_extra="${pull_extra_base}/${pull_default_tail}"63for i in ${subrepos_extra} ; do64if [ ! -f ${i}/.hg/hgrc ] ; then65repos_extra="${repos_extra} ${i}"66fi67done68fi69at_a_time=270# Any repos to deal with?71if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then72echo "No repositories to clone."73exit74fi75else76hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`77# Derive repository names from the .hg directory locations78for i in ${hgdirs} ; do79repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"80done81at_a_time=882# Any repos to deal with?83if [ "${repos}" = "" ] ; then84echo "No repositories to process."85exit86fi87fi8889# Echo out what repositories we will clone90echo "# Repos: ${repos} ${repos_extra}"9192# Run the supplied command on all repos in parallel, save output until end93n=094for i in ${repos} ; do95echo "Starting on ${i}"96n=`expr ${n} '+' 1`97(98(99if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then100pull_newrepo="`echo ${pull_default}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"101cline="hg clone ${pull_newrepo} ${i}"102echo "# ${cline}"103( eval "${cline}" )104else105cline="hg $*"106echo "# cd ${i} && ${cline}"107( cd ${i} && eval "${cline}" )108fi109echo "# exit code $?"110) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &111if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then112sleep 5113fi114done115# Wait for all hg commands to complete116wait117118if [ "${repos_extra}" != "" ] ; then119for i in ${repos_extra} ; do120echo "Starting on ${i}"121n=`expr ${n} '+' 1`122(123(124pull_newextrarepo="`echo ${pull_extra}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"125cline="hg clone ${pull_newextrarepo} ${i}"126echo "# ${cline}"127( eval "${cline}" )128echo "# exit code $?"129) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &130if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then131sleep 5132fi133done134# Wait for all hg commands to complete135wait136fi137138# Cleanup139rm -f -r ${tmp}140141# Terminate with exit 0 all the time (hard to know when to say "failed")142exit 0143144145146