ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.11
Committed: Wed Dec 5 16:09:40 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.10: +113 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 williamc 1.2 # Requirements Doc - just to get ordering info
2     #
3     # Interface
4     # ---------
5     # new(ActiveStore,url[,arch]) : new requirements doc
6     # setup(toolbox): set up the requirements into the specified toolbox object
7     # download(toolbox) : download description files (into toolbox cache)
8     # tools() : Return list of ALL requirements (ordered)
9     # selectedtools() : Return list of only those tools selected
10     # version(tool) : return the version of a given tool
11     # toolurl(tool) : return the url of a given tool
12     # getreqforarch(arch) : Return a RequirementsObject corresponding to the
13     # specified architecture
14     # toolcomment(tool,version) : return the comment string for the specified tool
15     # distributionurl(tool,version) : return the dist info url for the tool
16    
17     package BuildSystem::Requirements;
18     use ActiveDoc::ActiveDoc;
19     use Utilities::Verbose;
20    
21     require 5.004;
22     @ISA=qw(Utilities::Verbose);
23    
24     sub new {
25     my $class=shift;
26     my $self={};
27     bless $self, $class;
28     $self->{dbstore}=shift;
29     $self->{file}=shift;
30     $self->{cache}=$self->{dbstore}->cache();
31     if ( @_ ) {
32     $self->arch(shift);
33     }
34 williamc 1.3 $self->verbose("Initialising a new Requirements Doc");
35 williamc 1.2 $self->{mydocversion}="2.0";
36     $self->{Arch}=1;
37     push @{$self->{ARCHBLOCK}}, $self->{Arch};
38     $self->init($self->{file});
39     return $self;
40     }
41    
42     sub url {
43     my $self=shift;
44     if ( @_ ) {
45     $self->{file}=shift;
46     }
47     return $self->{file}
48     }
49    
50 sashby 1.7 sub setup
51     {
52     my $self=shift;
53     my $toolbox=shift;
54     my $tool;
55    
56     foreach $tool ( $self->selectedtools() )
57     {
58     $self->verbose("Setting Up Tool $tool");
59     $toolbox->toolsetup($tool, $self->version($tool), $self->toolurl($tool));
60     }
61     }
62 williamc 1.2
63     sub tools {
64     my $self=shift;
65     return @{$self->{tools}};
66     }
67    
68 sashby 1.11 # sub selectedtools
69     # {
70     # my $self=shift;
71     # my @toollist=();
72    
73     # foreach $tool ( @{$self->{tools}} )
74     # {
75     # if ( $self->{selected}{$tool} eq "UNSELECTED" )
76     # {
77     # $self->verbose(">> Adding tool $tool to list of selected tools");
78     # push @toollist, $tool;
79     # }
80     # $self->verbose(">> Tool $tool was deselected");
81     # }
82     # return @toollist;
83     # }
84    
85     ##############################################################
86    
87 sashby 1.8 sub selectedtools
88     {
89 sashby 1.11 ###############################################################
90     # selectedtools() #
91     ###############################################################
92     # modified : Wed Dec 5 15:39:39 2001 / SFA #
93     # params : #
94     # : #
95     # : #
96     # : #
97     # function : New version of routine. Return a list of tools #
98     # : that were selected after parsing RequirementsDoc #
99     # : #
100     # : #
101     ###############################################################
102     my $self=shift;
103     my @toolarray = ();
104    
105     # Grab the arrays of tools:
106     my ($toolref,$deseltoolref,$unseltoolref) = $self->grabtools();
107    
108     my @tools = @{$toolref};
109     my @deseltools = @{$deseltoolref};
110     my @unseltools = @{$unseltoolref};
111    
112     if ($#tools == -1)
113     {
114     $self->verbose(">> No tools SELECTED. Checking for DESELECTED tools");
115    
116     # No tools "SELECTED". We return the tools that were "UNSELECTED"
117     # (these are the tools that remain after unwanted tools are deselected):
118     if ($#unseltools != -1)
119     {
120     $self->verbose(">> Using the tools remaining after DESELECTION ops");
121     # The array has elements:
122     return @unseltools;
123     }
124     else
125     {
126     $self->verbose(">> No UNSELECTED tools.....");
127     }
128     }
129     else
130     {
131     # We will return the selected tools but only after checking
132     # for subsequently deselected tools (unlikely but...):
133     foreach $selected (@tools)
134     {
135     # If the tool exists in the deselected tool array, pass.
136     if ( ! grep /$selected/, @deseltools)
137     {
138     push @toolarray, $selected;
139     }
140     else
141     {
142     $self->verbose(">> Tool $selected was subsequently deselected.");
143     }
144     }
145     }
146     return @toolarray;
147     }
148    
149    
150     sub grabtools
151     {
152     ###############################################################
153     # grabtools() #
154     ###############################################################
155     # modified : Wed Dec 5 14:41:56 2001 / SFA #
156     # params : #
157     # : #
158     # : #
159     # : #
160     # function : Loop over the tools read from RequirementsDoc #
161     # : and fill arrays for selected, deselected and #
162     # : unselected tools. #
163     # : #
164     ###############################################################
165 sashby 1.8 my $self=shift;
166     my @toollist=();
167 sashby 1.11 my @deseltoollist=();
168     my @unseltoollist=();
169    
170 sashby 1.8 foreach $tool ( @{$self->{tools}} )
171     {
172     if ( $self->{selected}{$tool} eq "SELECTED" )
173     {
174     push @toollist, $tool;
175     }
176 sashby 1.11 elsif ( $self->{selected}{$tool} eq "DESELECTED" )
177     {
178     push @deseltoollist, $tool;
179     }
180     elsif ( $self->{selected}{$tool} eq "UNSELECTED" )
181     {
182     push @unseltoollist, $tool;
183     }
184     else
185     {
186     $self->verbose(">> Looks like an unknown sel flag for tool ".$tool." ");
187     }
188 sashby 1.8 }
189 sashby 1.11 return \(@toollist, @deseltoollist, @unseltoollist);
190 sashby 1.8 }
191 sashby 1.11
192     ####################################################################
193 williamc 1.2
194     sub toolcomment {
195     my $self=shift;
196     my $tool=shift;
197     my $version=shift;
198    
199     return $self->{reqtext}{$tool}{$version};
200     }
201    
202     sub distributionurl {
203     my $self=shift;
204     my $tool=shift;
205     my $version=shift;
206    
207     return ( defined $self->{dist}{$tool}{$version})?
208     $self->{dist}{$tool}{$version}:undef;
209     }
210    
211     sub version {
212     my $self=shift;
213     my $tool=shift;
214     return $self->{'version'}{$tool};
215     }
216    
217     sub toolurl {
218     my $self=shift;
219     my $tool=shift;
220     return $self->{'url'}{$tool};
221     }
222    
223     sub init {
224     my $self=shift;
225     my $url=shift;
226    
227     my $switch=ActiveDoc::ActiveDoc->new($self->{dbstore});
228     $switch->verbosity($self->verbosity());
229     $switch->url($url);
230     $switch->newparse("ordering");
231     $switch->addbasetags("ordering");
232     $switch->addtag("ordering","Architecture",
233     \&Arch_Start,$self,
234     "", $self,
235     \&Arch_End, $self);
236     $switch->addtag("ordering","Restrict",
237     \&Restrict_start,$self,
238     "", $self,
239     \&Restrict_end, $self);
240     $switch->addtag("ordering","deselect",
241     \&deselect_start,$self,
242     "", $self,
243     "", $self);
244     $switch->addtag("ordering","select",
245     \&select_start,$self,
246     "", $self,
247     "", $self);
248     $switch->addtag("ordering","distribution",
249     \&disttag,$self);
250     $switch->grouptag("Architecture","ordering");
251     $switch->addtag("ordering","require",
252     \&require_start,$self,
253     \&require_text, $self,
254     \&require_end, $self);
255    
256     $self->{reqcontext}=0;
257     $self->{switch}=$switch;
258     undef $self->{restrictstack};
259     @{$self->{tools}}=();
260    
261     my($doctype,$docversion)=$switch->doctype();
262     # -- for backwards compatability only parse if we have a docversion
263     # defined
264     if ( defined $docversion ) {
265     if ( $docversion eq $self->{mydocversion} ) {
266     @{$self->{ArchStack}}=();
267 williamc 1.3 $self->verbose("Initial Document Parse");
268 williamc 1.2 $self->{switch}->parse("ordering");
269     }
270 williamc 1.3 else {
271     $self->verbose("wrong doc version - not parsing");
272     }
273 williamc 1.2 }
274     else {
275 williamc 1.3 $self->verbose("wrong doc type - not parsing");
276 williamc 1.2 }
277     }
278    
279     sub arch {
280     my $self=shift;
281     if ( @_ ) {
282     $self->{arch}=shift
283     }
284     else {
285     if ( ! defined $self->{arch} ) {
286     $self->{arch}="";
287     }
288     }
289     return $self->{arch};
290     }
291    
292     sub archlist {
293     my $self=shift;
294     return @{$self->{ArchStack}};
295     }
296    
297     sub getreqforarch {
298     my $self=shift;
299     my $arch=shift;
300    
301     if ( ! defined $self->{reqsforarch}{$arch} ) {
302     $self->{reqsforarch}{$arch}=
303     BuildSystem::Requirements->new($self->{dbstore},$self->{file},
304     $arch);
305     }
306     return $self->{reqsforarch}{$arch};
307     }
308    
309    
310     sub download {
311     my $self=shift;
312    
313     my $tool;
314     foreach $tool ( $self->tools() ) {
315     $self->verbose("Downloading ".$self->toolurl($tool));
316     # get into the cache
317     $self->{switch}->urlget($self->toolurl($tool));
318     }
319     }
320    
321     sub _autoselect {
322     my $self=shift;
323     if ( @_ ) {
324     $self->{autoselect}=shift;
325     }
326     # -- default is true
327     return ((defined $self->{autoselect})?$self->{autoselect}:1);
328     }
329    
330     # ---- Tag routines
331    
332     sub Restrict_start {
333     my $self=shift;
334     my $name=shift;
335     my $hashref=shift;
336    
337     $self->{switch}->checktag( $name, $hashref, 'autoselect');
338     if ( $self->{Arch} ) {
339     # -- create selection state stack
340     push @{$self->{restrictstack}}, $self->_autoselect();
341     $self->_autoselect(
342     (($$hashref{'autoselect'}=~/true/i)?1:0));
343     }
344     }
345    
346     sub Restrict_end {
347     my $self=shift;
348     my $name=shift;
349 sashby 1.10
350 williamc 1.2 if ( $self->{Arch} ) {
351     if ( $#{$self->{restrictstack}} >= 0 ) {
352     $self->_autoselect(pop @{$self->{restrictstack}});
353     }
354     else {
355     $self->{switch}->parseerror("Unmatched </$name>");
356     }
357     }
358     }
359    
360     sub require_start {
361     my $self=shift;
362     my $name=shift;
363     my $hashref=shift;
364    
365     $self->{switch}->checktag( $name, $hashref, 'version');
366     $self->{switch}->checktag( $name, $hashref, 'name');
367     $self->{switch}->checktag( $name, $hashref, 'url');
368 sashby 1.10
369 williamc 1.2 if ( $self->{reqcontext} == 1 ) {
370     $self->{switch}->parseerror(
371 sashby 1.10 "Open new $name context without previous </$name>");
372 williamc 1.2 }
373     $self->{reqcontext}=1;
374     $$hashref{'name'}=~tr[A-Z][a-z];
375     push @{$self->{tools}}, $$hashref{'name'};
376     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
377     # -- make sure the full url is taken
378     my $urlobj=$self->{switch}->expandurl($$hashref{'url'});
379     $self->{url}{$$hashref{'name'}}=$urlobj->url();
380    
381 sashby 1.10
382     # Disable the auto select mechanism. Now, we start with
383     # all tools having a flag "UNSELECTED". Then we choose
384     # which we wish to select:
385     if ( $self->{Arch} )
386     {
387     $self->{selected}{$$hashref{'name'}}="UNSELECTED";
388     }
389    
390 williamc 1.2 # -- selection
391 sashby 1.10 # if ( $self->{Arch} ) {
392     # if ( $self->_autoselect() ) {
393     # $self->{selected}{$$hashref{'name'}}="UNSELECTED";
394     # }
395     # else {
396     # $self->{selected}{$$hashref{'name'}}="DESELECTED";
397     # }
398     # }
399    
400     # Output the tool name here with the value
401     # of its' select flag:
402     $self->verbose(">> Tool name: ".$$hashref{'name'}." sel/desel flag value: ".
403     $self->{selected}{$$hashref{'name'}} ." ");
404    
405 williamc 1.2 $self->{creqtool}=$$hashref{'name'};
406     $self->{creqversion}=$$hashref{'version'};
407     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
408     }
409    
410     sub require_text {
411     my $self=shift;
412     my $name=shift;
413     my $string=shift;
414    
415     chomp $string;
416     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
417     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
418     $string;
419    
420     }
421    
422     sub require_end {
423     my $self=shift;
424     my $name=shift;
425    
426     if ( $self->{reqcontext} != 1 ) {
427     $self->{switch}->parseerror("No matching tag for </$name>");
428     }
429     else {
430     $self->{reqcontext}=0;
431     }
432     }
433    
434 sashby 1.8 sub select_start
435     {
436     my $self=shift;
437     my $name=shift;
438     my $hashref=shift;
439    
440     $self->{switch}->checktag( $name, $hashref, 'name');
441     $$hashref{'name'}=~tr[A-Z][a-z];
442     if ( $self->{Arch} )
443     {
444     $self->verbose("Selecting ".$$hashref{'name'});
445     $self->{selected}{$$hashref{'name'}} = "SELECTED";
446     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
447     }
448     }
449    
450     sub deselect_start
451     {
452     my $self=shift;
453     my $name=shift;
454     my $hashref=shift;
455    
456     $self->{switch}->checktag( $name, $hashref, 'name');
457     $$hashref{'name'}=~tr[A-Z][a-z];
458     if ( $self->{Arch} )
459     {
460     $self->verbose("Deselecting ".$$hashref{'name'});
461     $self->{selected}{$$hashref{'name'}} = "DESELECTED";
462     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
463     }
464     }
465 williamc 1.2
466     sub Arch_Start {
467     my $self=shift;
468     my $name=shift;
469     my $hashref=shift;
470    
471     $self->{switch}->checktag($name, $hashref,'name');
472    
473     ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
474     : ($self->{Arch}=0);
475     $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
476     push @{$self->{ARCHBLOCK}}, $self->{Arch};
477     push @{$self->{ArchStack}}, $$hashref{'name'};
478     }
479    
480     sub Arch_End {
481     my $self=shift;
482     my $name=shift;
483    
484     pop @{$self->{ARCHBLOCK}};
485     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
486     }
487    
488     sub disttag {
489     my $self=shift;
490     my $name=shift;
491     my $hashref=shift;
492    
493     if ( exists $$hashref{'url'} ) {
494     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
495     $$hashref{'url'};
496     }
497     }