make/scripts/hgforest.sh
author jeff
Wed, 22 Jun 2011 10:11:19 -0700
changeset 9904 b3319c87fd74
parent 7650 6a3a53d8eacc
child 12582 46d24df71c5d
permissions -rw-r--r--
7057046: Add embedded license to THIRD PARTY README Reviewed-by: lana
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7650
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     1
#!/bin/sh
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     2
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     3
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     4
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     6
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
     9
# published by the Free Software Foundation.
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    10
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    15
# accompanied this code).
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    16
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    20
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    23
# questions.
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    24
#
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    25
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    26
# Shell script for a fast parallel forest command
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    27
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    28
tmp=/tmp/forest.$$
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    29
rm -f -r ${tmp}
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    30
mkdir -p ${tmp}
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    31
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    32
# Remove tmp area on A. B. Normal termination
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    33
trap 'rm -f -r ${tmp}' KILL
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    34
trap 'rm -f -r ${tmp}' EXIT
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    35
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    36
# Only look in specific locations for possible forests (avoids long searches)
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    37
pull_default=""
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    38
if [ "$1" = "clone" -o "$1" = "fclone" ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    39
  subrepos="corba jaxp jaxws langtools jdk hotspot"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    40
  if [ -f .hg/hgrc ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    41
    pull_default=`hg paths default`
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    42
  fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    43
  if [ "${pull_default}" = "" ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    44
    echo "ERROR: Need initial clone with 'hg paths default' defined"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    45
    exit 1
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    46
  fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    47
  repos=""
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    48
  for i in ${subrepos} ; do
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    49
    if [ ! -f ${i}/.hg/hgrc ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    50
      repos="${repos} ${i}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    51
    fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    52
  done
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    53
  at_a_time=2
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    54
else
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    55
  hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    56
  # Derive repository names from the .hg directory locations
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    57
  repos=""
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    58
  for i in ${hgdirs} ; do
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    59
    repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    60
  done
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    61
  at_a_time=8
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    62
fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    63
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    64
# Any repos to deal with?
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    65
if [ "${repos}" = "" ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    66
  echo "No repositories to process."
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    67
  exit
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    68
fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    69
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    70
# Echo out what repositories we will process
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    71
echo "# Repos: ${repos}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    72
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    73
# Run the supplied command on all repos in parallel, save output until end
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    74
n=0
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    75
for i in ${repos} ; do
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    76
  echo "Starting on ${i}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    77
  n=`expr ${n} '+' 1`
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    78
  (
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    79
    (
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    80
      if [ "$1" = "clone" -o "$1" = "fclone" ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    81
        cline="hg $* ${pull_default}/${i} ${i}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    82
        echo "# ${cline}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    83
        ( eval "${cline}" )
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    84
      else
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    85
        cline="hg $*"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    86
        echo "# cd ${i} && ${cline}"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    87
        ( cd ${i} && eval "${cline}" )
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    88
      fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    89
      echo "# exit code $?"
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    90
    ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    91
  if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    92
    sleep 5
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    93
  fi
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    94
done
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    95
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    96
# Wait for all hg commands to complete
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    97
wait
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    98
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
    99
# Cleanup
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
   100
rm -f -r ${tmp}
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
   101
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
   102
# Terminate with exit 0 all the time (hard to know when to say "failed")
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
   103
exit 0
6a3a53d8eacc 7003845: README-builds document proper location of forest extension, provide alternatives
ohair
parents:
diff changeset
   104