source: stable/0.6/coin-functions @ 1811

Last change on this file since 1811 was 1811, checked in by tkr, 9 years ago

Fixing function for calculating age

File size: 17.3 KB
Line 
1
2# Utility function definitions for the various COIN scripts.
3
4# Copyright (c) 2010 Lou Hafer  Simon Fraser University
5# All Rights Reserved.
6# This file is distributed under the Common Public License.
7# It is part of the BuildTools project in COIN-OR (www.coin-or.org)
8#
9# $Id$
10
11# Functions to disassemble svn URLs and extract relevant bits, and utilities
12# to find the best (most recent) stable and release URLs, calculate libtool
13# version numbers, and compare URLs for compatibility based on major and minor
14# version. Complicated because we have to account for trunk/stable/release and
15# for the variant syntax of Data and ThirdParty URLs. For your normal project,
16# it's
17#   https://projects.coin-or.org/svn/ProjName/trunk
18#   https://projects.coin-or.org/svn/ProjName/stable/M.m
19#   https://projects.coin-or.org/svn/ProjName/releases/M.m.r
20# with the proviso that sometimes it's
21#   https://projects.coin-or.org/svn/ProjName/SubProj/trunk
22# etc.
23# For ThirdParty, it's just like a normal project, except the prefix string
24# is longer:
25#   https://projects.coin-or.org/svn/BuildTools/ThirdParty/ProjName
26# Data is the real pain. Prior to 20101103 (1.0.x series), it had this form:
27#  https://projects.coin-or.org/svn/Data/trunk/ProjName
28#  https://projects.coin-or.org/svn/Data/stable/M.m/ProjName
29#  https://projects.coin-or.org/svn/Data/releases/M.m.r/ProjName
30# After 20101103 (1.1 and subsequent), it uses the same layout as ThirdParty,
31# namely <svn prefix>/Data/Projname/<trunk, stable, releases>. Macros below
32# will cope, but really you should be using pre-1.1 Data anyway.
33
34# Extract the COIN base from the URL, up to svn. Just in case it ever changes.
35# usage: baseURL=`extractBaseURL $svnURL`
36
37extractBaseURL ()
38{
39  exbu_baseURL=`echo $1 | sed -n -e 's|\(.*/svn\)/.*$|\1|p'`
40  echo "$exbu_baseURL"
41}
42
43
44# Extract branch type (trunk/stable/release) from the URL.
45# usage: branchType=`extractTypeFromURL $svnURL`
46
47extractTypeFromURL ()
48{
49  etfu_type="invalid"
50  case "$1" in
51    */trunk* ) etfu_type=trunk ;;
52    */stable/* ) etfu_type=stable ;;
53    */releases/* ) etfu_type=releases ;;
54  esac
55  echo $etfu_type
56}
57
58# Determine if this is a `normal' URL, defined as not Data, ThirdParty, or
59# BuildTools itself. ThirdParty lives in BuildTools as of 100628, so the
60# condition is redundant. Returns yes or no.
61# usage: isNormal=`isNormalURL $svnURL`
62
63isNormalURL ()
64{ case $1 in
65    */BuildTools/* | */ThirdParty/* | */Data/* )
66       echo "no"
67       ;;
68    *) echo "yes"
69       ;;
70  esac
71}
72
73# Extract the project from a svn URL. The trick, for `normal' projects, is to
74# handle CHiPPS, which has CHiPPS/Alps, Bcps, Blis. We can't assume the
75# project name does not contain '/'. The heuristic is to look for everything
76# between svn and one of trunk, stable, releases, or end of line.
77# usage: projName=`extractProjFromURL $svnURL`
78
79extractProjFromURL ()
80{
81  epfu_URL="$1"
82  epfu_projPat='\([^/][^/]*\)'
83  epfu_sfxPat='.*$'
84  case "$epfu_URL" in
85    */Data/trunk/* )
86        epfu_pfxPat=svn/Data/trunk/
87        ;;
88    */Data/stable/* | */Data/releases/* )
89        epfu_pfxPat='svn/Data/[^/][^/]*/[0-9][0-9.]*/'
90        ;;
91    */Data/* )
92        epfu_pfxPat='svn/Data/'
93        ;;
94    */ThirdParty/* )
95        epfu_pfxPat=svn/BuildTools/ThirdParty/
96        ;;
97    *)  epfu_type=`extractTypeFromURL $epfu_URL`
98        epfu_pfxPat='svn/'
99        epfu_projPat='\(.*\)'
100        case $epfu_type in
101          trunk | stable | releases )
102              epfu_sfxPat=$epfu_type'.*$'
103              ;;
104          * )
105              epfu_sfxPat='$'
106              ;;
107        esac
108        ;;
109  esac
110  epfu_projName=`echo $epfu_URL | sed -n -e 's|.*/'$epfu_pfxPat$epfu_projPat$epfu_sfxPat'|\1|p'`
111  epfu_projName=`echo $epfu_projName | sed -e 's|/$||'`
112  echo "$epfu_projName"
113}
114
115# Extract the tail (directory) from a URL that specifies an external. Relevant
116# only for normal projects, where the external will be a subdirectory
117# of the project. Returns null for Data / ThirdParty / BuildTools.
118# usage: projName=`extractTailFromExt $extURL`
119
120extractTailFromExt ()
121{
122  etfe_tail=
123  case "$1" in
124    */Data/* )
125        ;;
126    */BuildTools/ThirdParty/* )
127        ;;
128    */BuildTools/* )
129        ;;
130    *)
131        etfe_pfxPat=
132        case "$1" in
133          */trunk/* )
134              etfe_pfxPat='.*/trunk/'
135              ;;
136          */stable/* )
137              etfe_pfxPat='.*/stable/[0-9][0-9.]*/'
138              ;;
139          */releases/* )
140              etfe_pfxPat='.*/releases/[0-9][0-9.]*/'
141              ;;
142        esac
143        etfe_tail=`echo $1 | sed -n -e 's|'$etfe_pfxPat'\(.*\)|\1|p'`
144        ;;
145  esac
146  echo "$etfe_tail"
147}
148
149
150# CppAD uses a version string of the form YYYMMDD.rr. What a pain in the ass.
151# Hence the scattered exceptions below.
152# Extract the entire version string from a stable or release URL. Returns a
153# null string if handed a trunk URL or if there's no version in the URL. The
154# version number must have at least major.minor to match.
155# usage: version=`extractVersionFromURL $svnURL`
156
157extractVersionFromURL ()
158{
159  evfu_URL="$1"
160  if expr "$evfu_URL" : '.*/stable/.*' >/dev/null 2>&1 ||
161     expr "$evfu_URL" : '.*/releases/.*' >/dev/null 2>&1 ; then
162    if expr "$evfu_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
163      evfu_verPat='\([0-9][0-9.]*\)'
164    else
165      evfu_verPat='\([0-9][0-9]*\.[0-9][0-9.]*\)'
166    fi
167    evfu_sfxPat='.*$'
168    evfu_proj=`extractProjFromURL $evfu_URL`
169    case "$evfu_URL" in
170      */Data/stable/* | */Data/releases/* )
171          evfu_pfxPat='svn/Data/[^/][^/]*/'
172          ;;
173      */ThirdParty/* )
174          evfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
175          ;;
176      */Data/* )
177          evfu_pfxPat='svn/Data/'$evfu_proj'/[^/][^/]*/'
178          ;;
179      *)
180          evfu_pfxPat='svn/'$evfu_proj'/[^/][^/]*/'
181          ;;
182    esac
183    evfu_verVer=`echo $1 | sed -n -e 's|.*/'$evfu_pfxPat$evfu_verPat$evfu_sfxPat'|\1|p'`
184    echo "$evfu_verVer"
185  else
186    echo ""
187  fi
188}
189
190# Replace the entire version string from a stable or release URL. A trunk
191# URL will be unmodified. newRev will not be accessed unless the URL is a
192# release. The version must have at least major.minor to match.
193# usage: newURL=`replaceVersionInURL $oldURL $newMajor $newMinor $newRev`
194# and just for CppAD,
195# usage: newURL=`replaceVersionInURL $oldURL $newMajor $newRev`
196
197replaceVersionInURL ()
198{
199  if expr "$1" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
200    isCppAD=yes
201  else
202    isCppAD=no
203  fi
204  if test $isCppAD = no ; then
205    rviu_verPat='[0-9][0-9]*\.[0-9][0-9.]*'
206  else
207    rviu_verPat='[0-9][0-9.]*'
208  fi
209
210  if expr "$1" : '.*/stable/.*' >/dev/null 2>&1 ; then
211    if test $isCppAD = no ; then
212      rviu_newVersion=$2.$3
213    else
214      rviu_newVersion=$2
215    fi
216  elif expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
217    if test $isCppAD = no ; then
218      rviu_newVersion=$2.$3.$4
219    else
220      rviu_newVersion=$2.$3
221    fi
222  else
223    rviu_newVersion=
224    rviu_newURL=$1
225  fi
226  if test -n "$rviu_newVersion" ; then
227    rviu_newURL=`echo $1 | sed -n -e 's|^\(.*\)/'$rviu_verPat'\(.*\)$|\1/'$rviu_newVersion'\2|p'`
228  fi
229  echo $rviu_newURL
230}
231
232# Extract the major version number from a stable or release URL. Returns -1 if
233# handed a trunk URL or if there's no version in the URL
234# usage: majVer=`extractMajorFromURL $svnURL`
235
236extractMajorFromURL ()
237{
238  ejfu_URL="$1"
239  if expr "$ejfu_URL" : '.*/stable/.*' >/dev/null 2>&1 ||
240     expr "$ejfu_URL" : '.*/releases/.*' >/dev/null 2>&1 ; then
241    ejfu_majPat='\([0-9][0-9]*\)'
242    if expr "$ejfu_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
243      ejfu_sfxPat='.*$'
244    else
245      ejfu_sfxPat='\.[0-9][0-9]*.*$'
246    fi
247    ejfu_proj=`extractProjFromURL $ejfu_URL`
248    case "$ejfu_URL" in
249      */Data/stable/* | */Data/releases/* )
250          ejfu_pfxPat='svn/Data/[^/][^/]*/'
251          ;;
252      */ThirdParty/* )
253          ejfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
254          ;;
255      */Data/* )
256          ejfu_pfxPat='svn/Data/'$ejfu_proj'/[^/][^/]*/'
257          ;;
258      *)
259          ejfu_pfxPat='svn/'$ejfu_proj'/[^/][^/]*/'
260          ;;
261    esac
262    ejfu_majVer=`echo $ejfu_URL | sed -n -e 's|.*/'$ejfu_pfxPat$ejfu_majPat$ejfu_sfxPat'|\1|p'`
263    echo "$ejfu_majVer"
264  else
265    echo "-1"
266  fi
267}
268
269# Extract the minor version number from a stable or release URL. Returns -1 if
270# handed a trunk URL or if there's no version in the URL.
271# The CppAD form (YYYYMMDD.rr) doesn't have a minor version number.
272# usage: minVer=`extractMinorFromURL $svnURL`
273
274extractMinorFromURL ()
275{
276  emfu_URL="$1"
277  if expr "$emfu_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
278    echo "-1"
279  elif expr "$emfu_URL" : '.*/stable/.*' >/dev/null 2>&1 ||
280       expr "$emfu_URL" : '.*/releases/.*' >/dev/null 2>&1 ; then
281    emfu_minPat='[0-9][0-9]*\.\([0-9][0-9]*\)'
282    emfu_sfxPat='.*$'
283    emfu_proj=`extractProjFromURL $emfu_URL`
284    case "$emfu_URL" in
285      */Data/stable/* | */Data/releases/* )
286          emfu_pfxPat='svn/Data/[^/][^/]*/'
287          ;;
288      */ThirdParty/* )
289          emfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
290          ;;
291      */Data/* )
292          emfu_pfxPat='svn/Data/'$emfu_proj'/[^/][^/]*/'
293          ;;
294      *)
295          emfu_pfxPat='svn/'$emfu_proj'/[^/][^/]*/'
296          ;;
297    esac
298    emfu_minVer=`echo $emfu_URL | sed -n -e 's|.*/'$emfu_pfxPat$emfu_minPat$emfu_sfxPat'|\1|p'`
299    echo "$emfu_minVer"
300  else
301    echo "-1"
302  fi
303}
304
305# Extract the release (revision) number from a release URL. Returns -1 if
306# handed a trunk or stable URL
307# usage: minVer=`extractReleaseFromURL $svnURL`
308
309extractReleaseFromURL ()
310{
311  erfu_URL="$1"
312  if expr "$erfu_URL" : '.*/releases/.*' >/dev/null 2>&1 ; then
313    if expr "$erfu_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
314      erfu_relPat='[0-9][0-9]*\.\([0-9][0-9]*\)'
315    else
316      erfu_relPat='[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)'
317    fi
318    erfu_sfxPat='.*$'
319    erfu_proj=`extractProjFromURL $erfu_URL`
320    case "$erfu_URL" in
321      */Data/releases/* )
322          erfu_pfxPat='svn/Data/[^/][^/]*/'
323          ;;
324      */ThirdParty/* )
325          erfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
326          ;;
327      */Data/*)
328          erfu_pfxPat='svn/Data/'$erfu_proj'/[^/][^/]*/'
329          ;;
330      *)
331          erfu_pfxPat='svn/'$erfu_proj'/[^/][^/]*/'
332          ;;
333    esac
334    erfu_relVer=`echo $erfu_URL | sed -n -e 's|.*/'$erfu_pfxPat$erfu_relPat$erfu_sfxPat'|\1|p'`
335    echo "$erfu_relVer"
336  else
337    echo "-1"
338  fi
339}
340
341# Now some functions to locate the highest-numbered stable or release.
342
343# Return the URL of the most recent stable branch matching the parameters.
344# A value of -1 for major version is interpreted as `highest number'
345# Returns an empty string if no suitable stable branch exists.
346# usage: stableURL=`bestStable <URL> <major>`
347
348bestStable ()
349{ bstb_URL=$1
350  bstb_majVer=$2
351
352  # Construct a URL to send to the repository to list the stable branches.
353
354  bstb_baseURL=`extractBaseURL $bstb_URL`
355  bstb_proj=`extractProjFromURL $bstb_URL`
356
357  case "$bstb_URL" in
358    */Data/trunk/* )
359        bstb_listURL=$bstb_baseURL/Data/stable
360        ;;
361    */Data/* )
362        bstb_listURL=$bstb_baseURL/Data/$bstb_proj/stable
363        ;;
364    */ThirdParty/* )
365        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/stable
366        ;;
367    * )
368        bstb_listURL=$bstb_baseURL/$bstb_proj/stable
369        ;;
370  esac
371
372  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2`
373
374  # echo "Raw ls: $bstb_rawls"
375
376  # Filter the list of stable branches to remove any that do not match the
377  # requested major version. Note that there's a / at the end of each URL.
378
379  if test "$bstb_majVer" = "-1" ; then
380    bstb_verPat='[0-9][0-9.]*/'
381  elif expr "$bstb_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
382    bstb_verPat=$bstb_majVer'/'
383  else
384    bstb_verPat=$bstb_majVer'\.[0-9][0-9]*'
385  fi
386  bstb_filter=
387  for bstb_ver in $bstb_rawls ; do
388    if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
389      bstb_filter="$bstb_filter $bstb_ver"
390    fi
391  done
392
393  # echo "Filtered ls: $bstb_filter"
394
395  # If there are any candidates left ...
396
397  bstb_bestURL=
398  if test -n "$bstb_filter" ; then
399
400    # If we're dealing with old-style Data, we have to work a bit harder
401    # to find our project. See if any of the filtered candidates contain
402    # the correct project.
403
404    case "$bstb_URL" in
405      */Data/trunk/* | */Data/stable/* | */Data/releases/* )
406        bstb_projPat='.*'$bstb_proj'/.*'
407        # echo "Pattern: $bstb_projPat"
408        for bstb_ver in $bstb_filter ; do
409          if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
410            # echo "  url: $bstb_listURL/$bstb_ver"
411            bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
412            # echo "  result: $bstb_svnls2"
413            if expr "$bstb_svnls2" : $bstb_projPat >/dev/null 2>&1 ; then
414              bstb_best=$bstb_ver
415              # echo "  best: $bstb_best"
416              break
417            fi
418          fi
419        done
420        bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
421      ;;
422      *)
423        bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
424        bstb_bestURL=$bstb_listURL/$bstb_bestURL
425      ;;
426    esac
427  fi
428
429  echo $bstb_bestURL
430}
431
432# Return the URL of the most recent release matching the parameters. Returns
433# null if no suitable release exists.
434# A value of -1 for major or minor version is interpreted as `highest number'
435# A value of -1 for major version means that minor version is ignored.
436# usage: releaseURL=`bestRelease <URL> <major> <minor>`
437
438bestRelease ()
439{ bstb_URL=$1
440  bstb_majVer=$2
441  bstb_minVer=$3
442
443  # Construct a URL to send to the repository to list the releases.
444
445  bstb_baseURL=`extractBaseURL $bstb_URL`
446  bstb_proj=`extractProjFromURL $bstb_URL`
447
448  case "$bstb_URL" in
449    */Data/* )
450        bstb_listURL=$bstb_baseURL/Data/$bstb_proj/releases
451        ;;
452    */ThirdParty/* )
453        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/releases
454        ;;
455    * )
456        bstb_listURL=$bstb_baseURL/$bstb_proj/releases
457        ;;
458  esac
459
460  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2 -k3,3`
461
462  # echo "Raw ls: $bstb_rawls"
463
464  # Filter the list of releases to remove any that do not match the
465  # requested major and minor version.
466
467  if expr "$bstb_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
468    isCppAD=yes
469  else
470    isCppAD=no
471  fi
472
473  if test "$bstb_majVer" = "-1" ; then
474    bstb_verPat='[0-9][0-9.]*/'
475  else
476    bstb_verPat=$bstb_majVer
477    if test $isCppAD = no &&
478       test "$bstb_minVer" != "-1" ; then
479      bstb_verPat="${bstb_verPat}\.$bstb_minVer"
480    fi
481    bstb_verPat="${bstb_verPat}"'\.[0-9][0-9]*/'
482  fi
483
484  # echo "Version pattern: $bstb_verPat"
485  bstb_filter=
486  for bstb_ver in $bstb_rawls ; do
487    if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
488      bstb_filter="$bstb_filter $bstb_ver"
489    fi
490  done
491
492  # echo "Filtered ls: $bstb_filter"
493
494  # If there are any candidates left ...
495
496  bstb_bestURL=
497  if test -n "$bstb_filter" ; then
498
499    # If we're dealing with old-style Data, we have to work a bit harder to find our
500    # project. See if any of the filtered candidates contain the correct
501    # project.
502
503    case "$bstb_URL" in
504      */Data/trunk/* | */Data/stable/* | */Data/releases/* )
505        bstb_projPat='.*'$bstb_proj'/.*'
506        # echo "Pattern: $bstb_projPat"
507        for bstb_ver in $bstb_filter ; do
508          if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
509            # echo "  url: $bstb_listURL/$bstb_ver"
510            bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
511            # echo "  result: $bstb_svnls2"
512            if expr "$bstb_svnls2" : $bstb_projPat >/dev/null 2>&1 ; then
513              bstb_best=$bstb_ver
514              # echo "  best: $bstb_best"
515              break
516            fi
517          fi
518        done
519        bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
520      ;;
521      *)
522        bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
523        bstb_bestURL=$bstb_listURL/$bstb_bestURL
524      ;;
525    esac
526
527  fi
528
529  echo $bstb_bestURL
530}
531
532# Count the total number of stable branches for the project for the specified
533# major version number (libtool age). A major version number of -1 means all
534# stable branches (libtool current; see next function). Returns 0 if handed
535# a trunk url, or if the url is Data or BuildTools itself.
536# usage: calcLibtoolAge <svnURL> <major>
537
538calcLibtoolAge ()
539{ cltc_URL=$1
540  cltc_majVer=$2
541
542  # Construct a URL to send to the repository to list the stable branches.
543
544  cltc_baseURL=`extractBaseURL $cltc_URL`
545  cltc_proj=`extractProjFromURL $cltc_URL`
546
547  case "$cltc_URL" in
548    */Data/* )
549        cltc_listURL=
550        ;;
551    */ThirdParty/* )
552        cltc_listURL=$cltc_baseURL/BuildTools/ThirdParty/$cltc_proj/stable
553        ;;
554    */BuildTools/* )
555        cltc_listURL=
556        ;;
557    * )
558        cltc_listURL=$cltc_baseURL/$cltc_proj/stable
559        ;;
560  esac
561
562  # Run an ls and filter for standard stable branches (M.m or YYYYMMDD)
563
564  if test -n "$cltc_listURL" ; then
565    cltc_rawls=`svn list $cltc_listURL | sed -n -e '/[0-9][0-9.]/p'`
566
567    # echo "Raw ls: $cltc_rawls"
568
569    # Filter the list of stable branches to remove any that do not match the
570    # requested major version. -1 means `any major version', hence no filter.
571
572    if test "$cltc_majVer" != "-1" ; then
573      if expr "$cltc_URL" : '.*/CppAD/.*' >/dev/null 2>&1 ; then
574        cltc_verPat=$cltc_majVer
575      else
576        cltc_verPat=$cltc_majVer'\.[0-9][0-9]*'
577      fi
578    else
579      cltc_verPat='[0-9][0-9.]*'
580    fi
581    cltc_filter=
582    for cltc_ver in $cltc_rawls ; do
583      if  expr "$cltc_ver" : $cltc_verPat >/dev/null 2>&1 ; then
584        cltc_filter="$cltc_filter $cltc_ver"
585      fi
586    done
587
588    # echo "Filtered ls: $cltc_filter"
589
590    cltc_cnt=`echo $cltc_filter | wc -w | sed -e 's/ //g'`
591    cltc_cnt=`expr $cltc_cnt - 1`
592  else
593    cltc_cnt=0
594  fi
595
596  echo $cltc_cnt
597}
598
599# Function to compare the versions in a pair of URLs for equality. The criteria
600# is that the major and minor versions match. In theory, the release should
601# not matter. Probably should be a parameter.
602# usage: compareURLVersions <url1> <url2>
603
604compareURLVersions ()
605{
606  url1_major=`extractMajorFromURL $1`
607  url1_minor=`extractMinorFromURL $1`
608  url2_major=`extractMajorFromURL $2`
609  url2_minor=`extractMinorFromURL $2`
610
611  if test $url1_major = $url2_major &&
612     test $url1_minor = $url2_minor ; then
613    echo "yes"
614  else
615    echo "no"
616  fi
617}
618
Note: See TracBrowser for help on using the repository browser.