Fri, 29 Apr 2016 00:05:39 +0800
Added MIPS 64-bit port.
aoqi@0 | 1 | #!/bin/sh |
aoqi@0 | 2 | |
aoqi@0 | 3 | # |
aoqi@0 | 4 | # Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 6 | # |
aoqi@0 | 7 | # This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 8 | # under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 9 | # published by the Free Software Foundation. |
aoqi@0 | 10 | # |
aoqi@0 | 11 | # This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | # version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | # accompanied this code). |
aoqi@0 | 16 | # |
aoqi@0 | 17 | # You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | # 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | # |
aoqi@0 | 21 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | # or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | # questions. |
aoqi@0 | 24 | # |
aoqi@0 | 25 | |
aoqi@1 | 26 | # |
aoqi@1 | 27 | # This file has been modified by Loongson Technology in 2013. These |
aoqi@1 | 28 | # modifications are Copyright (c) 2013 Loongson Technology, and are made |
aoqi@1 | 29 | # available on the same license terms set forth above. |
aoqi@1 | 30 | # |
aoqi@1 | 31 | |
aoqi@0 | 32 | # Shell script for a fast parallel forest command |
aoqi@0 | 33 | command="$1" |
aoqi@0 | 34 | pull_extra_base="$2" |
aoqi@0 | 35 | |
aoqi@0 | 36 | if [ "" = "$command" ] ; then |
aoqi@0 | 37 | echo No command to hg supplied! |
aoqi@0 | 38 | exit 1 |
aoqi@0 | 39 | fi |
aoqi@0 | 40 | |
aoqi@0 | 41 | # Clean out the temporary directory that stores the pid files. |
aoqi@0 | 42 | tmp=/tmp/forest.$$ |
aoqi@0 | 43 | rm -f -r ${tmp} |
aoqi@0 | 44 | mkdir -p ${tmp} |
aoqi@0 | 45 | |
aoqi@0 | 46 | safe_interrupt () { |
aoqi@0 | 47 | if [ -d ${tmp} ]; then |
aoqi@0 | 48 | if [ "`ls ${tmp}/*.pid`" != "" ]; then |
aoqi@0 | 49 | echo "Waiting for processes ( `cat ${tmp}/*.pid | tr '\n' ' '`) to terminate nicely!" |
aoqi@0 | 50 | sleep 1 |
aoqi@0 | 51 | # Pipe stderr to dev/null to silence kill, that complains when trying to kill |
aoqi@0 | 52 | # a subprocess that has already exited. |
aoqi@0 | 53 | kill -TERM `cat ${tmp}/*.pid | tr '\n' ' '` 2> /dev/null |
aoqi@0 | 54 | wait |
aoqi@0 | 55 | echo Interrupt complete! |
aoqi@0 | 56 | fi |
aoqi@0 | 57 | fi |
aoqi@0 | 58 | rm -f -r ${tmp} |
aoqi@0 | 59 | exit 1 |
aoqi@0 | 60 | } |
aoqi@0 | 61 | |
aoqi@0 | 62 | nice_exit () { |
aoqi@0 | 63 | if [ -d ${tmp} ]; then |
aoqi@0 | 64 | if [ "`ls ${tmp}`" != "" ]; then |
aoqi@0 | 65 | wait |
aoqi@0 | 66 | fi |
aoqi@0 | 67 | fi |
aoqi@0 | 68 | rm -f -r ${tmp} |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | trap 'safe_interrupt' INT QUIT |
aoqi@0 | 72 | trap 'nice_exit' EXIT |
aoqi@0 | 73 | |
aoqi@0 | 74 | # Only look in specific locations for possible forests (avoids long searches) |
aoqi@0 | 75 | pull_default="" |
aoqi@0 | 76 | repos="" |
aoqi@0 | 77 | repos_extra="" |
aoqi@0 | 78 | if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
aoqi@0 | 79 | subrepos="corba jaxp jaxws langtools jdk hotspot nashorn" |
aoqi@0 | 80 | if [ -f .hg/hgrc ] ; then |
aoqi@0 | 81 | pull_default=`hg paths default` |
aoqi@0 | 82 | if [ "${pull_default}" = "" ] ; then |
aoqi@0 | 83 | echo "ERROR: Need initial clone with 'hg paths default' defined" |
aoqi@0 | 84 | exit 1 |
aoqi@0 | 85 | fi |
aoqi@0 | 86 | fi |
aoqi@0 | 87 | if [ "${pull_default}" = "" ] ; then |
aoqi@0 | 88 | echo "ERROR: Need initial repository to use this script" |
aoqi@0 | 89 | exit 1 |
aoqi@0 | 90 | fi |
aoqi@0 | 91 | for i in ${subrepos} ; do |
aoqi@0 | 92 | if [ ! -f ${i}/.hg/hgrc ] ; then |
aoqi@0 | 93 | repos="${repos} ${i}" |
aoqi@0 | 94 | fi |
aoqi@0 | 95 | done |
aoqi@0 | 96 | if [ "${pull_extra_base}" != "" ] ; then |
aoqi@0 | 97 | 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 | 98 | pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` |
aoqi@0 | 99 | pull_extra="${pull_extra_base}/${pull_default_tail}" |
aoqi@0 | 100 | for i in ${subrepos_extra} ; do |
aoqi@0 | 101 | if [ ! -f ${i}/.hg/hgrc ] ; then |
aoqi@0 | 102 | repos_extra="${repos_extra} ${i}" |
aoqi@0 | 103 | fi |
aoqi@0 | 104 | done |
aoqi@0 | 105 | fi |
aoqi@0 | 106 | at_a_time=2 |
aoqi@0 | 107 | # Any repos to deal with? |
aoqi@0 | 108 | if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then |
aoqi@0 | 109 | exit |
aoqi@0 | 110 | fi |
aoqi@0 | 111 | else |
aoqi@0 | 112 | hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` |
aoqi@0 | 113 | # Derive repository names from the .hg directory locations |
aoqi@0 | 114 | for i in ${hgdirs} ; do |
aoqi@0 | 115 | repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" |
aoqi@0 | 116 | done |
aoqi@0 | 117 | for i in ${repos} ; do |
aoqi@0 | 118 | if [ -h ${i}/.hg/store/lock -o -f ${i}/.hg/store/lock ] ; then |
aoqi@0 | 119 | locked="${i} ${locked}" |
aoqi@0 | 120 | fi |
aoqi@0 | 121 | done |
aoqi@0 | 122 | at_a_time=8 |
aoqi@0 | 123 | # Any repos to deal with? |
aoqi@0 | 124 | if [ "${repos}" = "" ] ; then |
aoqi@0 | 125 | echo "No repositories to process." |
aoqi@0 | 126 | exit |
aoqi@0 | 127 | fi |
aoqi@0 | 128 | if [ "${locked}" != "" ] ; then |
aoqi@0 | 129 | echo "These repositories are locked: ${locked}" |
aoqi@0 | 130 | exit |
aoqi@0 | 131 | fi |
aoqi@0 | 132 | fi |
aoqi@0 | 133 | |
aoqi@0 | 134 | # Echo out what repositories we do a command on. |
aoqi@0 | 135 | echo "# Repositories: ${repos} ${repos_extra}" |
aoqi@0 | 136 | echo |
aoqi@0 | 137 | |
aoqi@0 | 138 | # Run the supplied command on all repos in parallel. |
aoqi@0 | 139 | n=0 |
aoqi@0 | 140 | for i in ${repos} ${repos_extra} ; do |
aoqi@0 | 141 | n=`expr ${n} '+' 1` |
aoqi@0 | 142 | repopidfile=`echo ${i} | sed -e 's@./@@' -e 's@/@_@g'` |
aoqi@0 | 143 | reponame=`echo ${i} | sed -e :a -e 's/^.\{1,20\}$/ &/;ta'` |
aoqi@0 | 144 | pull_base="${pull_default}" |
aoqi@0 | 145 | for j in $repos_extra ; do |
aoqi@0 | 146 | if [ "$i" = "$j" ] ; then |
aoqi@0 | 147 | pull_base="${pull_extra}" |
aoqi@0 | 148 | fi |
aoqi@0 | 149 | done |
aoqi@0 | 150 | ( |
aoqi@0 | 151 | ( |
aoqi@0 | 152 | if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then |
aoqi@1 | 153 | # 2013.2.27 Jin: fix the repo url for ssh |
aoqi@1 | 154 | #pull_newrepo="`echo ${pull_base}/${i} | sed -e 's@\([^:]/\)//*@\1@g'`" |
aoqi@1 | 155 | pull_newrepo=${pull_base}/$i |
aoqi@0 | 156 | echo hg clone ${pull_newrepo} ${i} |
aoqi@0 | 157 | path="`dirname ${i}`" |
aoqi@0 | 158 | if [ "${path}" != "." ] ; then |
aoqi@0 | 159 | times=0 |
aoqi@0 | 160 | while [ ! -d "${path}" ] ## nested repo, ensure containing dir exists |
aoqi@0 | 161 | do |
aoqi@0 | 162 | times=`expr ${times} '+' 1` |
aoqi@0 | 163 | if [ `expr ${times} '%' 10` -eq 0 ] ; then |
aoqi@0 | 164 | echo ${path} still not created, waiting... |
aoqi@0 | 165 | fi |
aoqi@0 | 166 | sleep 5 |
aoqi@0 | 167 | done |
aoqi@0 | 168 | fi |
aoqi@1 | 169 | (PYTHONUNBUFFERED=true hg clone ${pull_newrepo} ${i}; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) |
aoqi@0 | 170 | else |
aoqi@0 | 171 | echo "cd ${i} && hg $*" |
aoqi@1 | 172 | cd ${i} && (PYTHONUNBUFFERED=true hg "$@"; echo "$?" > ${tmp}/${repopidfile}.pid.rc ) |
aoqi@0 | 173 | fi |
aoqi@0 | 174 | echo $! > ${tmp}/${repopidfile}.pid |
aoqi@1 | 175 | ) 2>&1 | sed -e "s@^@${reponame}: @") |
aoqi@0 | 176 | |
aoqi@0 | 177 | if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then |
aoqi@0 | 178 | sleep 2 |
aoqi@0 | 179 | echo Waiting 5 secs before spawning next background command. |
aoqi@0 | 180 | sleep 3 |
aoqi@0 | 181 | fi |
aoqi@0 | 182 | done |
aoqi@0 | 183 | # Wait for all hg commands to complete |
aoqi@0 | 184 | wait |
aoqi@0 | 185 | |
aoqi@0 | 186 | # Terminate with exit 0 only if all subprocesses were successful |
aoqi@0 | 187 | ec=0 |
aoqi@0 | 188 | if [ -d ${tmp} ]; then |
aoqi@0 | 189 | for rc in ${tmp}/*.pid.rc ; do |
aoqi@0 | 190 | exit_code=`cat ${rc} | tr -d ' \n\r'` |
aoqi@0 | 191 | if [ "${exit_code}" != "0" ] ; then |
aoqi@0 | 192 | echo "WARNING: ${rc} exited abnormally." |
aoqi@0 | 193 | ec=1 |
aoqi@0 | 194 | fi |
aoqi@0 | 195 | done |
aoqi@0 | 196 | fi |
aoqi@0 | 197 | exit ${ec} |