ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/Requirements.pm
Revision: 1.23
Committed: Tue Feb 27 11:59:44 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.22: +67 -72 lines
Log Message:
Merged from XML branch to HEAD. Start release prep.

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 sashby 1.23
19     BEGIN
20     {
21     die "\n\n".__PACKAGE__.": this package has been moved to Configuration::Requirements. This one is obsolete and can be removed.\n\n";
22     }
23    
24 williamc 1.2 use ActiveDoc::ActiveDoc;
25     use Utilities::Verbose;
26    
27     require 5.004;
28     @ISA=qw(Utilities::Verbose);
29 sashby 1.23 $BuildSystem::Requirements::self;
30 williamc 1.2
31 sashby 1.20 sub new
32     {
33     my $class=shift;
34 sashby 1.23 # Initialise the global package variable:
35     no strict 'refs';
36     $self = defined $self ? $self
37     : (bless {}, $class );
38 sashby 1.20 $self->{dbstore}=shift;
39     $self->{file}=shift;
40     $self->{cache}=$self->{dbstore}->cache();
41    
42     if ( @_ )
43     {
44     $self->arch(shift);
45     }
46     $self->verbose("Initialising a new Requirements Doc");
47 sashby 1.23 $self->{mydoctype} = "BuildSystem::Requirements";
48 sashby 1.20 $self->{mydocversion}="2.0";
49     # Counter for downloaded tools: zero it here. It will
50     # be auto-incremented as each tool is selected:
51     $self->{selectcounter}=0;
52    
53     $self->{Arch}=1;
54     push @{$self->{ARCHBLOCK}}, $self->{Arch};
55     $self->init($self->{file});
56     return $self;
57     }
58    
59     sub toolmanager
60     {
61     my $self=shift;
62    
63     @_ ? $self->{toolmanagerobject} = shift
64     : $self->{toolmanagerobject};
65    
66     }
67 williamc 1.2
68 sashby 1.20 sub configversion
69 sashby 1.7 {
70     my $self=shift;
71 sashby 1.20 @_ ? $self->{configversion} = shift
72     : $self->{configversion};
73     }
74 sashby 1.7
75 sashby 1.20 sub url
76     {
77     my $self=shift;
78    
79     if ( @_ )
80 sashby 1.7 {
81 sashby 1.20 $self->{file}=shift;
82 sashby 1.7 }
83 sashby 1.20 return $self->{file};
84     }
85    
86     sub tools
87     {
88     my $self=shift;
89     return @{$self->{tools}};
90     }
91    
92     sub toolcomment
93     {
94     my $self=shift;
95     my $tool=shift;
96     my $version=shift;
97    
98     return $self->{reqtext}{$tool}{$version};
99     }
100    
101     sub distributionurl
102     {
103     my $self=shift;
104     my $tool=shift;
105     my $version=shift;
106    
107     return ( defined $self->{dist}{$tool}{$version})?
108     $self->{dist}{$tool}{$version}:undef;
109 sashby 1.7 }
110 williamc 1.2
111 sashby 1.20 sub version
112     {
113     my $self=shift;
114     my $tool=shift;
115     return $self->{'version'}{$tool};
116     }
117 williamc 1.2
118 sashby 1.20 sub toolurl
119     {
120     my $self=shift;
121     my $tool=shift;
122     return $self->{'url'}{$tool};
123     }
124 sashby 1.11
125 sashby 1.20 sub init
126 sashby 1.8 {
127 sashby 1.11 my $self=shift;
128 sashby 1.20 my $url=shift;
129 sashby 1.23 my $scramdoc=ActiveDoc::ActiveDoc->new($self->{dbstore});
130     $scramdoc->verbosity($self->verbosity());
131     $scramdoc->url($url);
132     $scramdoc->newparse("ordering",$self->{mydoctype},'Subs');
133 sashby 1.20 $self->{reqcontext}=0;
134 sashby 1.23 $self->{scramdoc}=$scramdoc;
135 sashby 1.20 undef $self->{restrictstack};
136     @{$self->{tools}}=();
137 sashby 1.23 @{$self->{ArchStack}}=();
138     $self->verbose("Initial Document Parse");
139     $self->{scramdoc}->parse("ordering");
140     # Set the config version. If there isn't a version, it means that we
141     # have a stand-alone repository for the toolbox, rather than a CVS
142     # one. Hence, no CVS tag (== version):
143     ($scramdoc->{configurl}->param('version') eq '') ?
144     $self->configversion("STANDALONE") :
145     $self->configversion($scramdoc->{configurl}->param('version'));
146 sashby 1.20 }
147    
148     sub arch
149     {
150     my $self=shift;
151     # $self->arch is the SCRAM_ARCH value:
152     if ( @_ )
153     {
154     $self->{arch}=shift;
155     }
156     else
157     {
158     if ( ! defined $self->{arch} )
159 sashby 1.11 {
160 sashby 1.20 $self->{arch}="";
161 sashby 1.11 }
162     }
163 sashby 1.20 return $self->{arch};
164 sashby 1.11 }
165    
166 sashby 1.20 sub archlist
167     {
168     my $self=shift;
169     return @{$self->{ArchStack}};
170     }
171 sashby 1.11
172 sashby 1.20 sub getreqforarch
173 sashby 1.11 {
174 sashby 1.8 my $self=shift;
175 sashby 1.20 my $arch=shift;
176 sashby 1.11
177 sashby 1.20 if ( ! defined $self->{reqsforarch}{$arch} )
178 sashby 1.8 {
179 sashby 1.20 $self->{reqsforarch}{$arch}=
180     BuildSystem::Requirements->new($self->{dbstore},$self->{file},
181     $arch);
182 sashby 1.8 }
183 sashby 1.20 return $self->{reqsforarch}{$arch};
184 sashby 1.8 }
185 sashby 1.11
186 sashby 1.13 sub download
187     {
188     my $self=shift;
189     my $tool;
190     $| = 1; # Unbuffer the output
191    
192     print "Downloading tool descriptions....","\n";
193     print " ";
194     foreach $tool ( $self->tools() )
195     {
196     print "#";
197     $self->verbose("Downloading ".$self->toolurl($tool));
198 sashby 1.20 # get into the cache:
199 sashby 1.23 $self->{scramdoc}->urlget($self->toolurl($tool));
200 sashby 1.13 }
201 sashby 1.20 print "\nDone.","\n";
202     # So now add the list of downloaded tools, and which were
203     # selected, to tool cache:
204     print "Tool info cached locally.","\n","\n";
205    
206     # Now copy required info from this object to ToolManager (ToolCache):
207     $self->toolmanager()->downloadedtools($self->{tools});
208     $self->toolmanager()->defaultversions($self->{version});
209     $self->toolmanager()->toolurls($self->{url});
210     $self->toolmanager()->selected($self->{selected});
211 sashby 1.13 }
212 williamc 1.2
213 sashby 1.23 #sub _autoselect
214     # {
215     # my $self=shift;
216     # if ( @_ )
217     # {
218     # $self->{autoselect}=shift;
219     # }
220     # # -- default is true
221     # return ((defined $self->{autoselect})?$self->{autoselect}:1);
222     # }
223 williamc 1.2
224 sashby 1.23 sub require()
225 sashby 1.8 {
226     my $self=shift;
227     my $name=shift;
228     my $hashref=shift;
229 sashby 1.20
230 sashby 1.23 $self->{scramdoc}->checktag( $name, $hashref, 'version');
231     $self->{scramdoc}->checktag( $name, $hashref, 'name');
232     $self->{scramdoc}->checktag( $name, $hashref, 'url');
233 sashby 1.20
234     if ( $self->{reqcontext} == 1 )
235     {
236 sashby 1.23 $self->{scramdoc}->parseerror(
237 sashby 1.20 "Open new $name context without previous </$name>");
238     }
239     $self->{reqcontext}=1;
240 sashby 1.8 $$hashref{'name'}=~tr[A-Z][a-z];
241 sashby 1.20
242     # Add protection so that architecture tags are obeyed during download:
243 sashby 1.8 if ( $self->{Arch} )
244     {
245 sashby 1.20 # Add tool to the tool array:
246     push @{$self->{tools}}, $$hashref{'name'};
247    
248     # If the tool already has an entry, modify the version string to
249     # include both versions. The versions can later be separated and
250     # parsed as normal:
251     if (defined $self->{version}{$$hashref{'name'}})
252     {
253     # Don't need an extra entry for this tool onto tool array:
254     pop @{$self->{tools}}, $$hashref{'name'};
255     # Modify the version string to append the other tool version.
256     # Separate using a colon:
257     my $newversion=$self->{version}{$$hashref{'name'}}.":".$$hashref{'version'};
258     $self->{version}{$$hashref{'name'}}=$newversion;
259     }
260     else
261     {
262     $self->{version}{$$hashref{'name'}}=$$hashref{'version'};
263     }
264     # -- make sure the full url is taken
265 sashby 1.23 my $urlobj=$self->{scramdoc}->expandurl($$hashref{'url'});
266 sashby 1.20 $self->{url}{$$hashref{'name'}}=$urlobj->url();
267    
268     $self->{creqtool}=$$hashref{'name'};
269     $self->{creqversion}=$$hashref{'version'};
270     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}="";
271     }
272     }
273    
274     sub require_text
275     {
276     my $self=shift;
277     my $name=shift;
278     my $string=shift;
279    
280     chomp $string;
281     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}=
282     $self->{reqtext}{$self->{creqtool}}{$self->{creqversion}}.
283     $string;
284     }
285    
286     sub require_end
287     {
288     my $self=shift;
289     my $name=shift;
290    
291     if ( $self->{reqcontext} != 1 )
292     {
293 sashby 1.23 $self->{scramdoc}->parseerror("No matching tag for </$name>");
294 sashby 1.20 }
295     else
296     {
297     $self->{reqcontext}=0;
298 sashby 1.8 }
299     }
300    
301 sashby 1.20 sub select_start
302 sashby 1.8 {
303     my $self=shift;
304     my $name=shift;
305     my $hashref=shift;
306 sashby 1.20
307 sashby 1.23 $self->{scramdoc}->checktag( $name, $hashref, 'name');
308 sashby 1.8 $$hashref{'name'}=~tr[A-Z][a-z];
309     if ( $self->{Arch} )
310     {
311 sashby 1.20 $self->verbose("Selecting ".$$hashref{'name'});
312     # Increment counter:
313     $self->{selectcounter}++;
314     $self->{selected}{$$hashref{'name'}}=$self->{selectcounter};
315 sashby 1.8 }
316     }
317 williamc 1.2
318 sashby 1.14 sub Arch_Start
319     {
320     my $self=shift;
321     my $name=shift;
322     my $hashref=shift;
323 sashby 1.20
324 sashby 1.14 # Check the architecture tag:
325 sashby 1.23 $self->{scramdoc}->checktag($name, $hashref,'name');
326 sashby 1.20 ( ($self->arch()=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
327     : ($self->{Arch}=0);
328 sashby 1.19
329 sashby 1.14 $self->verbose(($self->{Arch}?"OK":"skipping")." ".$$hashref{name});
330     push @{$self->{ARCHBLOCK}}, $self->{Arch};
331     push @{$self->{ArchStack}}, $$hashref{'name'};
332     }
333 williamc 1.2
334 sashby 1.20 sub Arch_End
335     {
336     my $self=shift;
337     my $name=shift;
338     pop @{$self->{ARCHBLOCK}};
339     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
340     }
341    
342     sub disttag
343     {
344     my $self=shift;
345     my $name=shift;
346     my $hashref=shift;
347    
348     if ( exists $$hashref{'url'} )
349     {
350     $self->{dist}{$self->{creqtool}}{$self->{creqversion}}=
351     $$hashref{'url'};
352     }
353     }
354 sashby 1.23
355     sub select()
356     {
357     my ($xmlparser,$name,%attributes)=@_;
358     # print "Selecting ".$attributes{'name'},"\n";
359     }
360    
361     sub select_()
362     {}
363    
364     sub AUTOLOAD()
365     {
366     my ($xmlparser,$name,%attributes)=@_;
367     return if $AUTOLOAD =~ /::DESTROY$/;
368     my $name=$AUTOLOAD;
369     $name =~ s/.*://;
370     # Delegate missing function calls to the doc parser class:
371     $self->{scramdoc}->$name(%attributes);
372     }
373    
374     1;