2014-03-26 23:56:58 +00:00
|
|
|
#!/bin/sh
|
2012-12-18 08:57:01 +00:00
|
|
|
|
|
|
|
#
|
2014-02-10 20:53:40 +00:00
|
|
|
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
|
2012-12-18 08:57:01 +00:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Shell script for a fast parallel forest command
|
|
|
|
|
2014-03-24 22:40:29 +00:00
|
|
|
global_opts=""
|
|
|
|
status_output="/dev/stdout"
|
|
|
|
qflag="false"
|
|
|
|
vflag="false"
|
2014-04-11 08:35:03 +00:00
|
|
|
sflag="false"
|
2014-03-24 22:40:29 +00:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-q | --quiet )
|
|
|
|
qflag="true"
|
|
|
|
global_opts="${global_opts} -q"
|
|
|
|
status_output="/dev/null"
|
|
|
|
;;
|
|
|
|
|
|
|
|
-v | --verbose )
|
|
|
|
vflag="true"
|
|
|
|
global_opts="${global_opts} -v"
|
|
|
|
;;
|
|
|
|
|
2014-04-11 08:35:03 +00:00
|
|
|
-s | --sequential )
|
|
|
|
sflag="true"
|
|
|
|
;;
|
|
|
|
|
2014-03-24 22:40:29 +00:00
|
|
|
'--' ) # no more options
|
|
|
|
shift; break
|
|
|
|
;;
|
|
|
|
|
|
|
|
-*) # bad option
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
|
|
|
|
* ) # non option
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
command="$1"; shift
|
2014-03-26 23:56:58 +00:00
|
|
|
command_args="$@"
|
2014-03-24 22:40:29 +00:00
|
|
|
|
|
|
|
usage() {
|
2014-04-11 08:35:03 +00:00
|
|
|
echo "usage: $0 [-q|--quiet] [-v|--verbose] [-s|--sequential] [--] <command> [commands...]" > ${status_output}
|
2014-03-24 22:40:29 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ "x" = "x$command" ] ; then
|
|
|
|
echo "ERROR: No command to hg supplied!"
|
|
|
|
usage
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean out the temporary directory that stores the pid files.
|
|
|
|
tmp=/tmp/forest.$$
|
|
|
|
rm -f -r ${tmp}
|
|
|
|
mkdir -p ${tmp}
|
|
|
|
|
|
|
|
safe_interrupt () {
|
2013-02-06 11:36:19 +00:00
|
|
|
if [ -d ${tmp} ]; then
|
|
|
|
if [ "`ls ${tmp}/*.pid`" != "" ]; then
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" > ${status_output}
|
2012-12-18 08:57:01 +00:00
|
|
|
sleep 1
|
|
|
|
# Pipe stderr to dev/null to silence kill, that complains when trying to kill
|
|
|
|
# a subprocess that has already exited.
|
2013-02-06 11:36:19 +00:00
|
|
|
kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null
|
|
|
|
wait
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "Interrupt complete!" > ${status_output}
|
2013-02-06 11:36:19 +00:00
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
rm -f -r ${tmp}
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
exit 130
|
2012-12-18 08:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nice_exit () {
|
2013-02-06 11:36:19 +00:00
|
|
|
if [ -d ${tmp} ]; then
|
|
|
|
if [ "`ls ${tmp}`" != "" ]; then
|
|
|
|
wait
|
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
rm -f -r ${tmp}
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap 'safe_interrupt' INT QUIT
|
|
|
|
trap 'nice_exit' EXIT
|
2013-02-06 11:36:19 +00:00
|
|
|
|
2014-03-24 22:40:29 +00:00
|
|
|
subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
|
|
|
|
subrepos_extra="closed jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
|
|
|
|
|
2012-12-18 08:57:01 +00:00
|
|
|
# Only look in specific locations for possible forests (avoids long searches)
|
|
|
|
pull_default=""
|
|
|
|
repos=""
|
|
|
|
repos_extra=""
|
2014-03-26 23:56:58 +00:00
|
|
|
if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
|
|
|
|
if [ ! -f .hg/hgrc ] ; then
|
|
|
|
echo "ERROR: Need initial repository to use this script" > ${status_output}
|
|
|
|
exit 1
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
2014-03-26 23:56:58 +00:00
|
|
|
|
|
|
|
pull_default=`hg paths default`
|
2012-12-18 08:57:01 +00:00
|
|
|
if [ "${pull_default}" = "" ] ; then
|
2014-03-26 23:56:58 +00:00
|
|
|
echo "ERROR: Need initial clone with 'hg paths default' defined" > ${status_output}
|
2012-12-18 08:57:01 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2014-03-26 23:56:58 +00:00
|
|
|
|
2012-12-18 08:57:01 +00:00
|
|
|
for i in ${subrepos} ; do
|
|
|
|
if [ ! -f ${i}/.hg/hgrc ] ; then
|
|
|
|
repos="${repos} ${i}"
|
|
|
|
fi
|
|
|
|
done
|
2014-03-26 23:56:58 +00:00
|
|
|
if [ "${command_args}" != "" ] ; then
|
2012-12-18 08:57:01 +00:00
|
|
|
pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
|
2014-03-26 23:56:58 +00:00
|
|
|
if [ "x${pull_default}" = "x${pull_default_tail}" ] ; then
|
|
|
|
echo "ERROR: Need initial clone from non-local source" > ${status_output}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
pull_extra="${command_args}/${pull_default_tail}"
|
2012-12-18 08:57:01 +00:00
|
|
|
for i in ${subrepos_extra} ; do
|
|
|
|
if [ ! -f ${i}/.hg/hgrc ] ; then
|
|
|
|
repos_extra="${repos_extra} ${i}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
at_a_time=2
|
|
|
|
# Any repos to deal with?
|
|
|
|
if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "No repositories to process." > ${status_output}
|
2012-12-18 08:57:01 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
2014-03-24 22:40:29 +00:00
|
|
|
for i in . ${subrepos} ${subrepos_extra} ; do
|
|
|
|
if [ -d ${i}/.hg ] ; then
|
|
|
|
repos="${repos} ${i}"
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-03-24 22:40:29 +00:00
|
|
|
|
2012-12-18 08:57:01 +00:00
|
|
|
# Any repos to deal with?
|
|
|
|
if [ "${repos}" = "" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "No repositories to process." > ${status_output}
|
2012-12-18 08:57:01 +00:00
|
|
|
exit
|
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
|
|
|
|
# any of the repos locked?
|
|
|
|
for i in ${repos} ; do
|
|
|
|
if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then
|
|
|
|
locked="${i} ${locked}"
|
|
|
|
fi
|
|
|
|
done
|
2012-12-18 08:57:01 +00:00
|
|
|
if [ "${locked}" != "" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "ERROR: These repositories are locked: ${locked}" > ${status_output}
|
|
|
|
exit 1
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
at_a_time=8
|
2012-12-18 08:57:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Echo out what repositories we do a command on.
|
2014-03-24 22:40:29 +00:00
|
|
|
echo "# Repositories: ${repos} ${repos_extra}" > ${status_output}
|
|
|
|
|
|
|
|
if [ "${command}" = "serve" ] ; then
|
|
|
|
# "serve" is run for all the repos.
|
|
|
|
(
|
|
|
|
(
|
|
|
|
(
|
|
|
|
echo "[web]"
|
|
|
|
echo "description = $(basename $(pwd))"
|
|
|
|
echo "allow_push = *"
|
|
|
|
echo "push_ssl = False"
|
|
|
|
|
|
|
|
echo "[paths]"
|
|
|
|
for i in ${repos} ${repos_extra} ; do
|
|
|
|
if [ "${i}" != "." ] ; then
|
|
|
|
echo "/$(basename $(pwd))/${i} = ${i}"
|
|
|
|
else
|
|
|
|
echo "/$(basename $(pwd)) = $(pwd)"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
) > ${tmp}/serve.web-conf
|
|
|
|
|
|
|
|
echo "serving root repo $(basename $(pwd))"
|
|
|
|
|
|
|
|
(PYTHONUNBUFFERED=true hg${global_opts} serve -A ${status_output} -E ${status_output} --pid-file ${tmp}/serve.pid --web-conf ${tmp}/serve.web-conf; echo "$?" > ${tmp}/serve.pid.rc ) 2>&1 &
|
|
|
|
) 2>&1 | sed -e "s@^@serve: @" > ${status_output}
|
|
|
|
) &
|
|
|
|
else
|
|
|
|
# Run the supplied command on all repos in parallel.
|
|
|
|
n=0
|
|
|
|
for i in ${repos} ${repos_extra} ; do
|
|
|
|
n=`expr ${n} '+' 1`
|
|
|
|
repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'`
|
|
|
|
reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'`
|
|
|
|
pull_base="${pull_default}"
|
|
|
|
for j in $repos_extra ; do
|
2012-12-18 08:57:01 +00:00
|
|
|
if [ "$i" = "$j" ] ; then
|
|
|
|
pull_base="${pull_extra}"
|
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
done
|
2012-12-18 08:57:01 +00:00
|
|
|
(
|
2014-03-24 22:40:29 +00:00
|
|
|
(
|
2014-03-26 23:56:58 +00:00
|
|
|
if [ "${command}" = "clone" -o "${command}" = "fclone" -o "${command}" = "tclone" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
|
|
|
|
path="`dirname ${i}`"
|
|
|
|
if [ "${path}" != "." ] ; then
|
|
|
|
times=0
|
|
|
|
while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists
|
|
|
|
do
|
|
|
|
times=`expr ${times} '+' 1`
|
|
|
|
if [ `expr ${times} '%' 10` -eq 0 ] ; then
|
|
|
|
echo "${path} still not created, waiting..." > ${status_output}
|
|
|
|
fi
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
fi
|
2014-03-26 23:56:58 +00:00
|
|
|
echo "hg clone ${pull_newrepo} ${i}" > ${status_output}
|
2014-03-24 22:40:29 +00:00
|
|
|
(PYTHONUNBUFFERED=true hg${global_opts} clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
|
|
|
|
else
|
2014-03-26 23:56:58 +00:00
|
|
|
echo "cd ${i} && hg${global_opts} ${command} ${command_args}" > ${status_output}
|
|
|
|
cd ${i} && (PYTHONUNBUFFERED=true hg${global_opts} ${command} ${command_args}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) 2>&1 &
|
2013-02-06 11:36:19 +00:00
|
|
|
fi
|
|
|
|
|
2014-03-24 22:40:29 +00:00
|
|
|
echo $! > ${tmp}/${repopidfile}.pid
|
|
|
|
) 2>&1 | sed -e "s@^@${reponame}: @" > ${status_output}
|
|
|
|
) &
|
|
|
|
|
2014-04-11 08:35:03 +00:00
|
|
|
if [ `expr ${n} '%' ${at_a_time}` -eq 0 -a "${sflag}" = "false" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
sleep 2
|
|
|
|
echo "Waiting 5 secs before spawning next background command." > ${status_output}
|
|
|
|
sleep 3
|
|
|
|
fi
|
2014-04-11 08:35:03 +00:00
|
|
|
|
|
|
|
if [ "${sflag}" = "true" ] ; then
|
|
|
|
wait
|
|
|
|
fi
|
2014-03-24 22:40:29 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2012-12-18 08:57:01 +00:00
|
|
|
# Wait for all hg commands to complete
|
|
|
|
wait
|
|
|
|
|
2013-02-06 11:36:19 +00:00
|
|
|
# Terminate with exit 0 only if all subprocesses were successful
|
|
|
|
ec=0
|
|
|
|
if [ -d ${tmp} ]; then
|
|
|
|
for rc in ${tmp}/*.pid.rc ; do
|
|
|
|
exit_code=`cat ${rc} | tr -d ' \n\r'`
|
|
|
|
if [ "${exit_code}" != "0" ] ; then
|
2014-03-24 22:40:29 +00:00
|
|
|
repo="`echo ${rc} | sed -e s@^${tmp}@@ -e 's@/*\([^/]*\)\.pid\.rc$@\1@' -e 's@_@/@g'`"
|
|
|
|
echo "WARNING: ${repo} exited abnormally." > ${status_output}
|
2013-02-06 11:36:19 +00:00
|
|
|
ec=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
exit ${ec}
|