source: trunk/prepare_new_stable @ 1561

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

Correctly handle case where directory used for external does not match the
project name, e.g., FlopC++/trunk/FlopCpp. Also add libtool library version
functions in coin-functions and correct output redirection.

  • Property svn:executable set to *
File size: 19.4 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          # Normal (not BuildTools/ThirdParty/Data) need a directory name,
472          # and it may differ from the project name. Carefully preserve it.
473          # ThirdParty URLs include BuildTools ; both named for emphasis
474          case $ext_url in
475            */BuildTools/* | */ThirdParty/* | */Data/* ) ;;
476            *) ext_tail=`extractTailFromExt $ext_oldurl`
477               ext_url=${ext_url}${ext_tail}
478               ;;
479          esac
480          echo "    $ext_name $ext_oldurl ==> $ext_url"
481        fi
482      else
483        echo "    $ext_name $ext_url ==> unchanged"
484      fi
485
486# Get the BuildTools URL for the external and compare to the BuildTools URL
487# for the source, assuming we have one and the external has one.
488
489      if test $ext_proj != BuildTools && test $srcBTURL != none ; then
490        extBTURL=`svn propget svn:externals $ext_url`
491        extBTURL=`echo $extBTURL | \
492          sed -n -e 's/.*BuildTools https:\([^ ]*\) .*/https:\1/p'`
493        if test -n "$extBTURL" && test "$srcBTURL" != "$extBTURL" ; then
494          echo "    WARNING: BuildTools mismatch: $ext_url uses $extBTURL"
495          if test $ignoreBuildToolsMismatch = 0 ; then
496             buildtoolsMismatch=1
497          fi
498        fi
499      fi
500
501      echo "$ext_name  $ext_url" >>Dependencies
502      ext_name=
503      echo ''
504    fi
505  done
506  if test $buildtoolsMismatch -gt $ignoreBuildToolsMismatch ; then
507    echo "Exiting due to BuildTools mismatches; use -i to ignore."
508    exit 2
509  fi
510
511  $cmdDir/set_externals Dependencies
512
513  echo ''
514  echo '===> Checking out externals ...'
515  echo ''
516
517  svn update
518
519# Run any scripts to acquire ThirdParty code.
520
521  if test -d ThirdParty ; then
522
523    echo ''
524    echo '===> Downloading ThirdParty code ...'
525    echo ''
526   
527    ext_name=
528    ext_url=
529    for i in `svn propget svn:externals .` ; do
530      if test -z "$ext_name" ; then
531        ext_name=$i
532      else
533        ext_url=$i
534        if expr "$ext_name" : 'ThirdParty/.*' 2>&1 >/dev/null ; then
535          cd $ext_name
536          ext_proj=`extractProjFromURL $ext_url`
537          getScript=get.$ext_proj
538          if test -x "$getScript" ; then
539            ./$getScript -patch
540          fi
541          cd $coDir
542        fi
543        ext_name=
544      fi
545    done
546  fi
547fi
548
549
550# Done processing externals. If this is a ThirdParty project, we still have
551# to run the get script.
552
553if test $isThirdParty = yes; then
554  if test -x get.$srcProj ; then
555    echo ''
556    echo '===> Downloading third party code...'
557    echo ''
558    ./get.$srcProj
559  fi
560fi
561
562# Run the autotools to update configure and make files
563
564echo ''
565echo '===> Running BuildTools/run_autotools ...'
566echo ''
567
568if test $isThirdParty = yes || test $isData = yes ; then
569  cd ../..
570  BuildTools/run_autotools
571  cd "$coDir"
572else
573  BuildTools/run_autotools
574fi
575
576# Let's see if it works. We only run tests for non-ThirdParty, non-Data. DO NOT
577# turn on --enable-maintainer-mode in the initial configure command. At the
578# least, it's not needed. At the worst, as of 100526, it'll undo all the
579# careful work above to set externals.
580
581if test $isThirdParty != yes && test $isData != yes; then (
582   set -e
583   echo ''
584   echo '===> Creating build directory and running the configuration script...'
585   echo ''
586   mkdir build
587   cd build
588   cmd="$coDir/configure -C"
589   echo $cmd
590   eval $cmd
591   echo ''
592   echo '===> Compiling code...'
593   echo ''
594   cmd='make install'
595   echo $cmd
596   eval $cmd
597   echo ''
598   echo '===> Running the unit test...'
599   echo ''
600   echo '*******************************************************************************'
601   echo '***                                                                         ***'
602   echo '***                       BEGIN OUTPUT OF MAKE TEST                         ***'
603   echo '***                                                                         ***'
604   echo '*******************************************************************************'
605   echo ''
606   cmd='make test'
607   echo $cmd
608   eval $cmd
609   echo ''
610   echo '*******************************************************************************'
611   echo '***                                                                         ***'
612   echo '***                        END OUTPUT OF MAKE TEST                          ***'
613   echo '***                                                                         ***'
614   echo '*******************************************************************************'
615  )
616  if test $? != 0; then
617    echo ''
618    echo 'Error during build or test'
619    echo ''
620    exit 3
621  fi
622fi
623
624# No fatal errors. Declare victory.
625
626echo ''
627echo '===> ALL TESTS PASSED'
628if test $isThirdParty != yes &&
629   test $isData != yes && test $isBuildTools != yes ; then
630  echo ''
631  echo 'Please review the output above, particularly the one of make test'
632fi
633echo ''
634
635# Do we need to plug in nonexistent stable branches for circular dependencies
636# tested with the trunk? If so, generate a new Externals.release. This is
637# the only reason trunk references should appear in the externals for a
638# stable branch, so we don't need to check further before removing them.
639
640if test -n "$trunkExternals" ; then
641  echo ''
642  echo "===> Grooming externals to remove trunk references used for testing."
643  echo ''
644  mv Dependencies Dependencies.temp.$$
645  ext_name=
646  ext_url=
647  for i in `cat Dependencies.temp.$$`; do
648    if test "$ext_name" = ""; then
649      ext_name="$i"
650    else
651      ext_url=$i
652      ext_urltype=`extractTypeFromURL $ext_url`
653      ext_proj=`extractProjFromURL $ext_url`
654      if test $ext_urltype = trunk ; then
655        ext_oldurl=$ext_url
656        ext_url=`bestStable $ext_url -1`
657        ext_majVer=`extractMajorFromURL $ext_url`
658        ext_minVer=`extractMinorFromURL $ext_url`
659        ext_minVer=`expr $ext_minVer + 1`
660        ext_url=`replaceVersionInURL $ext_url $ext_majVer $ext_minVer`
661        ext_url="${ext_url}${ext_proj}"
662        echo "    $ext_name $ext_oldurl ==> $ext_url"
663      fi
664      echo "$ext_name  $ext_url" >>Dependencies
665      ext_name=
666    fi
667  done
668  rm -f Dependencies.temp.$$
669  $cmdDir/set_externals Dependencies
670fi
671
672if test -r Dependencies ; then
673  echo ''
674  echo 'Also, please confirm the Externals are correct:'
675  svn propget svn:externals
676fi
677
678echo ''
679echo 'After reviewing the output above, you can create a new release by going into'
680echo 'the directory'
681echo ''
682echo "          $startDir"
683echo ''
684echo "and run the commit_new_stable script"
685
686cd $topBuildDir
687
688# Record information for the commit_new_stable script.
689
690cat >.new_stable_data <<EOF
691coinURL=$coinURL
692startDir=$startDir
693topBuildDir=$topBuildDir
694coDir=$coDir
695newStableURL=$newStableURL
696srcURL=$srcURL
697newVersion=$newVersion
698bak_files="$bak_files"
699EOF
Note: See TracBrowser for help on using the repository browser.