| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Copyright (C) 2010 International Business Machines and others. |
| 4 |
# All Rights Reserved. |
| 5 |
# This file is distributed under the Eclipse Public License. |
| 6 |
# It is part of the BuildTools project in COIN-OR (www.coin-or.org) |
| 7 |
# |
| 8 |
# $Id$ |
| 9 |
# |
| 10 |
# Adapted from commit_new_release by Lou Hafer, SFU, 100507. |
| 11 |
|
| 12 |
#set -x -v |
| 13 |
|
| 14 |
set -e |
| 15 |
|
| 16 |
# Know thy self. If there are no '/' chars in the command name, we're running |
| 17 |
# in the current directory. Otherwise, strip the command name, leaving the |
| 18 |
# prefix. Coin-functions is expected to live in the same directory. As of |
| 19 |
# the original version (100602), this script doesn't need coin-functions, |
| 20 |
# but this still has some value as a consistency check. |
| 21 |
|
| 22 |
if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then |
| 23 |
cmdDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'` |
| 24 |
else |
| 25 |
cmdDir='.' |
| 26 |
fi |
| 27 |
cmdDir=`cd $cmdDir ; pwd` |
| 28 |
if test -r $cmdDir/coin-functions ; then |
| 29 |
. $cmdDir/coin-functions |
| 30 |
else |
| 31 |
echo "Cannot find utility functions file coin-functions; exiting." |
| 32 |
fi |
| 33 |
|
| 34 |
# We need at least one parameter. The default is a dry run (dryRun = 1). |
| 35 |
|
| 36 |
printHelp=0 |
| 37 |
dryRun=1 |
| 38 |
dirToCommit= |
| 39 |
|
| 40 |
if test "$#" -eq 0; then |
| 41 |
printHelp=1 |
| 42 |
else |
| 43 |
|
| 44 |
# Process the parameters. A parameter without an opening `-' is assumed to be |
| 45 |
# the spec for the directory to be committed. (Strip any trailing '/'. Some |
| 46 |
# people add it, but the script doesn't expect it.) |
| 47 |
|
| 48 |
while test $# -gt 0 && test $printHelp = 0 ; do |
| 49 |
case "$1" in |
| 50 |
-h* | --h*) |
| 51 |
printHelp=1 |
| 52 |
;; |
| 53 |
-c* | --c*) |
| 54 |
dryRun=0 |
| 55 |
;; |
| 56 |
-*) echo "$0: unrecognised command line switch '"$1"'." |
| 57 |
printHelp=1 |
| 58 |
;; |
| 59 |
*) dirToCommit=`echo $1 | sed -e 's,/$,,'` |
| 60 |
;; |
| 61 |
esac |
| 62 |
shift |
| 63 |
done |
| 64 |
fi |
| 65 |
|
| 66 |
# What are we committing? |
| 67 |
|
| 68 |
if test -z "$dirToCommit" ; then |
| 69 |
printHelp=1 |
| 70 |
fi |
| 71 |
|
| 72 |
if test $printHelp = 1 ; then |
| 73 |
cat <<EOF |
| 74 |
usage: commit_new_stable [-c] <directory_to_commit> |
| 75 |
|
| 76 |
By default, commit_new_stable is a dry run, printing the commands that |
| 77 |
will be executed. When you're confident that everything looks right, use |
| 78 |
the -c (--commit) flag to commit the new stable branch. |
| 79 |
EOF |
| 80 |
exit 1 |
| 81 |
fi |
| 82 |
|
| 83 |
# Remember what was done during generation of the new stable. |
| 84 |
|
| 85 |
if test -r $dirToCommit/.new_stable_data; then |
| 86 |
. $dirToCommit/.new_stable_data |
| 87 |
else |
| 88 |
echo '' |
| 89 |
echo "Error: the file .new_stable_data is not present in $dirToCommit." |
| 90 |
echo 'Are you running commit_new_stable in the same directory where you' |
| 91 |
echo 'ran prepare_new_stable?' |
| 92 |
echo '' |
| 93 |
exit 1 |
| 94 |
fi |
| 95 |
|
| 96 |
# Confirm that we're in the proper directory. |
| 97 |
|
| 98 |
currDir=`pwd` |
| 99 |
if test "$currDir/$dirToCommit" != "$topBuildDir" ; then |
| 100 |
echo "According to $dirToCommit/.new_stable_data, the stable candidate was assembled" |
| 101 |
echo "in $topBuildDir." |
| 102 |
echo "You have asked to commit $currDir/$dirToCommit." |
| 103 |
echo "There is some confusion. Repository is unchanged." |
| 104 |
exit 1 |
| 105 |
fi |
| 106 |
|
| 107 |
# Change to the checkout directory. |
| 108 |
|
| 109 |
cd $coDir |
| 110 |
|
| 111 |
# If there are externals set on this directory, confirm that |
| 112 |
# .Externals.original is present so that we can restore them later. |
| 113 |
|
| 114 |
newStableExternals=`svn propget svn:externals . || true` |
| 115 |
if test -n "$newStableExternals" ; then |
| 116 |
if test -r .Externals.original ; then |
| 117 |
: |
| 118 |
else |
| 119 |
echo "This project has externals, but no .Externals.original file" |
| 120 |
echo "is present to restore them. Repository is unchanged." |
| 121 |
exit 1 |
| 122 |
fi |
| 123 |
fi |
| 124 |
|
| 125 |
# Make some short-form URLs by stripping the COIN URL base. |
| 126 |
|
| 127 |
srcURLshort=`echo $srcURL | sed -e "s,$coinURL/\(.*\),\1,"` |
| 128 |
newStableURLshort=`echo $newStableURL | sed -e "s,$coinURL/\(.*\),\1,"` |
| 129 |
|
| 130 |
# Do we have to svn add Dependencies? If this query comes up with a leading |
| 131 |
# `?', the answer is yes. If Dependencies is entirely absent or unchanged, |
| 132 |
# we'll get a null string. If it's modified, we'll have a leading `M'. |
| 133 |
|
| 134 |
dependStatus=`svn status Dependencies` |
| 135 |
if expr "$dependStatus" : '?.*Dependencies.*' >/dev/null 2>&1 ; then |
| 136 |
cmd='svn add Dependencies' |
| 137 |
echo $cmd |
| 138 |
if test $dryRun = 0 ; then |
| 139 |
eval $cmd |
| 140 |
fi |
| 141 |
fi |
| 142 |
|
| 143 |
# Now, do we really need to to a temporary commit? BuildTools is the poster |
| 144 |
# child, there are no changes at time of writing (100629). Do an svn status |
| 145 |
# on the checkout directory and see if anything comes up as modified. |
| 146 |
|
| 147 |
if svn status $coDir | egrep '^M' 2>&1 >/dev/null ; then |
| 148 |
doCommit=yes |
| 149 |
else |
| 150 |
doCommit=no |
| 151 |
fi |
| 152 |
|
| 153 |
if test $doCommit = yes ; then |
| 154 |
|
| 155 |
# Commit the stable back to its source URL so we can do a repository-side copy |
| 156 |
# to create the release. |
| 157 |
|
| 158 |
echo '' |
| 159 |
echo "===> Temporarily committing stable candidate to $srcURLshort ..." |
| 160 |
echo '' |
| 161 |
|
| 162 |
rev_num_before=`svn info . | grep -E '^Revision:' | sed -e 's|Revision: ||'` |
| 163 |
echo "Revision number before commit: $rev_num_before" |
| 164 |
|
| 165 |
cmd="svn ci -m \"temporarily committing stable candidate\"" |
| 166 |
echo $cmd |
| 167 |
if test $dryRun = 0 ; then |
| 168 |
eval $cmd |
| 169 |
fi |
| 170 |
|
| 171 |
# Update to confirm the commit. Avoid pulling in externals --- if we're |
| 172 |
# doing multiple commits of new stable branches, they may not exist. As it |
| 173 |
# stands, the main purpose of this call is to allow us to easily obtain the |
| 174 |
# current revision. |
| 175 |
# It might be useful to strengthen this and check that the value |
| 176 |
# is what we're expecting --- one greater than the revision before |
| 177 |
# commit. `--ignore-externals' could be made provisional on the existence |
| 178 |
# of all externals by passing a boolean through .new_release_data. This |
| 179 |
# would strengthen the update, in that the update would confirm existence |
| 180 |
# of the externals. |
| 181 |
|
| 182 |
cmd='svn update --ignore-externals' |
| 183 |
echo $cmd |
| 184 |
if test $dryRun = 0 ; then |
| 185 |
eval $cmd |
| 186 |
fi |
| 187 |
|
| 188 |
rev_num=`svn info . | grep -E '^Revision:' | sed -e 's|Revision: ||'` |
| 189 |
echo "Current revision number is: $rev_num" |
| 190 |
|
| 191 |
fi |
| 192 |
|
| 193 |
# End of preparatory commit. |
| 194 |
|
| 195 |
# Create the new stable branch with a repository-side copy. |
| 196 |
|
| 197 |
echo '' |
| 198 |
echo "===> Creating new stable branch $newStableURLshort from $srcURLshort (r$rev_num) ..." |
| 199 |
echo '' |
| 200 |
|
| 201 |
cmd="svn copy -m \"creating $newStableURLshort from $srcURLshort (r$rev_num).\" $srcURL $newStableURL" |
| 202 |
echo $cmd |
| 203 |
if test $dryRun = 0 ; then |
| 204 |
eval $cmd |
| 205 |
fi |
| 206 |
|
| 207 |
# Now restore the original stable branch. |
| 208 |
|
| 209 |
if test $doCommit = yes ; then |
| 210 |
|
| 211 |
# And restore the source to its original condition. Start by reverting |
| 212 |
# to the original externals. |
| 213 |
|
| 214 |
if test -r .Externals.original ; then |
| 215 |
echo '' |
| 216 |
echo '===> Restoring original externals ...' |
| 217 |
echo '' |
| 218 |
cmd="svn propset -F .Externals.original svn:externals ." |
| 219 |
echo $cmd |
| 220 |
if test $dryRun = 0 ; then |
| 221 |
eval $cmd |
| 222 |
rm .Externals.original |
| 223 |
fi |
| 224 |
fi |
| 225 |
|
| 226 |
# For every .bak file that we created, revert it. |
| 227 |
|
| 228 |
if test -n "$bak_files" ; then |
| 229 |
echo '' |
| 230 |
echo '===> Restoring modified files ...' |
| 231 |
echo '' |
| 232 |
for i in $bak_files; do |
| 233 |
cmd="cp $i.bak $i ; rm $i.bak" |
| 234 |
if test $dryRun = 1 ; then |
| 235 |
echo "$cmd" |
| 236 |
else |
| 237 |
eval $cmd |
| 238 |
fi |
| 239 |
done |
| 240 |
fi |
| 241 |
|
| 242 |
# Rebuild configure and Makefile.in files |
| 243 |
|
| 244 |
echo '' |
| 245 |
echo '===> Executing run_autotools to restore configuration files ...' |
| 246 |
echo '' |
| 247 |
curdir=`pwd` |
| 248 |
cd $topBuildDir |
| 249 |
cmd="./BuildTools/run_autotools" |
| 250 |
echo $cmd |
| 251 |
if test $dryRun = 0 ; then |
| 252 |
eval $cmd |
| 253 |
fi |
| 254 |
cd "$curdir" |
| 255 |
|
| 256 |
# Commit the restored source URL. |
| 257 |
|
| 258 |
echo '' |
| 259 |
echo "===> Committing restored $srcURLshort ..." |
| 260 |
echo '' |
| 261 |
|
| 262 |
cmd="svn ci -m \"restoring $srcURLshort\"" |
| 263 |
echo $cmd |
| 264 |
if test $dryRun = 0 ; then |
| 265 |
eval $cmd |
| 266 |
fi |
| 267 |
|
| 268 |
fi |
| 269 |
|
| 270 |
# End of restorative commit. |
| 271 |
|
| 272 |
cd $topBuildDir |
| 273 |
cmd="rm .new_stable_data" |
| 274 |
echo $cmd |
| 275 |
if test $dryRun = 0 ; then |
| 276 |
eval $cmd |
| 277 |
fi |
| 278 |
|
| 279 |
cd $startDir |
| 280 |
|
| 281 |
echo '' |
| 282 |
echo "Done, new stable $newStableURLshort created." |
| 283 |
echo '' |
| 284 |
echo "You can now delete the directory $topBuildDir including subdirectories" |
| 285 |
|