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