source: trunk/prepare_new_stable @ 1593

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

Release scripts *_new_release rewritten for new script architecture. Upgrades
and bug fixes for coin-functions, *_new_stable, set_externals. Correctly handle
multilevel project names (e.g., CHiPPS/Alps), CppAD version numbering.

  • Property svn:executable set to *
File size: 20.1 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 current 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=`echo $srcProj | sed -e 's|.*/\([^/]*\)$|\1|'`
318topBuildDir=${topBuildDir}-${newVersion}
319echo "Build directory.....: $topBuildDir"
320
321# Now decide where to check out code.
322
323if test $isThirdParty = yes; then
324  coDir=$topBuildDir/Thirdparty/$srcProj
325elif test $isData = yes; then
326  coDir=$topBuildDir/Data/$srcProj
327else
328  coDir=$topBuildDir
329fi
330echo "Checkout directory..: $coDir"
331
332exit
333
334echo ''
335echo "===> Checking out source $srcURL without externals ..."
336echo ''
337
338cmd="svn co --ignore-externals $srcURL $coDir"
339if test $suppressCheckout = 1 ; then
340  echo "Pretending to do: $cmd"
341else
342  rm -rf $topBuildDir
343  echo $cmd
344  eval $cmd
345fi
346
347if test $isThirdParty = yes || test $isData = yes; then
348  echo ''
349  echo '===> Checking out BuildTools (Data or ThirdParty) ...'
350  echo ''
351  cmd="svn co $cmdBTURL $topBuildDir/BuildTools"
352  if test $suppressCheckout = 1 ; then
353    echo "Pretending to do: $cmd"
354  else
355    echo $cmd
356    eval $cmd
357  fi
358fi
359
360startDir=`pwd`
361coDir=`cd $coDir; pwd`
362topBuildDir=`cd $topBuildDir; pwd`
363
364cd $coDir
365
366# Find configure.ac files for the package and project and update the version.
367# We have no externals at this point, and no third-party code, so there will
368# be two files for a standard project, one for a ThirdParty or Data project.
369
370echo ''
371bak_files=`find . -name 'configure.ac'`
372echo "===> Creating backup (.bak) for configure.ac files..."
373for i in $bak_files; do
374  cp $i $i.bak
375done
376
377# Take the attitude that [] around parameters in AC_INIT is optional,
378# it's the commas that count. This does make for a surpassing ugly regular
379# expression.  A comma in the version string will cause a spectacular failure.
380# In AC_COIN_PROJECTDIR_INIT, take the attitude that the existing parameters
381# don't matter, we know what the release parameters should be.
382
383echo ''
384echo "===> Updating version numbers in configure.ac files"
385for i in $bak_files; do
386  sed -e "s|AC_INIT\(.*\),\(\[*\)[^],]*\(\]*\),\(.*\)|AC_INIT\1,\2$newVersion\3,\4|" $i > bla
387  mv bla $i
388  svn diff $i
389done
390
391# Find ProjConfig.h. If there's a definition for PROJ_VERSION, adjust it and
392# add ProjConfig.h.bak to the list of files to be restored.
393
394srcProjUC=`echo $srcProj | tr '[a-z]' '[A-Z]'`
395configFileLoc=`find . -name .svn -prune -o -name '*Config.h'  -print`
396if test -n "$configFileLoc" ; then
397  versionSym=${srcProjUC}_VERSION
398  echo ''
399  echo "===> Updating $versionSym in $configFileLoc (if present)"
400  echo ''
401  mv $configFileLoc $configFileLoc.bak
402  bak_files="$bak_files $configFileLoc"
403  sed -e "s/# *define $versionSym.*\$/#define $versionSym \"$newVersion\"/" <$configFileLoc.bak >$configFileLoc
404  svn diff $configFileLoc
405fi
406
407# Now generate a proper Dependencies file for the stable branch.  References to
408# trunk will be converted to references to stable branches unless the reference
409# is to a project in the trunkExternals list (in which case it'll be converted
410# at the very end). References to releases are not changed. Each line in a
411# Dependencies file has the format <ext_name> <ext_url>. Normally, each entry
412# should be a stable branch.
413
414srcDepFile=
415for file in Dependencies Externals ; do
416  if test -r $file ; then
417    srcDepFile=$file
418    break
419  fi
420done
421
422if test -n "$srcDepFile" ; then
423
424# Save the externals property of the source, so we can just restore it after
425# the commit. Also save srcDepFile, because we may well modify it for the
426# stable branch, converting trunk externals to stable externals.
427
428  svn propget svn:externals . > .Externals.original
429  bak_files="$bak_files $srcDepFile"
430  cp $srcDepFile $srcDepFile.bak
431
432  echo ''
433  echo "===> Checking externals in $srcDepFile ..."
434  echo ''
435
436# We've just checked this out, no sense going back to the server for the
437# BuildTools version. Because of the intermediate variable, newline has
438# become space.
439
440  srcExternals=`svn propget svn:externals .`
441  srcBTURL=`echo $srcExternals | \
442            sed -n -e 's/.*BuildTools *https:\([^ ]*\) .*/https:\1/p'`
443  if test -z "$srcBTURL" ; then
444    srcBTURL="none"
445  fi
446  echo "Source BuildTools...:  $srcBTURL"
447
448  rm -f Dependencies
449  ext_name=
450  ext_url=
451  buildtoolsMismatch=0
452  for i in `cat $srcDepFile.bak` ; do
453    if test "$ext_name" = "" ; then
454      ext_name=$i
455    else
456      ext_url=$i
457      if expr "$ext_name" : '#.*' 2>&1 >/dev/null ; then
458        echo "    $ext_name $ext_url ==> skipped"
459        ext_name=
460        continue
461      fi
462      ext_urltype=`extractTypeFromURL $ext_url`
463      ext_proj=`extractProjFromURL $ext_url`
464
465# See if this external should be dropped.
466
467      if expr "$exciseExternals" : '.*'$ext_proj'.*' 2>&1 > /dev/null ; then
468        echo "    $ext_name $ext_url ==> excised"
469        ext_name=
470        continue
471      fi
472
473      ext_isNormalURL=`isNormalURL $ext_url`
474
475# Convert a trunk URL to stable unless it's listed in trunkExternals.
476
477      if test $ext_urltype = trunk ; then
478        if expr "$trunkExternals" : '.*'$ext_proj'.*' 2>&1 >/dev/null ; then
479          echo "    $ext_name $ext_url ==> unchanged"
480        else
481          ext_oldurl=$ext_url
482          ext_url=`bestStable $ext_url -1`
483          # Normal (not BuildTools/ThirdParty/Data) need a directory name,
484          # and it may differ from the project name. Carefully preserve it.
485          if test $ext_isNormalURL = yes ; then
486            ext_tail=`extractTailFromExt $ext_oldurl`
487            ext_url=${ext_url}${ext_tail}
488          fi
489          echo "    $ext_name $ext_oldurl ==> $ext_url"
490        fi
491      else
492        echo "    $ext_name $ext_url ==> unchanged"
493      fi
494
495# Get the BuildTools URL for the external and compare to the BuildTools URL
496# for the source, assuming we have one and the external has one.
497
498      if test $ext_isNormalURL = yes &&
499         test $ext_proj != BuildTools && test $srcBTURL != none ; then
500        ext_url_notail=`echo $ext_url | sed -e 's,/[^/]*$,,'`
501        extBTURL=`svn propget svn:externals $ext_url_notail`
502        extBTURL=`echo $extBTURL | \
503          sed -n -e 's/.*BuildTools https:\([^ ]*\) .*/https:\1/p'`
504        if test -n "$extBTURL" ; then
505          testResult=`compareURLVersions "$srcBTURL" "$extBTURL"`
506          if test $testResult = no ; then
507            echo "    WARNING: BuildTools mismatch: $ext_url_notail uses $extBTURL"
508            if test $ignoreBuildToolsMismatch = 0 ; then
509               buildtoolsMismatch=1
510            fi
511          fi
512        fi
513      fi
514
515      echo "$ext_name  $ext_url" >>Dependencies
516      ext_name=
517      echo ''
518    fi
519  done
520
521# If we have a BuildTools mismatch, and mismatch is not permitted, exit.
522
523  if test $buildtoolsMismatch -gt $ignoreBuildToolsMismatch ; then
524    echo "Exiting due to BuildTools mismatches; use -i to ignore."
525    exit 2
526  fi
527
528  $cmdDir/set_externals Dependencies
529
530  echo ''
531  echo '===> Checking out externals ...'
532  echo ''
533
534  svn update
535
536# Run any scripts to acquire ThirdParty code.
537
538  if test -d ThirdParty ; then
539
540    echo ''
541    echo '===> Downloading ThirdParty code ...'
542    echo ''
543   
544    ext_name=
545    ext_url=
546    for i in `svn propget svn:externals .` ; do
547      if test -z "$ext_name" ; then
548        ext_name=$i
549      else
550        ext_url=$i
551        if expr "$ext_name" : 'ThirdParty/.*' 2>&1 >/dev/null ; then
552          cd $ext_name
553          ext_proj=`extractProjFromURL $ext_url`
554          getScript=get.$ext_proj
555          if test -x "$getScript" ; then
556            ./$getScript -patch
557          fi
558          cd $coDir
559        fi
560        ext_name=
561      fi
562    done
563  fi
564fi
565
566
567# Done processing externals. If this is a ThirdParty project, we still have
568# to run the get script.
569
570if test $isThirdParty = yes; then
571  if test -x get.$srcProj ; then
572    echo ''
573    echo '===> Downloading third party code...'
574    echo ''
575    ./get.$srcProj
576  fi
577fi
578
579# Run the autotools to update configure and make files
580
581echo ''
582echo '===> Running BuildTools/run_autotools ...'
583echo ''
584
585if test $isThirdParty = yes || test $isData = yes ; then
586  cd ../..
587  ./BuildTools/run_autotools
588  cd "$coDir"
589else
590  ./BuildTools/run_autotools
591fi
592
593# Let's see if it works. We only run tests for non-ThirdParty, non-Data. DO NOT
594# turn on --enable-maintainer-mode in the initial configure command. At the
595# least, it's not needed. At the worst, as of 100526, it'll undo all the
596# careful work above to set externals.
597
598if test $isThirdParty != yes && test $isData != yes; then (
599   set -e
600   echo ''
601   echo '===> Creating build directory and running the configuration script...'
602   echo ''
603   mkdir build
604   cd build
605   cmd="$coDir/configure -C"
606   echo $cmd
607   eval $cmd
608   echo ''
609   echo '===> Compiling code...'
610   echo ''
611   cmd='make install'
612   echo $cmd
613   eval $cmd
614   echo ''
615   echo '===> Running the unit test...'
616   echo ''
617   echo '*******************************************************************************'
618   echo '***                                                                         ***'
619   echo '***                       BEGIN OUTPUT OF MAKE TEST                         ***'
620   echo '***                                                                         ***'
621   echo '*******************************************************************************'
622   echo ''
623   cmd='make test'
624   echo $cmd
625   eval $cmd
626   echo ''
627   echo '*******************************************************************************'
628   echo '***                                                                         ***'
629   echo '***                        END OUTPUT OF MAKE TEST                          ***'
630   echo '***                                                                         ***'
631   echo '*******************************************************************************'
632  )
633  if test $? != 0; then
634    echo ''
635    echo 'Error during build or test'
636    echo ''
637    exit 3
638  fi
639fi
640
641# No fatal errors. Declare victory.
642
643echo ''
644echo '===> ALL TESTS PASSED'
645if test $isThirdParty != yes &&
646   test $isData != yes && test $isBuildTools != yes ; then
647  echo ''
648  echo 'Please review the output above, particularly the one of make test'
649fi
650echo ''
651
652# Do we need to plug in nonexistent stable branches for circular dependencies
653# tested with the trunk? If so, generate a new Dependencies. This is the only
654# reason trunk references should appear in the externals for a stable branch,
655# so we don't need to check further before removing them.
656
657if test -n "$trunkExternals" ; then
658  echo ''
659  echo "===> Grooming externals to remove trunk references used for testing."
660  echo ''
661  mv Dependencies Dependencies.temp.$$
662  ext_name=
663  ext_url=
664  for i in `cat Dependencies.temp.$$`; do
665    if test "$ext_name" = ""; then
666      ext_name="$i"
667    else
668      ext_url=$i
669      ext_urltype=`extractTypeFromURL $ext_url`
670      ext_proj=`extractProjFromURL $ext_url`
671      if test $ext_urltype = trunk ; then
672        ext_oldurl=$ext_url
673        ext_url=`bestStable $ext_url -1`
674        ext_majVer=`extractMajorFromURL $ext_url`
675        ext_minVer=`extractMinorFromURL $ext_url`
676        ext_minVer=`expr $ext_minVer + 1`
677        ext_url=`replaceVersionInURL $ext_url $ext_majVer $ext_minVer`
678        ext_url="${ext_url}${ext_proj}"
679        echo "    $ext_name $ext_oldurl ==> $ext_url"
680      fi
681      echo "$ext_name  $ext_url" >>Dependencies
682      ext_name=
683    fi
684  done
685  rm -f Dependencies.temp.$$
686  $cmdDir/set_externals Dependencies
687fi
688
689if test -r Dependencies ; then
690  echo ''
691  echo 'Also, please confirm the Externals are correct:'
692  svn propget svn:externals
693fi
694
695echo ''
696echo 'After reviewing the output above, you can create a new release by going into'
697echo 'the directory'
698echo ''
699echo "          $startDir"
700echo ''
701echo "and run the commit_new_stable script"
702
703cd $topBuildDir
704
705# Record information for the commit_new_stable script.
706
707cat >.new_stable_data <<EOF
708coinURL=$coinURL
709startDir=$startDir
710topBuildDir=$topBuildDir
711coDir=$coDir
712newStableURL=$newStableURL
713srcURL=$srcURL
714newVersion=$newVersion
715bak_files="$bak_files"
716EOF
Note: See TracBrowser for help on using the repository browser.