aoqi@0: #!/bin/sh aoqi@0: aoqi@0: # aoqi@0: # Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: # aoqi@0: # This code is free software; you can redistribute it and/or modify it aoqi@0: # under the terms of the GNU General Public License version 2 only, as aoqi@0: # published by the Free Software Foundation. aoqi@0: # aoqi@0: # This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: # version 2 for more details (a copy is included in the LICENSE file that aoqi@0: # accompanied this code). aoqi@0: # aoqi@0: # You should have received a copy of the GNU General Public License version aoqi@0: # 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: # aoqi@0: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: # or visit www.oracle.com if you need additional information or have any aoqi@0: # questions. aoqi@0: # aoqi@0: aoqi@1: # aoqi@1: # This file has been modified by Loongson Technology in 2013. These aoqi@1: # modifications are Copyright (c) 2013 Loongson Technology, and are made aoqi@1: # available on the same license terms set forth above. aoqi@1: # aoqi@1: aoqi@0: # Shell script for a fast parallel forest command aoqi@0: command="$1" aoqi@0: pull_extra_base="$2" aoqi@0: aoqi@0: if [ "" = "$command" ] ; then aoqi@0: echo No command to hg supplied! aoqi@0: exit 1 aoqi@0: fi aoqi@0: aoqi@0: # Clean out the temporary directory that stores the pid files. aoqi@0: tmp=/tmp/forest.$$ aoqi@0: rm -f -r ${tmp} aoqi@0: mkdir -p ${tmp} aoqi@0: aoqi@0: safe_interrupt () { aoqi@0: if [ -d ${tmp} ]; then aoqi@0: if [ "`ls ${tmp}/*.pid`" != "" ]; then aoqi@0: echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" aoqi@0: sleep 1 aoqi@0: # Pipe stderr to dev/null to silence kill, that complains when trying to kill aoqi@0: # a subprocess that has already exited. aoqi@0: kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null aoqi@0: wait aoqi@0: echo Interrupt complete! aoqi@0: fi aoqi@0: fi aoqi@0: rm -f -r ${tmp} aoqi@0: exit 1 aoqi@0: } aoqi@0: aoqi@0: nice_exit () { aoqi@0: if [ -d ${tmp} ]; then aoqi@0: if [ "`ls ${tmp}`" != "" ]; then aoqi@0: wait aoqi@0: fi aoqi@0: fi aoqi@0: rm -f -r ${tmp} aoqi@0: } aoqi@0: aoqi@0: trap 'safe_interrupt' INT QUIT aoqi@0: trap 'nice_exit' EXIT aoqi@0: aoqi@0: # Only look in specific locations for possible forests (avoids long searches) aoqi@0: pull_default="" aoqi@0: repos="" aoqi@0: repos_extra="" aoqi@0: if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then aoqi@0: subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" aoqi@0: if [ -f .hg/hgrc ] ; then aoqi@0: pull_default=`hg paths default` aoqi@0: if [ "${pull_default}" = "" ] ; then aoqi@0: echo "ERROR: Need initial clone with 'hg paths default' defined" aoqi@0: exit 1 aoqi@0: fi aoqi@0: fi aoqi@0: if [ "${pull_default}" = "" ] ; then aoqi@0: echo "ERROR: Need initial repository to use this script" aoqi@0: exit 1 aoqi@0: fi aoqi@0: for i in ${subrepos} ; do aoqi@0: if [ ! -f ${i}/.hg/hgrc ] ; then aoqi@0: repos="${repos} ${i}" aoqi@0: fi aoqi@0: done aoqi@0: if [ "${pull_extra_base}" != "" ] ; then aoqi@0: subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" aoqi@0: pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` aoqi@0: pull_extra="${pull_extra_base}/${pull_default_tail}" aoqi@0: for i in ${subrepos_extra} ; do aoqi@0: if [ ! -f ${i}/.hg/hgrc ] ; then aoqi@0: repos_extra="${repos_extra} ${i}" aoqi@0: fi aoqi@0: done aoqi@0: fi aoqi@0: at_a_time=2 aoqi@0: # Any repos to deal with? aoqi@0: if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then aoqi@0: exit aoqi@0: fi aoqi@0: else aoqi@0: hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` aoqi@0: # Derive repository names from the .hg directory locations aoqi@0: for i in ${hgdirs} ; do aoqi@0: repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" aoqi@0: done aoqi@0: for i in ${repos} ; do aoqi@0: if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then aoqi@0: locked="${i} ${locked}" aoqi@0: fi aoqi@0: done aoqi@0: at_a_time=8 aoqi@0: # Any repos to deal with? aoqi@0: if [ "${repos}" = "" ] ; then aoqi@0: echo "No repositories to process." aoqi@0: exit aoqi@0: fi aoqi@0: if [ "${locked}" != "" ] ; then aoqi@0: echo "These repositories are locked: ${locked}" aoqi@0: exit aoqi@0: fi aoqi@0: fi aoqi@0: aoqi@0: # Echo out what repositories we do a command on. aoqi@0: echo "# Repositories: ${repos} ${repos_extra}" aoqi@0: echo aoqi@0: aoqi@0: # Run the supplied command on all repos in parallel. aoqi@0: n=0 aoqi@0: for i in ${repos} ${repos_extra} ; do aoqi@0: n=`expr ${n} '+' 1` aoqi@0: repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` aoqi@0: reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` aoqi@0: pull_base="${pull_default}" aoqi@0: for j in $repos_extra ; do aoqi@0: if [ "$i" = "$j" ] ; then aoqi@0: pull_base="${pull_extra}" aoqi@0: fi aoqi@0: done aoqi@0: ( aoqi@0: ( aoqi@0: if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then aoqi@1: # 2013.2.27 Jin: fix the repo url for ssh aoqi@1: #pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" aoqi@1: pull_newrepo=${pull_base}/$i aoqi@0: echo hg clone ${pull_newrepo} ${i} aoqi@0: path="`dirname ${i}`" aoqi@0: if [ "${path}" != "." ] ; then aoqi@0: times=0 aoqi@0: while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists aoqi@0: do aoqi@0: times=`expr ${times} '+' 1` aoqi@0: if [ `expr ${times} '%' 10` -eq 0 ] ; then aoqi@0: echo ${path} still not created, waiting... aoqi@0: fi aoqi@0: sleep 5 aoqi@0: done aoqi@0: fi aoqi@1: (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) aoqi@0: else aoqi@0: echo "cd ${i} && hg $*" aoqi@1: cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) aoqi@0: fi aoqi@0: echo $! > ${tmp}/${repopidfile}.pid aoqi@1: ) 2>&1 | sed -e "s@^@${reponame}: @") aoqi@0: aoqi@0: if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then aoqi@0: sleep 2 aoqi@0: echo Waiting 5 secs before spawning next background command. aoqi@0: sleep 3 aoqi@0: fi aoqi@0: done aoqi@0: # Wait for all hg commands to complete aoqi@0: wait aoqi@0: aoqi@0: # Terminate with exit 0 only if all subprocesses were successful aoqi@0: ec=0 aoqi@0: if [ -d ${tmp} ]; then aoqi@0: for rc in ${tmp}/*.pid.rc ; do aoqi@0: exit_code=`cat ${rc} | tr -d ' \n\r'` aoqi@0: if [ "${exit_code}" != "0" ] ; then aoqi@0: echo "WARNING: ${rc} exited abnormally." aoqi@0: ec=1 aoqi@0: fi aoqi@0: done aoqi@0: fi aoqi@0: exit ${ec}