source: trunk/prepare_new_stable @ 1802

Last change on this file since 1802 was 1802, checked in by lou, 9 years ago

Merge stable/0.6 r1801 into trunk.

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