make/scripts/hgforest.sh
changeset 22585 cb36782f6044
parent 22584 eed64ee05369
parent 22455 b32e2219736e
child 22586 dd49926cdfae
child 22607 ba232b417248
equal deleted inserted replaced
22584:eed64ee05369 22585:cb36782f6044
     1 #!/bin/sh
       
     2 
       
     3 #
       
     4 # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
     5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6 #
       
     7 # This code is free software; you can redistribute it and/or modify it
       
     8 # under the terms of the GNU General Public License version 2 only, as
       
     9 # published by the Free Software Foundation.
       
    10 #
       
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14 # version 2 for more details (a copy is included in the LICENSE file that
       
    15 # accompanied this code).
       
    16 #
       
    17 # You should have received a copy of the GNU General Public License version
       
    18 # 2 along with this work; if not, write to the Free Software Foundation,
       
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20 #
       
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22 # or visit www.oracle.com if you need additional information or have any
       
    23 # questions.
       
    24 #
       
    25 
       
    26 # Shell script for a fast parallel forest command
       
    27 command="$1"
       
    28 pull_extra_base="$2"
       
    29 
       
    30 tmp=/tmp/forest.$$
       
    31 rm -f -r ${tmp}
       
    32 mkdir -p ${tmp}
       
    33 
       
    34 # Remove tmp area on A. B. Normal termination
       
    35 trap 'rm -f -r ${tmp}' KILL
       
    36 trap 'rm -f -r ${tmp}' EXIT
       
    37 
       
    38 # Only look in specific locations for possible forests (avoids long searches)
       
    39 pull_default=""
       
    40 repos=""
       
    41 repos_extra=""
       
    42 if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
       
    43   subrepos="corba jaxp jaxws langtools jdk hotspot nashorn"
       
    44   if [ -f .hg/hgrc ] ; then
       
    45     pull_default=`hg paths default`
       
    46     if [ "${pull_default}" = "" ] ; then
       
    47       echo "ERROR: Need initial clone with 'hg paths default' defined"
       
    48       exit 1
       
    49     fi
       
    50   fi
       
    51   if [ "${pull_default}" = "" ] ; then
       
    52     echo "ERROR: Need initial repository to use this script"
       
    53     exit 1
       
    54   fi
       
    55   for i in ${subrepos} ; do
       
    56     if [ ! -f ${i}/.hg/hgrc ] ; then
       
    57       repos="${repos} ${i}"
       
    58     fi
       
    59   done
       
    60   if [ "${pull_extra_base}" != "" ] ; then
       
    61     subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/make/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs"
       
    62     pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'`
       
    63     pull_extra="${pull_extra_base}/${pull_default_tail}"
       
    64     for i in ${subrepos_extra} ; do
       
    65       if [ ! -f ${i}/.hg/hgrc ] ; then
       
    66         repos_extra="${repos_extra} ${i}"
       
    67       fi
       
    68     done
       
    69   fi
       
    70   at_a_time=2
       
    71   # Any repos to deal with?
       
    72   if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then
       
    73     echo "No repositories to clone."
       
    74     exit
       
    75   fi
       
    76 else
       
    77   hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null`
       
    78   # Derive repository names from the .hg directory locations
       
    79   for i in ${hgdirs} ; do
       
    80     repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`"
       
    81   done
       
    82   at_a_time=8
       
    83   # Any repos to deal with?
       
    84   if [ "${repos}" = "" ] ; then
       
    85     echo "No repositories to process."
       
    86     exit
       
    87   fi
       
    88 fi
       
    89 
       
    90 # Echo out what repositories we will clone
       
    91 echo "# Repos: ${repos} ${repos_extra}"
       
    92 
       
    93 # Run the supplied command on all repos in parallel, save output until end
       
    94 n=0
       
    95 for i in ${repos} ; do
       
    96   echo "Starting on ${i}"
       
    97   n=`expr ${n} '+' 1`
       
    98   (
       
    99     (
       
   100       if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then
       
   101         pull_newrepo="`echo ${pull_default}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
       
   102         cline="hg clone ${pull_newrepo} ${i}"
       
   103         echo "# ${cline}"
       
   104         ( eval "${cline}" )
       
   105       else
       
   106         cline="hg $*"
       
   107         echo "# cd ${i} && ${cline}"
       
   108         ( cd ${i} && eval "${cline}" )
       
   109       fi
       
   110       echo "# exit code $?"
       
   111     ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &
       
   112   if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
       
   113     sleep 5
       
   114   fi
       
   115 done
       
   116 # Wait for all hg commands to complete
       
   117 wait
       
   118 
       
   119 if [ "${repos_extra}" != "" ] ; then
       
   120   for i in ${repos_extra} ; do
       
   121     echo "Starting on ${i}"
       
   122     n=`expr ${n} '+' 1`
       
   123     (
       
   124       (
       
   125           pull_newextrarepo="`echo ${pull_extra}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`"
       
   126           cline="hg clone ${pull_newextrarepo} ${i}"
       
   127           echo "# ${cline}"
       
   128           ( eval "${cline}" )
       
   129         echo "# exit code $?"
       
   130       ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) &
       
   131     if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then
       
   132       sleep 5
       
   133     fi
       
   134   done
       
   135   # Wait for all hg commands to complete
       
   136   wait
       
   137 fi
       
   138 
       
   139 # Cleanup
       
   140 rm -f -r ${tmp}
       
   141 
       
   142 # Terminate with exit 0 all the time (hard to know when to say "failed")
       
   143 exit 0
       
   144