source: trunk/coin-functions @ 1556

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

New scripts for generating stable versions. Significantly different
architecture; see the BuildTools? posting 100602. set_externals is modified to
conform to the new architecture. Be careful!

File size: 10.2 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
69# Extract the entire version string from a stable or release URL. Returns a
70# null string if handed a trunk URL or if there's no version in the URL.
71# usage: version=`extractVersionFromURL $svnURL`
72
73extractVersionFromURL ()
74{
75  if expr "$1" : '.*/stable/.*' 2>&1 >/dev/null ||
76     expr "$1" : '.*/releases/.*' 2>&1 >/dev/null ; then
77    evfu_verPat='\([0-9.][0-9.]*\)'
78    evfu_sfxPat='.*$'
79    case "$1" in
80      */Data/stable/* | */Data/releases/* )
81          evfu_pfxPat='svn/Data/[^/][^/]*/'
82          ;;
83      */ThirdParty/* )
84          evfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
85          ;;
86      *)
87          evfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
88          ;;
89    esac
90    evfu_verVer=`echo $1 | sed -n -e 's|.*/'$evfu_pfxPat$evfu_verPat$evfu_sfxPat'|\1|p'`
91    echo "$evfu_verVer"
92  else
93    echo ""
94  fi
95}
96
97# Replace the entire version string from a stable or release URL. A trunk
98# URL will be unmodified. newRev will not be accessed unless the URL is a
99# release.
100# usage: newURL=`replaceVersionInURL $oldURL $newMajor $newMinor $newRev`
101
102replaceVersionInURL ()
103{
104  if expr "$1" : '.*/stable/.*' 2>&1 >/dev/null ; then
105    rviu_newVersion=$2.$3
106  elif expr "$1" : '.*/releases/.*' 2>&1 >/dev/null ; then
107    rviu_newVersion=$2.$3.$4
108  else
109    rviu_newVersion=
110    rviu_newURL=$1
111  fi
112  if test -n "$rviu_newVersion" ; then
113    rviu_newURL=`echo $1 | sed -n -e 's|^\(.*\)/[0-9][0-9.]*\(.*\)$|\1/'$rviu_newVersion'\2|p'`
114  fi
115  echo $rviu_newURL
116}
117
118# Extract the major version number from a stable or release URL. Returns -1 if
119# handed a trunk URL or if there's no version in the URL
120# usage: majVer=`extractMajorFromURL $svnURL`
121
122extractMajorFromURL ()
123{
124  if expr "$1" : '.*/stable/.*' 2>&1 >/dev/null ||
125     expr "$1" : '.*/releases/.*' 2>&1 >/dev/null ; then
126    ejfu_majPat='\([0-9][0-9]*\)'
127    ejfu_sfxPat='\.[0-9][0-9]*.*$'
128    case "$1" in
129      */Data/stable/* | */Data/releases/* )
130          ejfu_pfxPat='svn/Data/[^/][^/]*/'
131          ;;
132      */ThirdParty/* )
133          ejfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
134          ;;
135      *)
136          ejfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
137          ;;
138    esac
139    ejfu_majVer=`echo $1 | sed -n -e 's|.*/'$ejfu_pfxPat$ejfu_majPat$ejfu_sfxPat'|\1|p'`
140    echo "$ejfu_majVer"
141  else
142    echo "-1"
143  fi
144}
145
146# Extract the minor version number from a stable or release URL. Returns -1 if
147# handed a trunk URL or if there's no version in the URL.
148# usage: minVer=`extractMinorFromURL $svnURL`
149
150extractMinorFromURL ()
151{
152  if expr "$1" : '.*/stable/.*' 2>&1 >/dev/null ||
153     expr "$1" : '.*/releases/.*' 2>&1 >/dev/null ; then
154    emfu_minPat='[0-9][0-9]*\.\([0-9][0-9]*\)'
155    emfu_sfxPat='.*$'
156    case "$1" in
157      */Data/stable/* | */Data/releases/* )
158          emfu_pfxPat='svn/Data/[^/][^/]*/'
159          ;;
160      */ThirdParty/* )
161          emfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
162          ;;
163      *)
164          emfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
165          ;;
166    esac
167    emfu_minVer=`echo $1 | sed -n -e 's|.*/'$emfu_pfxPat$emfu_minPat$emfu_sfxPat'|\1|p'`
168    echo "$emfu_minVer"
169  else
170    echo "-1"
171  fi
172}
173
174# Extract the release (revision) number from a release URL. Returns -1 if
175# handed a trunk or stable URL
176# usage: minVer=`extractReleaseFromURL $svnURL`
177
178extractReleaseFromURL ()
179{
180  if expr "$1" : '.*/releases/.*' 2>&1 >/dev/null ; then
181    erfu_relPat='[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)'
182    erfu_sfxPat='.*$'
183    case "$1" in
184      */Data/releases/* )
185          erfu_pfxPat='svn/Data/[^/][^/]*/'
186          ;;
187      */ThirdParty/* )
188          erfu_pfxPat='svn/BuildTools/ThirdParty/[^/][^/]*/[^/][^/]*/'
189          ;;
190      *)
191          erfu_pfxPat='svn/[^/][^/]*/[^/][^/]*/'
192          ;;
193    esac
194    erfu_relVer=`echo $1 | sed -n -e 's|.*/'$erfu_pfxPat$erfu_relPat$erfu_sfxPat'|\1|p'`
195    echo "$erfu_relVer"
196  else
197    echo "-1"
198  fi
199}
200
201# Now some functions to locate the highest-numbered stable or release.
202
203# Return the URL of the most recent stable branch matching the parameters.
204# A value of -1 for major or minor version is interpreted as `highest number'
205# usage: stableURL=`bestStable <URL> <major>`
206
207bestStable ()
208{ bstb_URL=$1
209  bstb_majVer=$2
210
211  # Construct a URL to send to the repository to list the stable branches.
212
213  bstb_baseURL=`extractBaseURL $bstb_URL`
214  bstb_proj=`extractProjFromURL $bstb_URL`
215
216  case "$bstb_URL" in
217    */Data/* )
218        bstb_listURL=$bstb_baseURL/Data/stable
219        ;;
220    */ThirdParty/* )
221        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/stable
222        ;;
223    * )
224        bstb_listURL=$bstb_baseURL/$bstb_proj/stable
225        ;;
226  esac
227
228  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2`
229
230  # echo "Raw ls: $bstb_rawls"
231
232  # Filter the list of stable branches to remove any that do not match the
233  # requested major version.
234
235  bstb_verPat='[0-9][0-9]*/'
236  if test "$bstb_majVer" != "-1" ; then
237    bstb_verPat=$bstb_majVer'\.[0-9][0-9]*'
238  else
239    bstb_verPat='[0-9][0-9.]*'
240  fi
241  bstb_filter=
242  for bstb_ver in $bstb_rawls ; do
243    if  expr "$bstb_ver" : $bstb_verPat 2>&1 >/dev/null ; then
244      bstb_filter="$bstb_filter $bstb_ver"
245    fi
246  done
247
248  # echo "Filtered ls: $bstb_filter"
249
250  # If there are any candidates left ...
251
252  bstb_bestURL=
253  if test -n "$bstb_filter" ; then
254
255    # If we're dealing with Data, we have to work a bit harder to find our
256    # project. See if any of the filtered candidates contain the correct
257    # project.
258
259    if expr "$bstb_URL" : '.*/Data/.*' 2>&1 >/dev/null ; then
260      bstb_projPat='.*'$bstb_proj'/.*'
261      # echo "Pattern: $bstb_projPat"
262      for bstb_ver in $bstb_filter ; do
263        if  expr "$bstb_ver" : $bstb_verPat 2>&1 >/dev/null ; then
264          # echo "  url: $bstb_listURL/$bstb_ver"
265          bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
266          # echo "  result: $bstb_svnls2"
267          if expr "$bstb_svnls2" : $bstb_projPat 2>&1 >/dev/null ; then
268            bstb_best=$bstb_ver
269            # echo "  best: $bstb_best"
270            break
271          fi
272        fi
273      done
274      bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
275    else
276      bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
277      bstb_bestURL=$bstb_listURL/$bstb_bestURL
278    fi
279
280  fi
281
282  echo $bstb_bestURL
283}
284
285# Return the URL of the most recent release matching the parameters.
286# A value of -1 for major or minor version is interpreted as `highest number'
287# usage: releaseURL=`bestRelease <URL> <major> <minor>`
288
289bestRelease ()
290{ bstb_URL=$1
291  bstb_majVer=$2
292  bstb_minVer=$3
293
294  # Construct a URL to send to the repository to list the releases.
295
296  bstb_baseURL=`extractBaseURL $bstb_URL`
297  bstb_proj=`extractProjFromURL $bstb_URL`
298
299  case "$bstb_URL" in
300    */Data/* )
301        bstb_listURL=$bstb_baseURL/Data/releases
302        ;;
303    */ThirdParty/* )
304        bstb_listURL=$bstb_baseURL/BuildTools/ThirdParty/$bstb_proj/releases
305        ;;
306    * )
307        bstb_listURL=$bstb_baseURL/$bstb_proj/releases
308        ;;
309  esac
310
311  bstb_rawls=`svn list $bstb_listURL | sort -nr -t. -k1,1 -k2,2 -k3,3`
312
313  # echo "Raw ls: $bstb_rawls"
314
315  # Filter the list of releases to remove any that do not match the
316  # requested major and minor version.
317
318  if test "$bstb_majVer" != "-1" ; then
319    bstb_verPat=$bstb_majVer'\.'
320  else
321    bstb_verPat='[0-9][0-9]*\.'
322  fi
323  if test "$bstb_minVer" != "-1" ; then
324    bstb_verPat="${bstb_verPat}$bstb_minVer"
325  else
326    bstb_verPat="${bstb_verPat}"'[0-9][0-9]*'
327  fi
328  bstb_verPat="${bstb_verPat}"'\.[0-9][0-9]*'
329  # echo "Version pattern: $bstb_verPat"
330  bstb_filter=
331  for bstb_ver in $bstb_rawls ; do
332    if  expr "$bstb_ver" : $bstb_verPat 2>&1 >/dev/null ; then
333      bstb_filter="$bstb_filter $bstb_ver"
334    fi
335  done
336
337  # echo "Filtered ls: $bstb_filter"
338
339  # If there are any candidates left ...
340
341  bstb_bestURL=
342  if test -n "$bstb_filter" ; then
343
344    # If we're dealing with Data, we have to work a bit harder to find our
345    # project. See if any of the filtered candidates contain the correct
346    # project.
347
348    if expr "$bstb_URL" : '.*/Data/.*' 2>&1 >/dev/null ; then
349      bstb_projPat='.*'$bstb_proj'/.*'
350      # echo "Pattern: $bstb_projPat"
351      for bstb_ver in $bstb_filter ; do
352        if  expr "$bstb_ver" : $bstb_verPat 2>&1 >/dev/null ; then
353          # echo "  url: $bstb_listURL/$bstb_ver"
354          bstb_svnls2="`svn list $bstb_listURL/$bstb_ver`"
355          # echo "  result: $bstb_svnls2"
356          if expr "$bstb_svnls2" : $bstb_projPat 2>&1 >/dev/null ; then
357            bstb_best=$bstb_ver
358            # echo "  best: $bstb_best"
359            break
360          fi
361        fi
362      done
363      bstb_bestURL=$bstb_listURL/$bstb_best$bstb_proj
364    else
365      bstb_bestURL=`echo $bstb_filter | sed -n -e 's|\([^/]*/\).*$|\1|p'`
366      bstb_bestURL=$bstb_listURL/$bstb_bestURL
367    fi
368
369  fi
370
371  echo $bstb_bestURL
372}
Note: See TracBrowser for help on using the repository browser.