forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctvspec.pl
More file actions
360 lines (338 loc) · 10.6 KB
/
ctvspec.pl
File metadata and controls
360 lines (338 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
require "$tool/built/include/ctutils.pl" ;
# read a .vspec file into a map
# $_[0] = project
# on exit $ctvspecs{} will contain the data
#
# vspec format:
# tag:type:other data
#
# type: ref, root, vroot, croot
# other data:
# ref: name=_____ - required, take to refference
# root: path=_____ - required, path of tree root
# vroot: name=_____ - optional, name of view to use (if not tag)
# croot: path=_____ - required, local path of tree root
# server=_____ - required, CVS server string, ',' for ':'
sub CTReadVSpec {
&CTUDebug( "reading vspec file for project " . $_[0] . "\n" ) ;
local( $ret ) = "" ;
local( $thisproj ) = $_[0] ;
if ( -e "$ctvspec_path/$thisproj.vspec" ) {
%ctvspecs = () ;
local( *SPECFILE ) ;
open( SPECFILE, "<$ctvspec_path/$thisproj.vspec" ) ;
local( @partlist ) ;
while ( $_ = <SPECFILE> ) {
s/\n$// ;
@partlist = split( /\#/ ) ;
$_ = $partlist[0] ;
if ( $_ ne "" ) {
@partlist = split( /:/ );
local( $tag ) = $partlist[0] ;
shift( @partlist ) ;
local( $spec ) = join( ":", @partlist ) ;
if ( &CTValidateSpec( $spec ) ) {
$ctvspecs{$tag} = $spec ;
if ( $ctdebug ) {
print STDERR "tag(" . $tag . ") = " . $spec . "\n" ;
}
}
}
}
close( SPECFILE ) ;
$ctvspec_read = $_[0] ;
} else {
print STDERR "CTReadVSpec: cannot locate '$ctvspec_path/$thisproj.vspec'\n" ;
print STDERR "(did you forget to run the \$WINTOOLS/cp_vspec script?)\n" ;
}
}
# given a spec line return it's type
# $_[0] = spec line
sub CTSpecType {
local( @speclist ) = split( /:/, $_[0] ) ;
$speclist[0] ;
}
# given a spec line return it's options if any
# $_[0] = spec line
sub CTSpecOptions {
local( @speclist ) = split( /:/, $_[0] ) ;
shift( @speclist ) ;
join( ":", @speclist ) ;
}
# given the options part of a spec line, find a given option
# $_[0] = options line
# $_[1] = desired option
sub CTSpecFindOption {
local( $ret ) = "" ;
local( @options ) = split( /:/, $_[0] ) ;
local( $item ) ;
local( @itemlist ) ;
foreach $item ( @options ) {
@itemlist = split( /=/, $item ) ;
if ( $itemlist[0] eq $_[1] ) {
$ret = $itemlist[1] ;
}
}
$ret ;
}
# resolve a final spec line for a given flavor
# $_[0] = project
# $_[1] = flavor
sub CTResolveSpec {
&CTUDebug( "in CTResolveSpec\n" ) ;
local( $proj ) = $_[0] ;
$proj =~ tr/A-Z/a-z/ ;
if ( $ctvspec_read ne $proj ) {
&CTReadVSpec( $proj ) ;
}
local( $spec ) = $ctvspecs{$_[1]} ;
local( $ret ) = "" ;
if ( $spec ne "" ) {
local( $type ) = &CTSpecType( $spec ) ;
local( @speclist ) = split( /:/, &CTSpecOptions( $spec ) ) ;
if ( $type eq "ref" ) {
local( @optionlist ) = split( /=/, $speclist[0] ) ;
if ( $optionlist[0] ne "name" ) {
print STDERR "bad data attached to flavor " . $_[1] .
" of project " . $proj . "\n" ;
} else {
local( $tmp ) = &CTUShellEval( $optionlist[1] ) ;
if ( $ctdebug ) {
print STDERR "resolved a 'ref' to " . $tmp .
", recuring\n" ;
}
$ret = &CTResolveSpec( $proj, $tmp ) ;
}
} else {
$ret = $spec ;
}
}
if ( $ret eq "" ) {
print STDERR "unknown flavor " . $_[1] . " of project " . $proj .
"\n" ;
}
&CTUDebug( "out of CTResolveSpec\n" ) ;
$ret ;
}
# resolve the final name for a given flavor
# $_[0] = project
# $_[1] = flavor
sub CTResolveSpecName {
&CTUDebug( "in CTResolveSpecName\n" ) ;
local( $proj ) = $_[0] ;
$proj =~ tr/A-Z/a-z/ ;
if ( $ctvspec_read ne $proj ) {
&CTReadVSpec( $proj ) ;
}
local( $spec ) = $ctvspecs{$_[1]} ;
local( $ret ) = $_[1] ;
if ( $spec ne "" ) {
local( $type ) = &CTSpecType( $spec ) ;
local( @speclist ) = split( /:/, &CTSpecOptions( $spec ) ) ;
if ( $type eq "ref" ) {
local( @optionlist ) = split( /=/, $speclist[0] ) ;
if ( $optionlist[0] ne "name" ) {
print STDERR "bad data attached to flavor " . $_[1] .
" of project " . $proj . "\n" ;
} else {
local( $tmp ) = &CTUShellEval( $optionlist[1] ) ;
if ( $ctdebug ) {
print STDERR "resolved a 'ref' to " . $tmp .
", recuring\n" ;
}
$ret = &CTResolveSpecName( $proj, $tmp ) ;
}
}
}
if ( $ret eq "" ) {
print STDERR "unknown flavor " . $_[1] . " of project " . $proj .
"\n" ;
}
&CTUDebug( "out of CTResolveSpecName\n" ) ;
$ret ;
}
# validate a spec line
# $_[0] = spec line
sub CTValidateSpec {
local( $ret ) = 0 ;
local( $type ) = &CTSpecType( $_[0] ) ;
local( @speclist ) = split( /:/, &CTSpecOptions( $_[0] ) ) ;
local( $have_error ) = 0 ;
local( $item ) ;
local( @itemlist ) ;
if ( $type eq "ref" ) {
local( $have_name ) = 0 ;
foreach $item ( @speclist ) {
@itemlist = split( /=/, $item ) ;
if ( $itemlist[0] eq "name" ) {
if ( $have_name ) {
$have_error = 1;
&CTUDebug( "multiple name options on 'ref'\n" ) ;
}
$have_name = 1;
} else {
&CTUDebug( "invalid option on 'ref' = " . $item . "\n" ) ;
$have_error = 1 ;
}
}
if ( ! $have_error ) {
if ( $have_name ) {
$ret = 1 ;
}
}
} elsif ( $type eq "root" ) {
local( $have_path ) = 0 ;
foreach $item ( @speclist ) {
@itemlist = split( /=/, $item ) ;
if ( $itemlist[0] eq "path" ) {
if ( $have_path ) {
$have_error = 1 ;
&CTUDebug( "multiple path options on 'root'\n" ) ;
}
$have_path = 1 ;
} else {
&CTUDebug( "invalid option on 'root' = " . $item . "\n" ) ;
$have_error = 1 ;
}
}
if ( ! $have_error ) {
if ( $have_path ) {
$ret = 1 ;
}
}
} elsif ( $type eq "vroot" ) {
local( $have_name ) = 0 ;
foreach $item ( @speclist ) {
@itemlist = split( /=/, $item ) ;
if ( $itemlist[0] eq "name" ) {
if ( $have_name ) {
$have_error = 1 ;
&CTUDebug( "multiple name options on 'vroot'\n" ) ;
}
$have_name = 1 ;
} else {
&CTUDebug( "invalid option on 'vroot' = " . $item . "\n" ) ;
$have_error = 1 ;
}
}
if ( ! $have_error ) {
$ret = 1 ;
}
} elsif ( $type eq "croot" ) {
local( $have_path ) = 0 ;
local( $have_server ) = 0 ;
foreach $item ( @speclist ) {
@itemlist = split( /=/, $item ) ;
if ( $itemlist[0] eq "path" ) {
if ( $have_path ) {
$have_error = 1 ;
&CTUDebug( "multiple path options on 'croot'\n" ) ;
}
$have_path = 1 ;
} elsif ( $itemlist[0] eq "server" ) {
if ( $have_server ) {
$have_error = 1 ;
&CTUDebug( "multiple server options on 'croot'\n" ) ;
}
$have_server = 1 ;
} else {
&CTUDebug( "invalid option on 'croot' = " . $item . "\n" ) ;
$have_error = 1 ;
}
}
if ( ! $have_error ) {
if ( $have_path && $have_server ) {
$ret = 1 ;
}
}
} else {
&CTUDebug( "unknow spec type '" . $speclist[0] . "'\n" ) ;
}
$ret ;
}
# get a list of all projects
sub CTListAllProjects {
&CTUDebug( "in CTListAllProjects\n" ) ;
local( $ret ) = "" ;
local( $done ) = 0 ;
local( *DIRFILES ) ;
open( DIRFILES, "(cd $ctvspec_path ; /bin/ls -1 *.vspec ; echo blahblah) |" ) ;
while ( ! $done ) {
$_ = <DIRFILES> ;
s/\n$// ;
if ( $_ eq "blahblah" ) {
$done = 1 ;
} else {
s/.vspec$// ;
if ( $_ ne "" ) {
if ( $ret eq "" ) {
$ret = $_ ;
} else {
$ret = $ret . " " . $_ ;
}
}
}
}
close( DIRFILES ) ;
&CTUDebug( "final list of projects '" . $ret . "'\n" .
"out of CTListAllProjects\n" ) ;
$ret ;
}
# list all flavors of a project
# $_[0] = project
sub CTListAllFlavors {
&CTUDebug( "in CTListAllFlavors\n" ) ;
local( $proj ) = $_[0] ;
$proj =~ tr/A-Z/a-z/ ;
if ( $ctvspec_read ne $proj ) {
&CTReadVSpec( $proj ) ;
}
local( $ret ) = "";
local( $item ) ;
foreach $item ( keys %ctvspecs ) {
if ( $ret eq "" ) {
$ret = $item ;
} else {
$ret = $ret . " " . $item ;
}
}
&CTUDebug( "out of CTListAllFlavors\n" ) ;
$ret ;
}
# given a project and a spec, determine the local root of the project
# $_[0] = project
# $_[1] = flavor
# $_[2] = spec line
sub CTComputeRoot {
&CTUDebug( "in CTComputeRoot\n" ) ;
local( $proj ) = $_[0] ;
$proj =~ tr/A-Z/a-z/ ;
if ( $ctvspec_read ne $proj ) {
&CTReadVSpec( $proj ) ;
}
local( $ret ) = "" ;
local( $type ) = &CTSpecType( $_[2] ) ;
local( $options ) = &CTSpecOptions( $_[2] ) ;
local( $vname ) = &CTResolveSpecName( $proj, $_[1] ) ;
&CTUDebug( "type = '" . $type . "' with options '" . $options . "'\n" ) ;
if ( $type eq "root" ) {
$ret = &CTSpecFindOption( $options, "path" ) ;
} elsif ( $type eq "vroot" ) {
local( $name ) = &CTSpecFindOption( $options, "name" ) ;
if ( $name ne "" ) {
$ret = "/view/$name/vobs/$proj" ;
} else {
$ret = "/view/$vname/vobs/$proj" ;
}
} elsif ( $type eq "croot" ) {
$ret = &CTSpecFindOption( $options, "path" ) ;
} elsif ( $ctdebug) {
print STDERR "unknown flavor type '" . $type . "'\n" ;
}
&CTUDebug( "returning '" . $ret . "'\n" ) ;
&CTUDebug( "out of CTComputeRoot\n" ) ;
$ret ;
}
%ctvspecs = () ;
$ctvspec_read = "" ;
1;