source: trunk/coin-functions @ 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.

File size: 12.6 KB
Line 
1
2# Utility function definitions for the various COIN scripts.
3
4# Functions to disassemble svn URLs and extract relevant bits. Complicated
5# because we have to account for trunk/stable/release and for the variant
6# syntax of Data and ThirdParty URLs. For your normal project, it's
7#   https://projects.coin-or.org/svn/ProjName/trunk
8#   https://projects.coin-or.org/svn/ProjName/stable/M.m
9#   https://projects.coin-or.org/svn/ProjName/releases/M.m.r
10# For ThirdParty, it's just like a normal project, except the prefix string
11# is longer:
12#   https://projects.coin-or.org/svn/BuildTools/ThirdParty/ProjName
13# Data is the real pain, with this form:
14#  https://projects.coin-or.org/svn/Data/trunk/ProjName
15#  https://projects.coin-or.org/svn/Data/stable/M.m/ProjName
16#  https://projects.coin-or.org/svn/Data/releases/M.m.r/ProjName
17
18# Extract the COIN base from the URL, up to svn. Just in case it ever changes.
19# usage: baseURL=`extractBaseURL $svnURL`
20
21extractBaseURL ()
22{
23  exbu_baseURL=`echo $1 | sed -n -e 's|\(.*/svn\)/.*$|\1|p'`
24  echo "$exbu_baseURL"
25}
26
27
28# Extract branch type (trunk/stable/release) from the URL.
29# usage: branchType=`extractTypeFromURL $svnURL`
30
31extractTypeFromURL ()
32{
33  etfu_type="invalid"
34  case "$1" in
35    */trunk* ) etfu_type=trunk ;;
36    */stable/* ) etfu_type=stable ;;
37    */releases/* ) etfu_type=releases ;;
38  esac
39  echo $etfu_type
40}
41
42
43# Extract the project from a svn URL
44# usage: projName=`extractProjFromURL $svnURL`
45
46extractProjFromURL ()
47{
48  epfu_projPat='\([^/][^/]*\)'
49  epfu_sfxPat='.*$'
50  case "$1" in
51    */Data/trunk/* )
52        epfu_pfxPat=svn/Data/trunk/
53        ;;
54    */Data/stable/* | */Data/releases/* )
55        epfu_pfxPat='svn/Data/[^/][^/]*/[0-9][0-9.]*/'
56        ;;
57    */ThirdParty/* )
58        epfu_pfxPat=svn/BuildTools/ThirdParty/
59        ;;
60    *)
61        epfu_pfxPat=svn/
62        ;;
63  esac
64  epfu_projName=`echo $1 | sed -n -e 's|.*/'$epfu_pfxPat$epfu_projPat$epfu_sfxPat'|\1|p'`
65  echo "$epfu_projName"
66}
67
68# Extract the tail (directory) from an external URL. Relevant only for normal
69# projects, where the external will be a subdirectory of the project. Returns
70# null for Data/ThirdParty/BuildTools.
71# usage: projName=`extractTailFromExt $extURL`
72
73extractTailFromExt ()
74{
75  etfe_tail=
76  case "$1" in
77    */Data/* )
78        ;;
79    */BuildTools/ThirdParty/* )
80        ;;
81    */BuildTools/* )
82        ;;
83    *)
84        etfe_pfxPat=
85        case "$1" in
86          */trunk/* )
87              etfe_pfxPat='.*/trunk/'
88              ;;
89          */stable/* )
90              etfe_pfxPat='.*/stable/[0-9][0-9.]*/'
91              ;;
92          */releases/* )
93              etfe_pfxPat='.*/releases/[0-9][0-9.]*/'
94              ;;
95        esac
96        etfe_tail=`echo $1 | sed -n -e 's|'$etfe_pfxPat'\(.*\)|\1|p'`
97        ;;
98  esac
99  echo "$etfe_tail"
100}
101
102
103# Extract the entire version string from a stable or release URL. Returns a
104# null string if handed a trunk URL or if there's no version in the URL.
105# usage: version=`extractVersionFromURL $svnURL`
106
107extractVersionFromURL ()
108{
109  if expr "$1" : '.*/stable/.*' >/dev/null 2>&1 ||
110     expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
111    evfu_verPat='\([0-9.][0-9.]*\)'
112    evfu_sfxPat='.*$'
113    case "$1" in
114      */Data/stable/* | */Data/releases/* )
115          evfu_pfxPat='svn/Data/[^/][^/]*/'
116          ;;
117      */ThirdParty/* )
118          evfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
119          ;;
120      *)
121          evfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
122          ;;
123    esac
124    evfu_verVer=`echo $1 | sed -n -e 's|.*/'$evfu_pfxPat$evfu_verPat$evfu_sfxPat'|\1|p'`
125    echo "$evfu_verVer"
126  else
127    echo ""
128  fi
129}
130
131# Replace the entire version string from a stable or release URL. A trunk
132# URL will be unmodified. newRev will not be accessed unless the URL is a
133# release.
134# usage: newURL=`replaceVersionInURL $oldURL $newMajor $newMinor $newRev`
135
136replaceVersionInURL ()
137{
138  if expr "$1" : '.*/stable/.*' >/dev/null 2>&1 ; then
139    rviu_newVersion=$2.$3
140  elif expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
141    rviu_newVersion=$2.$3.$4
142  else
143    rviu_newVersion=
144    rviu_newURL=$1
145  fi
146  if test -n "$rviu_newVersion" ; then
147    rviu_newURL=`echo $1 | sed -n -e 's|^\(.*\)/[0-9][0-9.]*\(.*\)$|\1/'$rviu_newVersion'\2|p'`
148  fi
149  echo $rviu_newURL
150}
151
152# Extract the major version number from a stable or release URL. Returns -1 if
153# handed a trunk URL or if there's no version in the URL
154# usage: majVer=`extractMajorFromURL $svnURL`
155
156extractMajorFromURL ()
157{
158  if expr "$1" : '.*/stable/.*' >/dev/null 2>&1 ||
159     expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
160    ejfu_majPat='\([0-9][0-9]*\)'
161    ejfu_sfxPat='\.[0-9][0-9]*.*$'
162    case "$1" in
163      */Data/stable/* | */Data/releases/* )
164          ejfu_pfxPat='svn/Data/[^/][^/]*/'
165          ;;
166      */ThirdParty/* )
167          ejfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
168          ;;
169      *)
170          ejfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
171          ;;
172    esac
173    ejfu_majVer=`echo $1 | sed -n -e 's|.*/'$ejfu_pfxPat$ejfu_majPat$ejfu_sfxPat'|\1|p'`
174    echo "$ejfu_majVer"
175  else
176    echo "-1"
177  fi
178}
179
180# Extract the minor version number from a stable or release URL. Returns -1 if
181# handed a trunk URL or if there's no version in the URL.
182# usage: minVer=`extractMinorFromURL $svnURL`
183
184extractMinorFromURL ()
185{
186  if expr "$1" : '.*/stable/.*' >/dev/null 2>&1 ||
187     expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
188    emfu_minPat='[0-9][0-9]*\.\([0-9][0-9]*\)'
189    emfu_sfxPat='.*$'
190    case "$1" in
191      */Data/stable/* | */Data/releases/* )
192          emfu_pfxPat='svn/Data/[^/][^/]*/'
193          ;;
194      */ThirdParty/* )
195          emfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
196          ;;
197      *)
198          emfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
199          ;;
200    esac
201    emfu_minVer=`echo $1 | sed -n -e 's|.*/'$emfu_pfxPat$emfu_minPat$emfu_sfxPat'|\1|p'`
202    echo "$emfu_minVer"
203  else
204    echo "-1"
205  fi
206}
207
208# Extract the release (revision) number from a release URL. Returns -1 if
209# handed a trunk or stable URL
210# usage: minVer=`extractReleaseFromURL $svnURL`
211
212extractReleaseFromURL ()
213{
214  if expr "$1" : '.*/releases/.*' >/dev/null 2>&1 ; then
215    erfu_relPat='[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)'
216    erfu_sfxPat='.*$'
217    case "$1" in
218      */Data/releases/* )
219          erfu_pfxPat='svn/Data/[^/][^/]*/'
220          ;;
221      */ThirdParty/* )
222          erfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
223          ;;
224      *)
225          erfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
226          ;;
227    esac
228    erfu_relVer=`echo $1 | sed -n -e 's|.*/'$erfu_pfxPat$erfu_relPat$erfu_sfxPat'|\1|p'`
229    echo "$erfu_relVer"
230  else
231    echo "-1"
232  fi
233}
234
235# Now some functions to locate the highest-numbered stable or release.
236
237# Return the URL of the most recent stable branch matching the parameters.
238# A value of -1 for major or minor version is interpreted as `highest number'
239# usage: stableURL=`bestStable <URL> <major>`
240
241bestStable ()
242{ bstb_URL=$1
243  bstb_majVer=$2
244
245  # Construct a URL to send to the repository to list the stable branches.
246
247  bstb_baseURL=`extractBaseURL $bstb_URL`
248  bstb_proj=`extractProjFromURL $bstb_URL`
249
250  case "$bstb_URL" in
251    */Data/* )
252        bstb_listURL=$bstb_baseURL/Data/stable
253        ;;
254    */ThirdParty/* )
255        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/stable
256        ;;
257    * )
258        bstb_listURL=$bstb_baseURL/$bstb_proj/stable
259        ;;
260  esac
261
262  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2`
263
264  # echo "Raw ls: $bstb_rawls"
265
266  # Filter the list of stable branches to remove any that do not match the
267  # requested major version.
268
269  bstb_verPat='[0-9][0-9]*/'
270  if test "$bstb_majVer" != "-1" ; then
271    bstb_verPat=$bstb_majVer'\.[0-9][0-9]*'
272  else
273    bstb_verPat='[0-9][0-9.]*'
274  fi
275  bstb_filter=
276  for bstb_ver in $bstb_rawls ; do
277    if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
278      bstb_filter="$bstb_filter $bstb_ver"
279    fi
280  done
281
282  # echo "Filtered ls: $bstb_filter"
283
284  # If there are any candidates left ...
285
286  bstb_bestURL=
287  if test -n "$bstb_filter" ; then
288
289    # If we're dealing with Data, we have to work a bit harder to find our
290    # project. See if any of the filtered candidates contain the correct
291    # project.
292
293    if expr "$bstb_URL" : '.*/Data/.*' >/dev/null 2>&1 ; then
294      bstb_projPat='.*'$bstb_proj'/.*'
295      # echo "Pattern: $bstb_projPat"
296      for bstb_ver in $bstb_filter ; do
297        if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
298          # echo "  url: $bstb_listURL/$bstb_ver"
299          bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
300          # echo "  result: $bstb_svnls2"
301          if expr "$bstb_svnls2" : $bstb_projPat >/dev/null 2>&1 ; then
302            bstb_best=$bstb_ver
303            # echo "  best: $bstb_best"
304            break
305          fi
306        fi
307      done
308      bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
309    else
310      bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
311      bstb_bestURL=$bstb_listURL/$bstb_bestURL
312    fi
313
314  fi
315
316  echo $bstb_bestURL
317}
318
319# Return the URL of the most recent release matching the parameters.
320# A value of -1 for major or minor version is interpreted as `highest number'
321# usage: releaseURL=`bestRelease <URL> <major> <minor>`
322
323bestRelease ()
324{ bstb_URL=$1
325  bstb_majVer=$2
326  bstb_minVer=$3
327
328  # Construct a URL to send to the repository to list the releases.
329
330  bstb_baseURL=`extractBaseURL $bstb_URL`
331  bstb_proj=`extractProjFromURL $bstb_URL`
332
333  case "$bstb_URL" in
334    */Data/* )
335        bstb_listURL=$bstb_baseURL/Data/releases
336        ;;
337    */ThirdParty/* )
338        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/releases
339        ;;
340    * )
341        bstb_listURL=$bstb_baseURL/$bstb_proj/releases
342        ;;
343  esac
344
345  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2 -k3,3`
346
347  # echo "Raw ls: $bstb_rawls"
348
349  # Filter the list of releases to remove any that do not match the
350  # requested major and minor version.
351
352  if test "$bstb_majVer" != "-1" ; then
353    bstb_verPat=$bstb_majVer'\.'
354  else
355    bstb_verPat='[0-9][0-9]*\.'
356  fi
357  if test "$bstb_minVer" != "-1" ; then
358    bstb_verPat="${bstb_verPat}$bstb_minVer"
359  else
360    bstb_verPat="${bstb_verPat}"'[0-9][0-9]*'
361  fi
362  bstb_verPat="${bstb_verPat}"'\.[0-9][0-9]*'
363  # echo "Version pattern: $bstb_verPat"
364  bstb_filter=
365  for bstb_ver in $bstb_rawls ; do
366    if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
367      bstb_filter="$bstb_filter $bstb_ver"
368    fi
369  done
370
371  # echo "Filtered ls: $bstb_filter"
372
373  # If there are any candidates left ...
374
375  bstb_bestURL=
376  if test -n "$bstb_filter" ; then
377
378    # If we're dealing with Data, we have to work a bit harder to find our
379    # project. See if any of the filtered candidates contain the correct
380    # project.
381
382    if expr "$bstb_URL" : '.*/Data/.*' >/dev/null 2>&1 ; then
383      bstb_projPat='.*'$bstb_proj'/.*'
384      # echo "Pattern: $bstb_projPat"
385      for bstb_ver in $bstb_filter ; do
386        if  expr "$bstb_ver" : $bstb_verPat >/dev/null 2>&1 ; then
387          # echo "  url: $bstb_listURL/$bstb_ver"
388          bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
389          # echo "  result: $bstb_svnls2"
390          if expr "$bstb_svnls2" : $bstb_projPat >/dev/null 2>&1 ; then
391            bstb_best=$bstb_ver
392            # echo "  best: $bstb_best"
393            break
394          fi
395        fi
396      done
397      bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
398    else
399      bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
400      bstb_bestURL=$bstb_listURL/$bstb_bestURL
401    fi
402
403  fi
404
405  echo $bstb_bestURL
406}
407
408# Count the total number of stable branches for the project for the specified
409# major version number (libtool age). A major version number of -1 means all
410# stable branches (libtool current; see next function). Returns 0 if handed
411# a trunk url, or if the url is Data or BuildTools itself.
412# usage: calcLibtoolAge <svnURL> <major>
413
414calcLibtoolAge ()
415{ cltc_URL=$1
416  cltc_majVer=$2
417
418  # Construct a URL to send to the repository to list the stable branches.
419
420  cltc_baseURL=`extractBaseURL $cltc_URL`
421  cltc_proj=`extractProjFromURL $cltc_URL`
422
423  case "$cltc_URL" in
424    */Data/* )
425        cltc_listURL=
426        ;;
427    */ThirdParty/* )
428        cltc_listURL=$cltc_baseURL/BuildTools/ThirdParty/$cltc_proj/stable
429        ;;
430    */BuildTools/* )
431        cltc_listURL=
432        ;;
433    * )
434        cltc_listURL=$cltc_baseURL/$cltc_proj/stable
435        ;;
436  esac
437
438  # Run an ls and filter for standard stable branches (M.m)
439  if test -n "$cltc_listURL" ; then
440    cltc_rawls=`svn list $cltc_listURL | sed -n -e '/[0-9]\.[0-9]/p'`
441
442    # echo "Raw ls: $cltc_rawls"
443
444    # Filter the list of stable branches to remove any that do not match the
445    # requested major version. -1 means `any major version', hence no filter.
446
447    cltc_verPat='[0-9][0-9]*/'
448    if test "$cltc_majVer" != "-1" ; then
449      cltc_verPat=$cltc_majVer'\.[0-9][0-9]*'
450    else
451      cltc_verPat='[0-9][0-9.]*'
452    fi
453    cltc_filter=
454    for cltc_ver in $cltc_rawls ; do
455      if  expr "$cltc_ver" : $cltc_verPat >/dev/null 2>&1 ; then
456        cltc_filter="$cltc_filter $cltc_ver"
457      fi
458    done
459
460    # echo "Filtered ls: $cltc_filter"
461
462    cltc_cnt=`echo $cltc_filter | wc -w | sed -e 's/ //g'`
463  else
464    cltc_cnt=0
465  fi
466
467  echo $cltc_cnt
468}
469
470# Count the total number of stable branches (libtool current). See comments
471# above for calcLibtoolAge.
472# usage: calcLibtoolCurrent <url>
473calcLibtoolCurrent ()
474{ calcLibtoolAge $1 -1
475}
476
Note: See TracBrowser for help on using the repository browser.