ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.12
Committed: Thu Dec 6 19:00:59 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1
Changes since 1.11: +0 -19 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     sub download {
292     my $self=shift;
293    
294     my $tool;
295     foreach $tool ( $self->tools() ) {
296     $self->verbose("Downloading ".$self->toolurl($tool));
297     # get into the cache
298     $self->{switch}->urlget($self->toolurl($tool));
299     }
300     }
301    
302     sub _autoselect {
303     my $self=shift;
304     if ( @_ ) {
305     $self->{autoselect}=shift;
306     }
307     # -- default is true
308     return ((defined $self->{autoselect})?$self->{autoselect}:1);
309     }
310    
311     # ---- Tag routines
312    
313     sub Restrict_start {
314     my $self=shift;
315     my $name=shift;
316     my $hashref=shift;
317    
318     $self->{switch}->checktag( $name, $hashref, 'autoselect');
319     if ( $self->{Arch} ) {
320     # -- create selection state stack
321     push @{$self->{restrictstack}}, $self->_autoselect();
322     $self->_autoselect(
323     (($$hashref{'autoselect'}=~/true/i)?1:0));
324     }
325     }
326    
327     sub Restrict_end {
328     my $self=shift;
329     my $name=shift;
330 sashby 1.10
331 williamc 1.2 if ( $self->{Arch} ) {
332     if ( $#{$self->{restrictstack}} >= 0 ) {
333     $self->_autoselect(pop @{$self->{restrictstack}});
334     }
335     else {
336     $self->{switch}->parseerror("Unmatched </$name>");
337     }
338     }
339     }
340    
341     sub require_start {
342     my $self=shift;
343     my $name=shift;
344     my $hashref=shift;
345    
346     $self->{switch}->checktag( $name, $hashref, 'version');
347     $self->{switch}->checktag( $name, $hashref, 'name');
348     $self->{switch}->checktag( $name, $hashref, 'url');
349 sashby 1.10
350 williamc 1.2 if ( $self->{reqcontext} == 1 ) {
351     $self->{switch}->parseerror(
352 sashby 1.10 "Open new $name context without previous </$name>");
353 williamc 1.2 }
354     $self->{reqcontext}=1;
355     $$hashref{'name'}=~tr[A-Z][a-z];
356     push @{$self->{tools}}, $$hashref{'name'};
357     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
358     # -- make sure the full url is taken
359     my $urlobj=$self->{switch}->expandurl($$hashref{'url'});
360     $self->{url}{$$hashref{'name'}}=$urlobj->url();
361    
362 sashby 1.10
363     # Disable the auto select mechanism. Now, we start with
364     # all tools having a flag "UNSELECTED". Then we choose
365     # which we wish to select:
366     if ( $self->{Arch} )
367     {
368     $self->{selected}{$$hashref{'name'}}="UNSELECTED";
369     }
370    
371 williamc 1.2 # -- selection
372 sashby 1.10 # if ( $self->{Arch} ) {
373     # if ( $self->_autoselect() ) {
374     # $self->{selected}{$$hashref{'name'}}="UNSELECTED";
375     # }
376     # else {
377     # $self->{selected}{$$hashref{'name'}}="DESELECTED";
378     # }
379     # }
380    
381     # Output the tool name here with the value
382     # of its' select flag:
383     $self->verbose(">> Tool name: ".$$hashref{'name'}." sel/desel flag value: ".
384     $self->{selected}{$$hashref{'name'}} ." ");
385    
386 williamc 1.2 $self->{creqtool}=$$hashref{'name'};
387     $self->{creqversion}=$$hashref{'version'};
388     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
389     }
390    
391     sub require_text {
392     my $self=shift;
393     my $name=shift;
394     my $string=shift;
395    
396     chomp $string;
397     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
398     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
399     $string;
400    
401     }
402    
403     sub require_end {
404     my $self=shift;
405     my $name=shift;
406    
407     if ( $self->{reqcontext} != 1 ) {
408     $self->{switch}->parseerror("No matching tag for </$name>");
409     }
410     else {
411     $self->{reqcontext}=0;
412     }
413     }
414    
415 sashby 1.8 sub select_start
416     {
417     my $self=shift;
418     my $name=shift;
419     my $hashref=shift;
420    
421     $self->{switch}->checktag( $name, $hashref, 'name');
422     $$hashref{'name'}=~tr[A-Z][a-z];
423     if ( $self->{Arch} )
424     {
425     $self->verbose("Selecting ".$$hashref{'name'});
426     $self->{selected}{$$hashref{'name'}} = "SELECTED";
427     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
428     }
429     }
430    
431     sub deselect_start
432     {
433     my $self=shift;
434     my $name=shift;
435     my $hashref=shift;
436    
437     $self->{switch}->checktag( $name, $hashref, 'name');
438     $$hashref{'name'}=~tr[A-Z][a-z];
439     if ( $self->{Arch} )
440     {
441     $self->verbose("Deselecting ".$$hashref{'name'});
442     $self->{selected}{$$hashref{'name'}} = "DESELECTED";
443     $self->verbose(">> Tool select flag = ".$self->{selected}{$$hashref{'name'}}."\n");
444     }
445     }
446 williamc 1.2
447     sub Arch_Start {
448     my $self=shift;
449     my $name=shift;
450     my $hashref=shift;
451    
452     $self->{switch}->checktag($name, $hashref,'name');
453    
454     ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
455     : ($self->{Arch}=0);
456     $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
457     push @{$self->{ARCHBLOCK}}, $self->{Arch};
458     push @{$self->{ArchStack}}, $$hashref{'name'};
459     }
460    
461     sub Arch_End {
462     my $self=shift;
463     my $name=shift;
464    
465     pop @{$self->{ARCHBLOCK}};
466     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
467     }
468    
469     sub disttag {
470     my $self=shift;
471     my $name=shift;
472     my $hashref=shift;
473    
474     if ( exists $$hashref{'url'} ) {
475     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
476     $$hashref{'url'};
477     }
478     }