source: trunk/prepare_new_stable @ 1556

Last change on this file since 1556 was 1556, checked in by lou, 11 years ago

New scripts for generating stable versions. Significantly different
architecture; see the BuildTools? posting 100602. set_externals is modified to
conform to the new architecture. Be careful!

  • Property svn:executable set to *
File size: 19.2 KB
Line 
1#!/bin/sh
2
3# Copyright (C) 2007  International Business Machines.
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 prepare_new_release by Lou Hafer, SFU, 100507.
11
12#set -x -v
13set -e
14
15# Know thy self. If there are no '/' chars in the command name, we're running
16# in the currrent directory. Otherwise, strip the command name, leaving the
17# prefix.  Coin-functions is expected to live in the same directory.
18
19if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then
20  cmdDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'`
21else
22  cmdDir='.'
23fi
24if test -r $cmdDir/coin-functions ; then
25  . $cmdDir/coin-functions
26else
27  echo "Cannot find utility functions file coin-functions; exiting."
28fi
29
30#################### end of function definitions ##########################
31
32
33# Note that plain sh does not accept negative exit values
34
35exitValue=0
36
37# Specify the COIN URL base for convenience.
38
39coinURL="https://projects.coin-or.org/svn"
40
41# Begin parameter processing.
42
43printHelp=0
44ignoreBuildToolsMismatch=0
45bumpMajor=0
46suppressCheckout=0
47
48# srcURL will be the parent for the stable we are building. We'll need to be
49# able to distinguish ThirdParty and Data builds, and BuildTools itself; they
50# require special handling.  cmdBTURL points to a BuildTools source and is
51# required when srcURL specifies a ThirdParty or Data project --- we'll need to
52# assemble a temporary package while creating the stable candidate.
53
54srcURL=
55isThirdParty=no
56isData=no
57isBuildTools=no
58cmdBTURL=
59
60# trunkExternals specifies externals for which we want to do simultaneous
61# creation of stable branches. We will use the trunk as the external while
62# preparing and testing the stable candidate, changing the Dependencies file
63# to specify a (nonexistent) stable branch of the external at the last moment.
64
65trunkExternals=
66
67# exciseExternals specifies externals that should be removed when creating the
68# new stable branch.
69
70exciseExternals=
71
72# We need at least one parameter.
73
74if test "$#" -eq 0; then
75  printHelp=1
76else
77
78# Process the parameters. A parameter without an opening `-' is assumed to be
79# the spec for the source branch.
80
81  while test $# -gt 0 && test $exitValue = 0 && test $printHelp = 0 ; do
82    case "$1" in
83      -h* | --h*) printHelp=1 ;;
84      -i* | --i*) ignoreBuildToolsMismatch=1 ;;
85      -m* | --m*) bumpMajor=1 ;;
86      -p* | --p*) suppressCheckout=1 ;;
87      -t* | --t*)
88           if expr "$1" : '.*-t.*=.*' 2>&1 >/dev/null ; then
89             trunkExternals=`echo $1 | sed -n -e 's/[^=]*=\(.*\)/\1/p'`
90           else
91             shift
92             trunkExternals=$1
93           fi
94           ;;
95      -x* | --x*)
96           if expr "$1" : '.*-x.*=.*' 2>&1 >/dev/null ; then
97             exciseExternals=`echo $1 | sed -n -e 's/[^=]*=\(.*\)/\1/p'`
98           else
99             shift
100             exciseExternals=$1
101           fi
102           ;;
103      -b* | --b*)
104           if expr "$1" : '.*-b.*=.*' 2>&1 >/dev/null ; then
105             cmdBTURL=`echo $1 | sed -n -e 's/[^=]*=\(.*\)/\1/p'`
106           else
107             shift
108             cmdBTURL=$1
109           fi
110           if expr "$cmdBTURL" : '.*BuildTools.*' 2>&1 >/dev/null ; then
111             case $cmdBTURL in
112               http*) ;;
113                   *) cmdBTURL=${coinURL}/$cmdBTURL
114                      ;;
115             esac
116           else
117             echo ''
118             echo "URL $cmdBTURL does not point to BuildTools."
119             echo ''
120             printHelp=1
121             exitValue=3
122            fi
123           ;;
124      -*)  echo "$0: unrecognised command line switch '"$1"'."
125           printHelp=1
126           exitValue=1
127           ;;
128       *)  srcURL=$1
129           case $srcURL in
130             http* ) ;;
131             BuildTools/ThirdParty/* )
132                 srcURL=${coinURL}/$srcURL
133                 ;;
134             ThirdParty/* )
135                 srcURL=${coinURL}/BuildTools/$srcURL
136                 ;;
137             * ) srcURL=${coinURL}/$srcURL
138                    ;;
139           esac
140           ;;
141    esac
142    shift
143  done
144
145# Consistency check: Make sure that the source URL exists.  Note that it's not
146# possible to specify a Data URL without including trunk/stable/release in the
147# URL. For others, helpfully append `trunk'.
148
149  srcURL=`echo $srcURL | sed -e 's/\/$//'`
150  urlType=`extractTypeFromURL "$srcURL"`
151  if test $printHelp = 0 && test $exitValue = 0 ; then
152    if svn list $srcURL 2>&1 >/dev/null ; then
153      :
154    else
155      echo "Source URL $srcURL does not seem to exist."
156      printHelp=1
157      exitValue=5
158    fi
159    if test "$urlType" = invalid ; then
160      srcURL=$srcURL/trunk
161      urlType=trunk
162    fi
163  fi
164
165# Just what are we building? Order is important; BuildTools without ThirdParty
166# means we're actually doing a BuildTools stable.
167
168  if test $printHelp = 0 && test $exitValue = 0 ; then
169    case $srcURL in
170      *ThirdParty* )
171        isThirdParty=yes
172        ;;
173      *BuildTools* )
174        isBuildTools=yes
175        ;;
176      *Data* )
177        isData=yes
178        ;;
179      *)
180        ;;
181    esac
182
183# If we're building a ThirdParty or Data release, we need a BuildTools URL.
184
185    if test $isThirdParty = yes || test $isData = yes ; then
186      if test -z "$cmdBTURL" ; then
187        cmdBTURL=`bestRelease $coinURL/BuildTools -1 -1`
188        echo "A BuildTools URL is required for Data or ThirdParty projects."
189        echo "Using $cmdBTURL; override with -b"
190      else
191        if svn list $cmdBTURL 2>&1 >/dev/null ; then
192          :
193        else
194          echo "BuildTools URL $cmdBTURL does not seem to exist."
195          printHelp=1
196          exitValue=6
197        fi
198      fi
199    fi
200  fi
201fi  # if "$#" .eq 0
202
203if test $printHelp = 1 ; then
204  cat <<EOF
205Usage: prepare_new_stable [options] <source URL>
206
207This script will create a new stable branch from the head of the specified
208URL. Typically this will be the trunk, but it can be an existing stable
209branch.  You can specify the entire URL, or just enter what comes after
210"https://projects.coin-or.org/svn".  A typical example is
211
212  prepare_new_stable Ipopt/trunk
213
214Options:
215  -b <BuildToolsURL>    URL for BuildTools; required to generate a release
216                        for a ThirdParty or Data project.
217  -i                    Ignore BuildTools version mismatches in externals.
218  -p                    Suppress checkout (useful for testing)
219  -m                    Bump the major version number.
220  -t <project-list>     Suppress conversion from trunk to stable for the
221                        listed externals (comma-separated list of project
222                        names, e.g., -t Osi,Cbc).
223  -x <project-list>     Remove the listed projects from the list of externals
224                        (comma-separated list of project names).
225
226This script will do the following:
227
228  - Set the new stable version number as the next minor version number in
229    the current major version number. Use the -m flag to bump the major
230    version number.
231
232  - Convert externals from trunk to the top stable branch. Externals which
233    are currently stable or release are left untouched. Use -t to suppress
234    the change from trunk to stable. Set_externals is then invoked to set
235    release externals where available.
236
237  - Check out externals. The BuildTools version used by externals (if any)
238    is checked, and the script issues a warning if it doesn't match the
239    version used by the source URL.
240
241  - Run the scripts to download any ThirdParty code.
242
243  - Run run_autotools to rebuild configure and make files.
244
245  - Run configure, make, and make test
246
247  - Tweak the externals to upgrade trunk (-t) dependencies to stable (you
248    won't get to release in this case).
249
250If there is any error during these tasks the script will stop and you should
251examine the output.
252
253If the script completes without error, examine the output, particularly the
254output of the unit test ('make test') and the set of externals specified in
255the Dependencies file. Whether you start with Externals or Dependencies, the
256stable will have a proper Dependencies. Externals will be unmodified.
257
258This script does not make any changes to the repository.  If you want to
259commit the new stable branch, run the "commit_new_stable" script, as described
260at the end of the output.
261
262EOF
263fi
264
265if test $exitValue != 0 || test $printHelp = 1 ; then
266  exit $exitValue
267fi
268
269# End of parameter parsing. We have a source URL to work with.  Tell the
270# user what we've seen.
271
272srcURL=`echo $srcURL | sed -e 's|/$||'`
273srcProj=`extractProjFromURL $srcURL`
274
275echo "Source URL..........: $srcURL"
276echo "Base project........: $srcProj"
277if test $isThirdParty = yes || test $isData = yes ; then
278  echo "BuildTools URL......: $cmdBTURL"
279fi
280
281# Figure out the URL of the new stable branch. Consider that there may not be
282# any existing stable branches.
283
284topStableURL=`bestStable $srcURL -1`
285echo "Top stable URL......: ${topStableURL:-none}"
286
287if test -z "$topStableURL" ; then
288  majVer=0
289  minVer=1
290  case "$srcURL" in
291    */Data/* )
292        newStableURL=$coinURL/Data/stable/$majVer.$minVer/$srcProj
293        ;;
294    */ThirdParty/* )
295        newStableURL=$coinURL/BuildTools/ThirdParty/$srcProj/stable/$majVer.$minVer
296        ;;
297    * )
298        newStableURL=$coinURL/$srcProj/stable/$majVer.$minVer
299        ;;
300  esac
301else
302  majVer=`extractMajorFromURL $topStableURL`
303  if test $bumpMajor = 1 ; then
304    majVer=`expr $majVer + 1`
305    minVer=0
306  else
307    minVer=`extractMinorFromURL $topStableURL`
308    minVer=`expr $minVer + 1`
309  fi
310  newStableURL=`replaceVersionInURL $topStableURL $majVer $minVer`
311fi
312echo "New stable URL......: $newStableURL"
313newVersion=${majVer}.${minVer}
314
315# Construct a build directory name.
316
317topBuildDir=${srcProj}-${newVersion}
318echo "Build directory.....: $topBuildDir"
319
320# Now decide where to check out code.
321
322if test $isThirdParty = yes; then
323  coDir=$topBuildDir/Thirdparty/$srcProj
324elif test $isData = yes; then
325  coDir=$topBuildDir/Data/$srcProj
326else
327  coDir=$topBuildDir
328fi
329echo "Checkout directory..: $coDir"
330
331echo ''
332echo "===> Checking out source $srcURL without externals ..."
333echo ''
334
335cmd="svn co --ignore-externals $srcURL $coDir"
336if test $suppressCheckout = 1 ; then
337  echo "Pretending to do: $cmd"
338else
339  rm -rf $topBuildDir
340  echo $cmd
341  eval $cmd
342fi
343
344if test $isThirdParty = yes || test $isData = yes; then
345  echo ''
346  echo '===> Checking out BuildTools (Data or ThirdParty) ...'
347  echo ''
348  cmd="svn co $cmdBTURL $topBuildDir/BuildTools"
349  if test $suppressCheckout = 1 ; then
350    echo "Pretending to do: $cmd"
351  else
352    echo $cmd
353    eval $cmd
354  fi
355fi
356
357startDir=`pwd`
358coDir=`cd $coDir; pwd`
359topBuildDir=`cd $topBuildDir; pwd`
360
361cd $coDir
362
363# Find configure.ac files for the package and project and update the version.
364# We have no externals at this point, so there will be two files for a
365# standard project, one for a ThirdParty or Data project.
366
367echo ''
368bak_files=`find . -name 'configure.ac' | grep -v -E 'ThirdParty/.*/.*/configure.ac'`
369echo "===> Creating backup (.bak) for configure.ac files..."
370for i in $bak_files; do
371  cp $i $i.bak
372done
373
374echo ''
375echo "===> Updating version number in configure.ac files"
376for i in $bak_files; do
377  sed -e "s|AC_INIT\(.*\),\[[^]]*\],\(.*\)|AC_INIT\1,[$newVersion],\2|" $i > bla
378  mv bla $i
379  svn diff $i
380done
381
382# Find ProjConfig.h. If there's a definition for PROJ_VERSION, adjust it and
383# add ProjConfig.h.bak to the list of files to be restored.
384
385srcProjUC=`echo $srcProj | tr '[a-z]' '[A-Z]'`
386configFileLoc=`find . -name .svn -prune -o -name '*Config.h'  -print`
387if test -n "$configFileLoc" ; then
388  versionSym=${srcProjUC}_VERSION
389  echo ''
390  echo "===> Updating $versionSym in $configFileLoc (if present)"
391  echo ''
392  mv $configFileLoc $configFileLoc.bak
393  bak_files="$bak_files $configFileLoc"
394  sed -e "s/# *define $versionSym.*\$/#define $versionSym \"$newVersion\"/" <$configFileLoc.bak >$configFileLoc
395  svn diff $configFileLoc
396fi
397
398# Now generate a proper Dependencies file for the stable branch.  References to
399# trunk will be converted to references to stable branches unless the reference
400# is to a project in the trunkExternals list (in which case it'll be converted
401# at the very end). References to releases are not changed. Each line in a
402# Dependencies file has the format <ext_name> <ext_url>. Normally, each entry
403# should be a stable branch.
404
405srcDepFile=
406for file in Dependencies Externals ; do
407  if test -r $file ; then
408    srcDepFile=$file
409    break
410  fi
411done
412
413if test -n "$srcDepFile" ; then
414
415# Save the externals property of the source, so we can just restore it after
416# the commit. Also save srcDepFile, because we may well modify it for the
417# stable branch, converting trunk externals to stable externals.
418
419  svn propget svn:externals . > .Externals.original
420  bak_files="$bak_files $srcDepFile"
421  cp $srcDepFile $srcDepFile.bak
422
423  echo ''
424  echo "===> Checking externals in $srcDepFile ..."
425  echo ''
426
427# We've just checked this out, no sense going back to the server for the
428# BuildTools version.
429
430  srcExternals=`svn propget svn:externals .`
431  srcBTURL=`echo $srcExternals | \
432    sed -n -e 's/.*BuildTools https:\([^ ]*\) .*/https:\1/p'`
433  if test -z "$srcBTURL" ; then
434    srcBTURL="none"
435  fi
436  echo "Source BuildTools...:  $srcBTURL"
437
438  rm -f Dependencies
439  ext_name=
440  ext_url=
441  buildtoolsMismatch=0
442  for i in `cat $srcDepFile.bak` ; do
443    if test "$ext_name" = "" ; then
444      ext_name=$i
445    else
446      ext_url=$i
447      if expr "$ext_name" : '#.*' 2>&1 >/dev/null ; then
448        echo "    $ext_name $ext_url ==> skipped"
449        ext_name=
450        continue
451      fi
452      ext_urltype=`extractTypeFromURL $ext_url`
453      ext_proj=`extractProjFromURL $ext_url`
454
455# See if this external should be dropped.
456
457      if expr "$exciseExternals" : '.*'$ext_proj'.*' 2>&1 > /dev/null ; then
458        echo "    $ext_name $ext_url ==> excised"
459        ext_name=
460        continue
461      fi
462
463# Convert a trunk URL to stable unless it's listed in trunkExternals.
464
465      if test $ext_urltype = trunk ; then
466        if expr "$trunkExternals" : '.*'$ext_proj'.*' 2>&1 >/dev/null ; then
467          echo "    $ext_name $ext_url ==> unchanged"
468        else
469          ext_oldurl=$ext_url
470          ext_url=`bestStable $ext_url -1`
471          case "$ext_url" in
472            */Data/* | */BuildTools/* ) ;;
473            *) ext_url="${ext_url}${ext_proj}"
474          esac
475          echo "    $ext_name $ext_oldurl ==> $ext_url"
476        fi
477      else
478        echo "    $ext_name $ext_url ==> unchanged"
479      fi
480
481# Get the BuildTools URL for the external and compare to the BuildTools URL
482# for the source, assuming we have one and the external has one.
483
484      if test $ext_proj != BuildTools && test $srcBTURL != none ; then
485        extBTURL=`svn propget svn:externals $ext_url`
486        extBTURL=`echo $extBTURL | \
487          sed -n -e 's/.*BuildTools https:\([^ ]*\) .*/https:\1/p'`
488        if test -n "$extBTURL" && test "$srcBTURL" != "$extBTURL" ; then
489          echo "    WARNING: BuildTools mismatch: $ext_url uses $extBTURL"
490          if test $ignoreBuildToolsMismatch = 0 ; then
491             buildtoolsMismatch=1
492          fi
493        fi
494      fi
495
496      echo "$ext_name  $ext_url" >>Dependencies
497      ext_name=
498      echo ''
499    fi
500  done
501  if test $buildtoolsMismatch -gt $ignoreBuildToolsMismatch ; then
502    echo "Exiting due to BuildTools mismatches; use -i to ignore."
503    exit 2
504  fi
505
506  $cmdDir/set_externals Dependencies
507
508  echo ''
509  echo '===> Checking out externals ...'
510  echo ''
511
512  svn update
513
514# Run any scripts to acquire ThirdParty code.
515
516  if test -d ThirdParty ; then
517
518    echo ''
519    echo '===> Downloading ThirdParty code ...'
520    echo ''
521   
522    ext_name=
523    ext_url=
524    for i in `svn propget svn:externals .` ; do
525      if test -z "$ext_name" ; then
526        ext_name=$i
527      else
528        ext_url=$i
529        if expr "$ext_name" : 'ThirdParty/.*' 2>&1 >/dev/null ; then
530          cd $ext_name
531          ext_proj=`extractProjFromURL $ext_url`
532          getScript=get.$ext_proj
533          if test -x "$getScript" ; then
534            ./$getScript -patch
535          fi
536          cd $coDir
537        fi
538        ext_name=
539      fi
540    done
541  fi
542fi
543
544
545# Done processing externals. If this is a ThirdParty project, we still have
546# to run the get script.
547
548if test $isThirdParty = yes; then
549  if test -x get.$srcProj ; then
550    echo ''
551    echo '===> Downloading third party code...'
552    echo ''
553    ./get.$srcProj
554  fi
555fi
556
557# Run the autotools to update configure and make files
558
559echo ''
560echo '===> Running BuildTools/run_autotools ...'
561echo ''
562
563if test $isThirdParty = yes || test $isData = yes ; then
564  cd ../..
565  BuildTools/run_autotools
566  cd "$coDir"
567else
568  BuildTools/run_autotools
569fi
570
571# Let's see if it works. We only run tests for non-ThirdParty, non-Data. DO NOT
572# turn on --enable-maintainer-mode in the initial configure command. At the
573# least, it's not needed. At the worst, as of 100526, it'll undo all the
574# careful work above to set externals.
575
576if test $isThirdParty != yes && test $isData != yes; then (
577   set -e
578   echo ''
579   echo '===> Creating build directory and running the configuration script...'
580   echo ''
581   mkdir build
582   cd build
583   cmd="$coDir/configure -C"
584   echo $cmd
585   eval $cmd
586   echo ''
587   echo '===> Compiling code...'
588   echo ''
589   cmd='make install'
590   echo $cmd
591   eval $cmd
592   echo ''
593   echo '===> Running the unit test...'
594   echo ''
595   echo '*******************************************************************************'
596   echo '***                                                                         ***'
597   echo '***                       BEGIN OUTPUT OF MAKE TEST                         ***'
598   echo '***                                                                         ***'
599   echo '*******************************************************************************'
600   echo ''
601   cmd='make test'
602   echo $cmd
603   eval $cmd
604   echo ''
605   echo '*******************************************************************************'
606   echo '***                                                                         ***'
607   echo '***                        END OUTPUT OF MAKE TEST                          ***'
608   echo '***                                                                         ***'
609   echo '*******************************************************************************'
610  )
611  if test $? != 0; then
612    echo ''
613    echo 'Error during build or test'
614    echo ''
615    exit 3
616  fi
617fi
618
619# No fatal errors. Declare victory.
620
621echo ''
622echo '===> ALL TESTS PASSED'
623if test $isThirdParty != yes &&
624   test $isData != yes && test $isBuildTools != yes ; then
625  echo ''
626  echo 'Please review the output above, particularly the one of make test'
627fi
628echo ''
629
630# Do we need to plug in nonexistent stable branches for circular dependencies
631# tested with the trunk? If so, generate a new Externals.release. This is
632# the only reason trunk references should appear in the externals for a
633# stable branch, so we don't need to check further before removing them.
634
635if test -n "$trunkExternals" ; then
636  echo ''
637  echo "===> Grooming externals to remove trunk references used for testing."
638  echo ''
639  mv Dependencies Dependencies.temp.$$
640  ext_name=
641  ext_url=
642  for i in `cat Dependencies.temp.$$`; do
643    if test "$ext_name" = ""; then
644      ext_name="$i"
645    else
646      ext_url=$i
647      ext_urltype=`extractTypeFromURL $ext_url`
648      ext_proj=`extractProjFromURL $ext_url`
649      if test $ext_urltype = trunk ; then
650        ext_oldurl=$ext_url
651        ext_url=`bestStable $ext_url -1`
652        ext_majVer=`extractMajorFromURL $ext_url`
653        ext_minVer=`extractMinorFromURL $ext_url`
654        ext_minVer=`expr $ext_minVer + 1`
655        ext_url=`replaceVersionInURL $ext_url $ext_majVer $ext_minVer`
656        ext_url="${ext_url}${ext_proj}"
657        echo "    $ext_name $ext_oldurl ==> $ext_url"
658      fi
659      echo "$ext_name  $ext_url" >>Dependencies
660      ext_name=
661    fi
662  done
663  rm -f Dependencies.temp.$$
664  $cmdDir/set_externals Dependencies
665fi
666
667if test -r Dependencies ; then
668  echo ''
669  echo 'Also, please confirm the Externals are correct:'
670  svn propget svn:externals
671fi
672
673echo ''
674echo 'After reviewing the output above, you can create a new release by going into'
675echo 'the directory'
676echo ''
677echo "          $startDir"
678echo ''
679echo "and run the commit_new_stable script"
680
681cd $topBuildDir
682
683# Record information for the commit_new_stable script.
684
685cat >.new_stable_data <<EOF
686coinURL=$coinURL
687startDir=$startDir
688topBuildDir=$topBuildDir
689coDir=$coDir
690newStableURL=$newStableURL
691srcURL=$srcURL
692newVersion=$newVersion
693bak_files="$bak_files"
694EOF
Note: See TracBrowser for help on using the repository browser.