ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.13
Committed: Mon Apr 29 16:09:23 2002 UTC (23 years ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2
Branch point for: V0_19_4_B
Changes since 1.12: +17 -21 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
69 sashby 1.8 sub selectedtools
70     {
71 sashby 1.11 ###############################################################
72     # selectedtools() #
73     ###############################################################
74     # modified : Wed Dec 5 15:39:39 2001 / SFA #
75     # params : #
76     # : #
77     # : #
78     # : #
79     # function : New version of routine. Return a list of tools #
80     # : that were selected after parsing RequirementsDoc #
81     # : #
82     # : #
83     ###############################################################
84     my $self=shift;
85     my @toolarray = ();
86    
87     # Grab the arrays of tools:
88     my ($toolref,$deseltoolref,$unseltoolref) = $self->grabtools();
89    
90     my @tools = @{$toolref};
91     my @deseltools = @{$deseltoolref};
92     my @unseltools = @{$unseltoolref};
93    
94     if ($#tools == -1)
95     {
96     $self->verbose(">> No tools SELECTED. Checking for DESELECTED tools");
97    
98     # No tools "SELECTED". We return the tools that were "UNSELECTED"
99     # (these are the tools that remain after unwanted tools are deselected):
100     if ($#unseltools != -1)
101     {
102     $self->verbose(">> Using the tools remaining after DESELECTION ops");
103     # The array has elements:
104     return @unseltools;
105     }
106     else
107     {
108     $self->verbose(">> No UNSELECTED tools.....");
109     }
110     }
111     else
112     {
113     # We will return the selected tools but only after checking
114     # for subsequently deselected tools (unlikely but...):
115     foreach $selected (@tools)
116     {
117     # If the tool exists in the deselected tool array, pass.
118     if ( ! grep /$selected/, @deseltools)
119     {
120     push @toolarray, $selected;
121     }
122     else
123     {
124     $self->verbose(">> Tool $selected was subsequently deselected.");
125     }
126     }
127     }
128     return @toolarray;
129     }
130    
131    
132     sub grabtools
133     {
134     ###############################################################
135     # grabtools() #
136     ###############################################################
137     # modified : Wed Dec 5 14:41:56 2001 / SFA #
138     # params : #
139     # : #
140     # : #
141     # : #
142     # function : Loop over the tools read from RequirementsDoc #
143     # : and fill arrays for selected, deselected and #
144     # : unselected tools. #
145     # : #
146     ###############################################################
147 sashby 1.8 my $self=shift;
148     my @toollist=();
149 sashby 1.11 my @deseltoollist=();
150     my @unseltoollist=();
151    
152 sashby 1.8 foreach $tool ( @{$self->{tools}} )
153     {
154     if ( $self->{selected}{$tool} eq "SELECTED" )
155     {
156     push @toollist, $tool;
157     }
158 sashby 1.11 elsif ( $self->{selected}{$tool} eq "DESELECTED" )
159     {
160     push @deseltoollist, $tool;
161     }
162     elsif ( $self->{selected}{$tool} eq "UNSELECTED" )
163     {
164     push @unseltoollist, $tool;
165     }
166     else
167     {
168     $self->verbose(">> Looks like an unknown sel flag for tool ".$tool." ");
169     }
170 sashby 1.8 }
171 sashby 1.11 return \(@toollist, @deseltoollist, @unseltoollist);
172 sashby 1.8 }
173 sashby 1.11
174 williamc 1.2
175     sub toolcomment {
176     my $self=shift;
177     my $tool=shift;
178     my $version=shift;
179    
180     return $self->{reqtext}{$tool}{$version};
181     }
182    
183     sub distributionurl {
184     my $self=shift;
185     my $tool=shift;
186     my $version=shift;
187    
188     return ( defined $self->{dist}{$tool}{$version})?
189     $self->{dist}{$tool}{$version}:undef;
190     }
191    
192     sub version {
193     my $self=shift;
194     my $tool=shift;
195     return $self->{'version'}{$tool};
196     }
197    
198     sub toolurl {
199     my $self=shift;
200     my $tool=shift;
201     return $self->{'url'}{$tool};
202     }
203    
204     sub init {
205     my $self=shift;
206     my $url=shift;
207    
208     my $switch=ActiveDoc::ActiveDoc->new($self->{dbstore});
209     $switch->verbosity($self->verbosity());
210     $switch->url($url);
211     $switch->newparse("ordering");
212     $switch->addbasetags("ordering");
213     $switch->addtag("ordering","Architecture",
214     \&Arch_Start,$self,
215     "", $self,
216     \&Arch_End, $self);
217     $switch->addtag("ordering","Restrict",
218     \&Restrict_start,$self,
219     "", $self,
220     \&Restrict_end, $self);
221     $switch->addtag("ordering","deselect",
222     \&deselect_start,$self,
223     "", $self,
224     "", $self);
225     $switch->addtag("ordering","select",
226     \&select_start,$self,
227     "", $self,
228     "", $self);
229     $switch->addtag("ordering","distribution",
230     \&disttag,$self);
231     $switch->grouptag("Architecture","ordering");
232     $switch->addtag("ordering","require",
233     \&require_start,$self,
234     \&require_text, $self,
235     \&require_end, $self);
236    
237     $self->{reqcontext}=0;
238     $self->{switch}=$switch;
239     undef $self->{restrictstack};
240     @{$self->{tools}}=();
241    
242     my($doctype,$docversion)=$switch->doctype();
243     # -- for backwards compatability only parse if we have a docversion
244     # defined
245     if ( defined $docversion ) {
246     if ( $docversion eq $self->{mydocversion} ) {
247     @{$self->{ArchStack}}=();
248 williamc 1.3 $self->verbose("Initial Document Parse");
249 williamc 1.2 $self->{switch}->parse("ordering");
250     }
251 williamc 1.3 else {
252     $self->verbose("wrong doc version - not parsing");
253     }
254 williamc 1.2 }
255     else {
256 williamc 1.3 $self->verbose("wrong doc type - not parsing");
257 williamc 1.2 }
258     }
259    
260     sub arch {
261     my $self=shift;
262     if ( @_ ) {
263     $self->{arch}=shift
264     }
265     else {
266     if ( ! defined $self->{arch} ) {
267     $self->{arch}="";
268     }
269     }
270     return $self->{arch};
271     }
272    
273     sub archlist {
274     my $self=shift;
275     return @{$self->{ArchStack}};
276     }
277    
278     sub getreqforarch {
279     my $self=shift;
280     my $arch=shift;
281    
282     if ( ! defined $self->{reqsforarch}{$arch} ) {
283     $self->{reqsforarch}{$arch}=
284     BuildSystem::Requirements->new($self->{dbstore},$self->{file},
285     $arch);
286     }
287     return $self->{reqsforarch}{$arch};
288     }
289    
290    
291 sashby 1.13 sub download
292     {
293     my $self=shift;
294     my $tool;
295     $| = 1; # Unbuffer the output
296    
297     print "Downloading tool descriptions....","\n";
298     print " ";
299     foreach $tool ( $self->tools() )
300     {
301     print "#";
302     $self->verbose("Downloading ".$self->toolurl($tool));
303     # get into the cache
304     $self->{switch}->urlget($self->toolurl($tool));
305     }
306     print "\nDone.","\n","\n";
307     }
308 williamc 1.2
309     sub _autoselect {
310     my $self=shift;
311     if ( @_ ) {
312     $self->{autoselect}=shift;
313     }
314     # -- default is true
315     return ((defined $self->{autoselect})?$self->{autoselect}:1);
316     }
317    
318     # ---- Tag routines
319    
320     sub Restrict_start {
321     my $self=shift;
322     my $name=shift;
323     my $hashref=shift;
324    
325     $self->{switch}->checktag( $name, $hashref, 'autoselect');
326     if ( $self->{Arch} ) {
327     # -- create selection state stack
328     push @{$self->{restrictstack}}, $self->_autoselect();
329     $self->_autoselect(
330     (($$hashref{'autoselect'}=~/true/i)?1:0));
331     }
332     }
333    
334     sub Restrict_end {
335     my $self=shift;
336     my $name=shift;
337 sashby 1.10
338 williamc 1.2 if ( $self->{Arch} ) {
339     if ( $#{$self->{restrictstack}} >= 0 ) {
340     $self->_autoselect(pop @{$self->{restrictstack}});
341     }
342     else {
343     $self->{switch}->parseerror("Unmatched </$name>");
344     }
345     }
346     }
347    
348     sub require_start {
349     my $self=shift;
350     my $name=shift;
351     my $hashref=shift;
352    
353     $self->{switch}->checktag( $name, $hashref, 'version');
354     $self->{switch}->checktag( $name, $hashref, 'name');
355     $self->{switch}->checktag( $name, $hashref, 'url');
356 sashby 1.10
357 williamc 1.2 if ( $self->{reqcontext} == 1 ) {
358     $self->{switch}->parseerror(
359 sashby 1.10 "Open new $name context without previous </$name>");
360 williamc 1.2 }
361     $self->{reqcontext}=1;
362     $$hashref{'name'}=~tr[A-Z][a-z];
363     push @{$self->{tools}}, $$hashref{'name'};
364     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
365     # -- make sure the full url is taken
366     my $urlobj=$self->{switch}->expandurl($$hashref{'url'});
367     $self->{url}{$$hashref{'name'}}=$urlobj->url();
368    
369 sashby 1.10
370     # Disable the auto select mechanism. Now, we start with
371     # all tools having a flag "UNSELECTED". Then we choose
372     # which we wish to select:
373     if ( $self->{Arch} )
374     {
375     $self->{selected}{$$hashref{'name'}}="UNSELECTED";
376     }
377     # Output the tool name here with the value
378     # of its' select flag:
379     $self->verbose(">> Tool name: ".$$hashref{'name'}." sel/desel flag value: ".
380     $self->{selected}{$$hashref{'name'}} ." ");
381    
382 williamc 1.2 $self->{creqtool}=$$hashref{'name'};
383     $self->{creqversion}=$$hashref{'version'};
384     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
385     }
386    
387     sub require_text {
388     my $self=shift;
389     my $name=shift;
390     my $string=shift;
391    
392     chomp $string;
393     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
394     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
395     $string;
396    
397     }
398    
399     sub require_end {
400     my $self=shift;
401     my $name=shift;
402    
403     if ( $self->{reqcontext} != 1 ) {
404     $self->{switch}->parseerror("No matching tag for </$name>");
405     }
406     else {
407     $self->{reqcontext}=0;
408     }
409     }
410    
411 sashby 1.8 sub select_start
412     {
413     my $self=shift;
414     my $name=shift;
415     my $hashref=shift;
416    
417     $self->{switch}->checktag( $name, $hashref, 'name');
418     $$hashref{'name'}=~tr[A-Z][a-z];
419     if ( $self->{Arch} )
420     {
421     $self->verbose("Selecting ".$$hashref{'name'});
422     $self->{selected}{$$hashref{'name'}} = "SELECTED";
423     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
424     }
425     }
426    
427     sub deselect_start
428     {
429     my $self=shift;
430     my $name=shift;
431     my $hashref=shift;
432    
433     $self->{switch}->checktag( $name, $hashref, 'name');
434     $$hashref{'name'}=~tr[A-Z][a-z];
435     if ( $self->{Arch} )
436     {
437     $self->verbose("Deselecting ".$$hashref{'name'});
438     $self->{selected}{$$hashref{'name'}} = "DESELECTED";
439     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
440     }
441     }
442 williamc 1.2
443     sub Arch_Start {
444     my $self=shift;
445     my $name=shift;
446     my $hashref=shift;
447    
448     $self->{switch}->checktag($name, $hashref,'name');
449    
450     ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
451     : ($self->{Arch}=0);
452     $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
453     push @{$self->{ARCHBLOCK}}, $self->{Arch};
454     push @{$self->{ArchStack}}, $$hashref{'name'};
455     }
456    
457     sub Arch_End {
458     my $self=shift;
459     my $name=shift;
460    
461     pop @{$self->{ARCHBLOCK}};
462     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
463     }
464    
465     sub disttag {
466     my $self=shift;
467     my $name=shift;
468     my $hashref=shift;
469    
470     if ( exists $$hashref{'url'} ) {
471     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
472     $$hashref{'url'};
473     }
474     }